Skip to main content
gamedev.net
🔒 Locked

quaternions

Started by Ataru Apr 11, 2002 at 6:14 PM 5 replies 500+ views
Original Post
Ataru
Ataru
I''m having a little bit of trouble keeping a quaternion camera centered. I have a x,y,z position, and a quaternion from which I can derive the direction vector. I also have a left and an up vector. What I can''t seem to be able to do, is generate new quaternions to multiply to my original one, so that my up vector is always pointing up (i.e. no need to rotate around the direction vector) I try to do this (but I can''t seem to get it to work. Anyone tried to do something like it?
sQuid
sQuid
If you want to do a rotation through an angle theta about your up vector n (which I''m assuming is normalised) then the quaternion representing this rotation is

q = (cos(theta/2), sin(theta/2)*nx,sin(theta/2)*ny,sin(theta/2)*nz)

The rotation is applied to quaternions p = (0,r) representing a position r like so: q p q-1.
Ataru
Ataru
I may not be getting what you''re saying, but that''s for a rotation of theta around the up vector, right?

What I''m looking for is, after slerp, the up vector may be not be perpendicular to the world plane, and I need to know how to get the angle to rotate the quaternion so that it is.

Maybe what you''ve shown me does that, but if it does, I don''t really understand how.
executor_2k2
executor_2k2
"The rotation is applied to quaternions p = (0,r) representing a position r like so: q p q-1."

Would you mind breaking that sentence up, please? In the end, p will hold the new camera position? What is r? Is r a vector? I dont understand what you mean by position. Thanks.
Well, that was a waste of 2 minutes of my life. Now I have to code faster to get 'em back...
sQuid
sQuid
What I''m looking for is, after slerp, the up vector may be not be perpendicular to the world plane, and I need to know how to get the angle to rotate the quaternion so that it is.

Oops, sorry. So you want to rotate some vector v to the ''up'' vector u.

Use the vector cross product to get the angle theta and rotation axis r

v x u = |v| |u| sin(theta) r.

Would you mind breaking that sentence up, please? In the end, p will hold the new camera position? What is r? Is r a vector?

A point P in 3d can be represented as a triplet (px, py, pz) or alternatively as a vector r representing its displacement from the origin.

As a quaternion P is represented as p = (0,px, py, pz) = (0,r. After applying a rotation represented by q new position is given by the vector r'' where
(0,r'') = q p q-1.

executor_2k2
executor_2k2
quote:
Original post by sQuid

Use the vector cross product to get the angle theta and rotation axis r

v x u = |v | |u | sin(theta) r .



I am suffering from the problem of my camera not staying in one position. The axis keep getting changed and I eventually incur gimbal lock. How can I fix this. I am using glRotate to rotate my scene, which takes the parameters of the angle of rotation and the axis of rotation. How can I use the concept of the up and right vectors to keep my axis the same? Thanks.
Well, that was a waste of 2 minutes of my life. Now I have to code faster to get 'em back...
Ataru
Ataru
Hmmm, that''s what I do, but I can''t seem to get it to work. Must be a bug in my program, I''ll look at the code again.

Thanks for the help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.