CollisionPointDistance [Maybe, there is some mistake]

SusanDing

13-06-2006 05:07:37

I have read the following code, and I find the code in red may be wrong! :(
int CollisionPointDistance( const OgreNewt::World* world, const Ogre::Vector3& globalpt,
const OgreNewt::Collision* col, const Ogre::Quaternion& colorient, const Ogre::Vector3& colpos,
Ogre::Vector3& retpt, Ogre::Vector3& retnormal )
{
float matrix[16];
Converters::QuatPosToMatrix( colorient, colpos, matrix );

NewtonCollisionPointDistance( world->getNewtonWorld(), &colpos.x, col->getNewtonCollision(), matrix, &retpt.x, &retnormal.x ); }

I think it should be
return NewtonCollisionPointDistance( world->getNewtonWorld(), &globalpt.x, col->getNewtonCollision(), matrix, &retpt.x, &retnormal.x );

Because the second param of NewtonCollisionPointDistance is
  1. pointer to and array of a least 3 floats representing the origin.

That should be the position of the origin point, not the position of the body. :?

Am I right? Or I confuse with it.

walaber

13-06-2006 05:39:36

yes, you are right, that is a mistake! I have fixed it in my local copy, and will update CVS and my website now.

thanks!

SusanDing

13-06-2006 08:26:22

I still meet some trouble.
void _CDECL OgreNewtonFrameListener::newtonallcallbak( const NewtonBody* body )
{
//newton wants to destroy the body.. so first find it.
OgreNewt::Body* me;

me = (OgreNewt::Body*)NewtonBodyGetUserData( body );

float mass;
Vector3 inertia;
me->getMassMatrix(mass,inertia);

// static bodies dont move!
if (mass == 0) return;
Vector3 pos;
Quaternion orient;
me->getPositionOrientation(pos,orient);

Vector3 origin(0,-8,0);
Vector3 nearestPos,nearestNormal;
if (OgreNewt::CollisionTools::CollisionPointDistance(me->getWorld(),origin,me->getCollision(),orient,pos,
nearestPos,nearestNormal)==1)
{
//calculate and add force

}

}


I use this for sitimulate the explosion. Afer explosion happen, this function was called to add some globalForce. But the function
if (OgreNewt::CollisionTools::CollisionPointDistance(me->getWorld(),origin,me->getCollision(),orient,pos,
nearestPos,nearestNormal)==1)

will be interrupted, because of access conflict. I don't know why?

walaber

13-06-2006 16:04:41

did you delete the Collision object when you created the body?