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.
How to rotate a scene node towards a point?
-
- Admin
- Posts: 3590
- Joined: Mon Oct 09, 2006 9:36 am
- Location: Scotland - gonnae no slag aff mah Engleesh
- Contact:
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.
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
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way