#### Archived

This topic is now archived and is closed to further replies.

# Quaternions

This topic is 5559 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''ve been having a couple of problems with quaternions. I''ve been learning them to make a camera class that works without gimble lock, the bane of euler rotations . Since when using quaternions to perform rotations the rotation you apply to the quat is done on the axis of the quat as it is. That works and I can get full 3D movement, however I''m wondering if there''s a way to use quaternions yet still somehow perform the rotations on it as aligned to the world axis. Anybody got some good ideas?

##### Share on other sites
Some ideas --
1. Use more punctuation.
2. Use better grammar.
3. Explain what "...perform the rotations on it as aligned to the world axis" means.

##### Share on other sites
rofl. Sorry bout that, I''m so piss poor and explaining things . I''ve sorted out my problem anyway. Thanks anyway though

##### Share on other sites
FYI, your grammar isn''t bad, b/c I can understand what you''re talking about and I''ve just delved into quaternions using Tot3DGPGurus as an intro--and Lamothe sure knows how to dymistify quaternions. First thing you need to do is buy his book. It costs 59 dollars in the US but I got it for 58 with my B&N discount card (saves 10%, so ~3% when taxed), but you don''t care. You must get this for quaternions and every other mathematical mystery of 3D graphics. From his book, this is what you must do; and it''s called using the Euler angles to rotate with a quaternion:
Quaternion rotation:
v = vector to rotate, axis of rot and degrees is encoded in quaternion q
v'' = q * v * q~
where q~ is the conjugate of the quaternion q, that has a unit-normalized vector to rotate around. The conjugate, which when multiplied by q (order-independently) yields the sum of the squares of q''s real terms (which when taken the square root of gives q''s norm or magnitude), ["The conjugate..."] is nothing more than the negation of the vector part of q. If the axis encoded in q were not normalized, you''d have to use the inverse of q, instead of its conjugate, which is obtained by q^-1 = q~/(|q|^2). And note that the magnitude is also sqrt q*q~, so when q is itself normalized or of magnitude 1, q/|q| is one, and q^-1 essentially equals q''s conjugate. Get it? If you don''t, then buying Tricks of the 3D... is a must, because I myself would not have gotten what I just said before I read that enlightening section. To add: q~ * v * q (notice the order) is a rotation in the opposite of the clock direction that the first formula yields.
Continuing...
Well basically, you need to encode the three word axis rotations (x-y-z) into q. When can be accomplished with quaternion multiplication of 3 different "q''s", where in each one the corresponding vector component (either i,j,k where xyz are scalars to) must contain the formula, that was given in the book, for rotation. So... if q is incoded normally with an axis and you have an angle of rot to pass in called theta (t for short), you''d have:
q = cos(t/2)*q0 + sin(t/2)*qV //---the imaginary vector part of q with the reals: q1, q2, and q3, and the imaginary coefficients i-j-k
Thus you''d expand to:
q = cos(t/2)*q0 + [sin(t/2)*q1 * i,
sin(t/2)*q2 * j,
sin(t/2)*q3 * k]//that''s qV
and in explicit 4D vector form, that becomes:
(q0,q1,q2,q3) //but I''m too lazy to type the trig stuff, and in the book he had the vectors with alligartor brackets, but b/c HTML script, can''t use here, but they look much niser than parentheses
Continuin once more, to your question:
qX = cos(t/2) * [sin(t/2)*q1 * i, 0 * j, 0 * k]
qY = same thing but the sin thingy in the j component
qZ = same thing but the sin thingy in the k component
And the old formula of v'' = q~ * v * q becomes:
v'' = (qX * qY * qZ)~ * v * (qX * qY * qZ)
v, and v prime will be quaternions with q0 as 0, b/c they''re only 4D vectors so they can be implemented with quats (as in "4". Oh shit....Look back at the qX,qY,qZ quats where I had t for every angle...t would actually be different fo each axis. LOL. Go figure

-leinad (if you feel the need to flame me )

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5

• 14
• 9
• 9
• 9
• 10
• ### Forum Statistics

• Total Topics
632912
• Total Posts
3009199
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!