Quaternions(again)

Started by
1 comment, last by oscar_ 22 years, 1 month ago
From looking at the forum I''m sure everyones sick of quaternions, but my question is simple: if quaternions are used to "represent a transformation" such as rotation in the form of 4 numbers w,x,y,z then how do I set these values for a transformation (or alter them) and then how do I use these values to do the transformations (I only need to end up with an angle and a vector for the opengl rotatef function.) I dont intend to understand how they actually work, at the moment, just to resolve my frustration about my failing 3d program. The "why"s and "how"s of it will be resolved some day, but can somone just answer these hopefully more straight forward questions. The help really will be appreciated, thanks.
Advertisement
axis (X,Y,Z) angle (A) to quaternion (w,x,y,z) :

normalize (X,Y,Z) (X^2+Y^2+Z^2==1)
w = cos(A/2)
(x,y,z) = (X,Y,Z)*sin(A/2)

quaternion to axis/angle
A = 2*acos(w)
(X,Y,Z) = (x,y,z)/sqrt(1-w^2) // irrelevant if A == 0

quaternion to transformation matrix (will be faster than glRotate, use glMatrixMultiply). You might need to use the transposed of the following matrix though (element ordering...)

| 1-2yy-2zz 2xy+2wz 2xz-2wy 0 |
| 2xy-2wz 1-2xx-2zz 2yz+2wx 0 |
| 2xz+2wy 2yz-2wx 1-2xx-2yy 0 |
| 0 0 0 1 |
<br><br>Edited by - Fruny on February 25, 2002 5:41:13 PM </pre>
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Thank you so much. I''ve been looking for that answer for quite a while, that''s just I wanted. Thanx again.

This topic is closed to new replies.

Advertisement