|

楼主 |
发表于 2007-7-21 09:56:00
|
显示全部楼层
Re:糖块
呵呵,画面确实不是太好,那个场景我是用的addon里面octree的一个模型,忍者和机器人还有人族大法是大家认识的,僵尸是用的addon里ogrenewt的Ragdoll的一个模型。我只是做了“减你钱”和“弹”两个模型(用max导出的)
碰撞检测并不需要研究的过多,你看下前面我Re: ArenAK的回帖吧。
{PROFILE("Enimy::NewtonWorldRayCast");
Vector3 from,to;
from = this->getPos()+Vector3::UNIT_Y;
to = this->getPos()-Vector3::UNIT_Y*10;
NewtonWorldRayCast(mWorld->getNewtonWorld()->getNewtonWorld(), (float*)&from, (float*)&to,
Enimy::newtonRaycastFilter, this, Enimy::newtonRaycastPreFilter );
Vector3 res= (to-from)*this->mRayScale+from;
this->mPosHeight= res.y;
this->getSceneNode()->setPosition(getPos().x,mPosHeight,getPos().z);
}//PROFILE("Enimy::BasicRaycast"); end!!
float _CDECL Enimy::newtonRaycastFilter(const NewtonBody* body, const float* hitNormal, int collisionID, void* userData, float intersectParam)
{
// get our object!
Enimy* me = (Enimy*)userData;
OgreNewt::Body* bod = (OgreNewt::Body*)NewtonBodyGetUserData( body );
Ogre::Vector3 normal = Ogre::Vector3( hitNormal[0], hitNormal[1], hitNormal[2] );
if (bod&&bod->getType()==0) //这个0就是主体的场景了
{
if(abs(intersectParam)>0.001)
me->setRayScale(intersectParam);
// info.mDistance is in the range [0,1].
}
return 1.1;
}
static float _CDECL newtonRaycastFilter(const NewtonBody* body, const float* hitNormal, int collisionID, void* userData, float intersetParam);
static unsigned _CDECL newtonRaycastPreFilter( const NewtonBody* body, const NewtonCollision* collision, void* userData )
{return 1;}
这是我程序里enimy确定高度的newton的直线和场景的碰撞检测,在enimy.cpp和.h中,等同与ogre demo里那个ode的碰撞检测的例子,都是给定一条线段,然后让物理引擎计算出碰撞到的场景时所截得的线段占整条线段长度的比例,然后再根据这个确定碰撞点的位置。
如果你真的对碰撞检测比较感兴趣的话你可以去看看irrlicht的底层代码,重点看下三角形和球以及三角形和线的碰撞即可,那个我之前都打印出来不少看。但后来发现研究那个并不是很实用,到用时把别人的拷过来用就行了。但自己一定要清楚碰撞检测计算的原理和步骤。 |
|