Dingo Egret

03-10-2004, 03:58 PM

Hello!

I was hoping someone could show me some examples (with code!) of how rotation can be achieved though the use of quaternions.

I have studied several quaternion tutorials that i've found on the web and they all do a great job in explaining the math and the theory behind quaternions but they all assume that i already know how to put them to work.

So far, i've been using glRotatef()'s to do sequential rotations first in one axis then in the next one and then in the next one. I often end up twiddling the order of these rotations until it does what i want, but it's all trial and error. I'm also not sure if i've encountered the infamous Gimbal Lock... to tell the truth i don't fully understand when or why it happens.

If i understand it correctly, by using quaternions to generate rotation matrices, and then applying these rotation matrices, i can solve my "order of rotations" problem and gimbal lock. Right?

Say i want to rotate an object A degrees along the x axis, B degrees along the y axis and C degrees along the z axis.

Is this information in what OpenGL describes as "euler angles" form?

Do i have to then use something like glEulerToQuat() to transform it into a quaternion and then glQuatToMat() to further transform it into a matrix that i can then apply with glMultMatrixd()?

Why is there no function to transform from euler angles to a matrix directly, BTW?

Say i have the following code:

glPushMatrix();

glRotatef(A, 1.0, 0.0, 0.0);

glRotatef(B, 0.0, 1.0, 0.0);

glRotatef(C, 0.0, 0.0, 1.0);

glutWireSphere(1.0, 30, 30);

glPopMatrix();

How can i do the same thing using quaternions?

Thank you very much for the info.

I was hoping someone could show me some examples (with code!) of how rotation can be achieved though the use of quaternions.

I have studied several quaternion tutorials that i've found on the web and they all do a great job in explaining the math and the theory behind quaternions but they all assume that i already know how to put them to work.

So far, i've been using glRotatef()'s to do sequential rotations first in one axis then in the next one and then in the next one. I often end up twiddling the order of these rotations until it does what i want, but it's all trial and error. I'm also not sure if i've encountered the infamous Gimbal Lock... to tell the truth i don't fully understand when or why it happens.

If i understand it correctly, by using quaternions to generate rotation matrices, and then applying these rotation matrices, i can solve my "order of rotations" problem and gimbal lock. Right?

Say i want to rotate an object A degrees along the x axis, B degrees along the y axis and C degrees along the z axis.

Is this information in what OpenGL describes as "euler angles" form?

Do i have to then use something like glEulerToQuat() to transform it into a quaternion and then glQuatToMat() to further transform it into a matrix that i can then apply with glMultMatrixd()?

Why is there no function to transform from euler angles to a matrix directly, BTW?

Say i have the following code:

glPushMatrix();

glRotatef(A, 1.0, 0.0, 0.0);

glRotatef(B, 0.0, 1.0, 0.0);

glRotatef(C, 0.0, 0.0, 1.0);

glutWireSphere(1.0, 30, 30);

glPopMatrix();

How can i do the same thing using quaternions?

Thank you very much for the info.