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);
}