Convert Angle to Torque

majc

17-08-2008 03:28:26

Im using this code i got from a post:

Ogre::Vector3 Destination, Position;
Ogre::Quaternion npcOrientation;
Ogre::Quaternion playerOrientation;
mPlayer->getBody()->getPositionOrientation(Destination,playerOrientation);
body->getPositionOrientation(Position,npcOrientation);
Ogre::Vector3 goalHeading = Destination;
goalHeading.y = 0.0f;
goalHeading.normalise();

Ogre::Vector3 curHeading = npcOrientation * Ogre::Vector3::UNIT_Z;

// angle between these vectors.
Ogre::Degree delta_o = Math::ACos( curHeading.dotProduct( goalHeading ) );
Ogre::Vector3 rot_axis = curHeading.crossProduct( goalHeading ).normalisedCopy();
body->addLocalForce(gravity * mNPC->getMass(), Ogre::Vector3::ZERO);
body->addTorque( (rot_axis * delta_o.valueDegrees() * 40.0f) - (body->getOmega()*100.0f) );


This is more or less working the problem is that the npc is always facing is side to me not the front it seems that the mesh front direction is his side.
How i change that?

Some help please.
Thanks in advance!

majc

17-08-2008 13:57:34

Ok its working :) I t seems that the default forward direction is X not Z
I change this:

Ogre::Vector3 curHeading = npcOrientation * Ogre::Vector3::UNIT_Z;

to this:

Ogre::Vector3 curHeading = npcOrientation * Ogre::Vector3::UNIT_X;

NOTE: the npc mass if its too high the npc dont rotate.

walaber

17-08-2008 16:48:03

if the mass of the object is different, you need to change the 40.0f and 100.0f in the last line accordingly.

majc

17-08-2008 16:51:58

Yes i did that but this function has a problem when i collide with the npc after that the npc dont face the player well i dont know why :(