Quaternions problem

Started by
4 comments, last by ProgrammerDX 11 years, 12 months ago
Hello,

I'm having this odd behaviour with Quaternions.

I have 3 euler angles for Pitch, Yaw and Roll.

I want to make 3 quaternions from these 3 euler angles.

I want to convert the 3 quaternions to a rotation matrix that contains all 3 rotations finally. I do this by first multiplying all 3 quaternions to 1 quaternion, and then make a Matrix 4x4 from that final quaternion. I compute this final quaternion in the order Roll, Pitch, Yaw.

Then use that rotation matrix as usual with the scaling matrix * rotation matrix * translation matrix to build a transformation matrix.

The odd behaviour is that my object is becoming stretched / morphed if I use more than 1 euler angle. If I just use 1 angle (ie. pitch) then my object rotates like it is supposed to with no distortion (stretching/scaling effect) on the object.

An interesting point is that if I use for example Yaw and Roll 90 degrees (and Pitch 0), or any 2 angles 90 degrees and the other 0, then my object is totally invisible (like scaled to zero).
I noticed that in my final rotation matrix the values on the diagonal are all 0 in that case. I'm sure this is wrong as that is scaling 0 on a scale matrix....
I also noticed that the final quaternion has, in that example, the values (w,x,y,z): 0.5 -0.5 0.5 0.5

My final quaternion of (0.5 -0.5 0.5 0.5) makes the rotation matrix:

0 0 -1 0
-1 0 1 0
0 0 0 0
0 0 0 1


Anyone knows what's wrong?
Advertisement
Ah just noticed my Quaternion to Matrix code was wrong..

Anyway I've noticed that Gimbal Lock still occurs this way so kind of pointless to implement
Don't use Euler angles. If you start with those, any conversions to any other representations will not avoid gimbal lock. Instead, keep either a matrix or a quaternion and incrementally compose small rotations into it. Remember to renormalize periodically.
The reason why quaternions avoid gimbal lock is really that you don't have three axial rotations, but a single one around a single arbitrary axis. Three quaternions for three orthogonal rotations are just the same as Euler angles, only with slightly more complicated math.
My 'object' currently keeps 1 vector with angles for all 3 axes. With those values I make a rotation matrix for each axis and multiply them together to form a rotation matrix.
If I want to rotate around an axis, I can just add/subtract the value for that axis.

If I want to replace this with Quaternions, my object will keep 1 Quaternion?
And if I want to rotate that Quaternion around an axis (could already be rotated), the steps i would take is:?
- Make a quaternion to represent new rotation?
- Multiply object Quaternion with that new Quaternion?

I have a feeling that still causes Gimbal Lock.

How do I go about using Quaternions if 3d program exporters usually export rotation in euler angles?

If I want to replace this with Quaternions, my object will keep 1 Quaternion?

Yes.

And if I want to rotate that Quaternion around an axis (could already be rotated), the steps i would take is:?
- Make a quaternion to represent new rotation?
- Multiply object Quaternion with that new Quaternion?[/quote]
Yes. Remember to normalize the quaternion every so often. It's actually pretty cheap to do, so just do it every time.

I have a feeling that still causes Gimbal Lock.[/quote]
Your intuition is malfunctioning. :)

How do I go about using Quaternions if 3d program exporters usually export rotation in euler angles?[/quote]
You do the conversion when you read in the file.
Hehe ok.

You know every article on the internet about Quaternions in games starts very promising, giving you awesome definitions and saying that it's imaginary in 4D and is just so cool and awesome. And then it continues about that it is better than Euler rotation and that it avoids Gimbal Lock oh it's so good. And then we are about to get to the point where the article should start explaining about how to actually properly fully implement a Quaternion to replace Euler Angles in a game but then the article stops and it's like the writer of the article was too stupid and don't know shit about how to apply Quaternions either.

Pisses me off this.

Sorry for rant :P

This topic is closed to new replies.

Advertisement