How to rotate a scene node towards a point?

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
Weng
Posts: 97
Joined: Tue Oct 03, 2006 4:23 pm
Location: Singapore

How to rotate a scene node towards a point?

Post by Weng »

I would like to rotate a fairie node towards a point where the player right clicked.

According to some maths formula I've read, the approach seems to be like this:

1. Find the vector where the node is facing
2. Find the vector from the node's position to the position where the player clicked
3. Normalize both the above vectors
4. Take the dot product between these 2 and arc cosine the result to get the angle to rotate
5. Use setRotate on the y axis to rotate the node

The problem is, how do I find out the vector where the node is facing?

Also, is the above approach correct? I've read that rotation is best done using matrices, instead of setting the y axis to rotate by an angle.

:?
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

It's been discussed many times before, try searching for rotateToFace and you may well find a working function.
Image Image Image
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

If you just want to rotate around the Y axis, then it's fairly simple.

Calculate the vector from the moving node to the target position. Call vector.getHorizontalAngle() on it. That will get you 3 Euler rotations, of which only X and Y will be non 0. You can ignore the X rotation, and then simply change your moving node's Y rotation until it matches the target Y rotation, and then off you go.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply