Getting the angle of a rotation. getHorizontalAngle?

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
Delee
Posts: 18
Joined: Sat Apr 14, 2007 8:36 am

Getting the angle of a rotation. getHorizontalAngle?

Post by Delee »

I think I might be doing something wrong. Take for example the following picture.

Image

The object is rotated to face the direction of the red arrow. This works correctly. The rotation is smooth and no problems occur. However, I need to calculate the angle of the rotation as represented by the blue arrow.

If the object is facing the front, the angle is zero. If it turns, what is the angle of the rotation?

Now I assumed this was done using getHorizontalAngle, but I get some crazy results. When the object is stable, I get a fairly consistent direction. However, if I move the position of the object, the horizontal angle is completely wrong.

It can switch from being 315 at a stable point, to about 220 when I am moving the object. When the character is again stable, it eventually goes back to 315.

Here is the general code.

Code: Select all

vector3df rotation = node -> getRotation();
vector3df angle    = rotation.getHorizontalAngle();
I have tried using both angle.X and angle.Y, although I assume angle.X is the one I want. Am I using the wrong function? If there isn't any function I can use, how would I calculate the angle based on the rotation?

Any help is greatly appreciated.
SilentBob
Posts: 3
Joined: Thu Mar 08, 2007 12:11 pm

Post by SilentBob »

AFAIK, what you're looking for is the

Code: Select all

node->getRotation().Y
The rotation returned is a vector with each component equal to the rotation in degrees around that axis.

getHorizontalAngle() would be used say if you had a veloctity vector and wanted to work out the angles from that. Or if you wanted to work out the direction from one point to another.

Code: Select all

//target & node are both ISceneNode*
vector3df diff = target->getRotation() - node->getRotation();
vector3df angle = target.getHorizontalAngle();

//now angle.Y is the angle from node to target around the Y-axis
Post Reply