(Get angle between 2 Vectors, ...) [solved] tnx everyone

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
fakin
Posts: 14
Joined: Wed Jan 24, 2007 9:02 pm
Location: zagreb, croatia

(Get angle between 2 Vectors, ...) [solved] tnx everyone

Post by fakin »

OK, here's the problem.

I have a character. he is looking at some direction. now, when i click somewhere on the map i want it to rotate to that point and move there.
move part is OK, but i can get him to rotate it to look at that point. Knowing that angle between two 3D vectors is acos of dot product of two normalized vectors I've made some calculations but it doesn't do me no good.

Code: Select all

void CsModelHandler::fRotateModel(ISceneNode* from, const vector3df& to) {
// i get 'to' vector from ISceneManager->getSceneCollisionManager()->getCollisionPoint(), it's intersection vector

	vector3df fromPosition = from->getAbsolutePosition();

	vector3df differenceVector = fromPosition - to;

	vector3df fromOrientation = from->getRotation();

	differenceVector.normalize();

	fromOrientation.normalize();

	f32 dotProduct = fromOrientation.dotProduct(differenceVector);

	f32 angle = acos(dotProduct);

	vector3df finalRotation = from->getRotation();

	finalRotation.Y += angle;

	from->setRotation(finalRotation);
}
any help would be appreciated.
Post Reply