Little bug correction

kallaspriit

15-06-2009 12:51:10

The Body::addGlobalForce() method of OgreNewt wrapper (I am using Melvin's version for Newton 2, but the same should be in the original Walaber version) does not seem to take center of gravity into account and fails if the latter is anything but zero.

Original implementation:
void Body::addGlobalForce( const Ogre::Vector3& force, const Ogre::Vector3& pos )
{
Ogre::Vector3 bodypos;
Ogre::Quaternion bodyorient;
getPositionOrientation( bodypos, bodyorient );

Ogre::Vector3 topoint = pos - bodypos;
Ogre::Vector3 torque = topoint.crossProduct( force );

addForce( force );
addTorque( torque );
}


Updated version:
void Body::addGlobalForce( const Ogre::Vector3& force, const Ogre::Vector3& pos )
{
Ogre::Vector3 bodypos;

Ogre::Quaternion bodyorient;
getPositionOrientation( bodypos, bodyorient );

Ogre::Vector3 localMassCenter = getCenterOfMass();
Ogre::Vector3 globalMassCenter = bodyorient * localMassCenter;

Ogre::Vector3 topoint = pos - bodypos - globalMassCenter;
Ogre::Vector3 torque = topoint.crossProduct( force );

addForce( force );
addTorque( torque );
}


Not sure whether I'm doing it right, but this seems to work for me :)

Many thanks to Walaber and also Melvin for updating the wrapper for NGD 2.0 - there were many interface-breaking changes, but I agree with them and got it to work with my project beautifully :P

melven

15-06-2009 16:23:59

I think you are right... I integrated your changes (but I did not yet commit all my local changes...)