quaternions & rotations issue?

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
random
Posts: 158
Joined: Wed Aug 11, 2010 6:01 am

quaternions & rotations issue?

Post by random »

Hello let me explain a problem i have on a example

I have a seeking node which receives its rotation by functions with quaternions.
Anything looks OK if i just use keyboard inputs on loop for that.
Now i want to make an animator for rotations with that.

NOW comes my problem while i calculate the rotation from my seeking node to the target with getHorizontalAngle i also need the current rotation of the seeking Node.
But due the Quaternion Rotation(transformation) i get values i can not realy use.

Now my example...

On the Y Axis the angle from Aeeker to Target is 189° DEG so the shortest way would be to rotate it -171°.

But when the Seeker reaches a rotation of 270° (or even -90°) the quaternion.toEuler().Y does not count like -89 , -90 , -91 ... it counts -89, -90, -89.. so in the opposite direction like bevore although the rotation continous in the right direction.
I also recognized that from -90° on the X-Axis which was 0° flipped to 180°.
I thought ok, lets use node->getRotation().Y instead, but here i got the same values -89, -90, -89 ..
I thought ok lets get something usefull via Matrix, as you guess i received the same result.

My current way to get a usefull result is to get the y rotation by:

Code: Select all

    quaternion rotQuat;
    vector3df fromVect = emptyZ->getAbsolutePosition();
    f32 sinusY = 2 * radToDeg(asinf(myQuat.Y));
emptyZ is a empty node i added as child to the seeker at position 0.0.1 just to get a direction vector.
This code works yet when the seeker has a rotation of 0.0.0° and so that the target will not go across the +-180° world angle of an axis.

i think i can build something that works combined from both values toEuler().Y and the sinusY but i asked myself iif there may is annother way that i missed to think of?

Any kind of help would be usefull, thx in advance
Post Reply