Quaternion Translation..
I have asked this question before...
But does anyone know how to do translations using quaternions? Please help!
Thanks!
[edited by - zealouselixir on August 27, 2002 6:00:20 PM]
Unit Quaternions are ONLY for rotations. A point and a quaternion specify an exact location and facing in 3D space!
Chromebender...
So how do you combine the two? Or can you? I have done the rotations using quaternions, scaling using the gl scaling function, but no translation...at least not yet.
So how do you combine the two? Or can you? I have done the rotations using quaternions, scaling using the gl scaling function, but no translation...at least not yet.
bah yet AGAIN a post to this board failed to be submitted. here goes:
Evidently you know how to do rotations by keeping a rotation quaternion, converting it to a matrix and multiplying the modelview matrix by the rotation matrix.
To do a translation, simply multiply the matrix or vector by a translation matrix composed of:
1 0 0 0
0 1 0 0
0 0 1 0
x y z 1
where x,y and z are the distance to translate the previous transformation matrix
if you wanted to handle scaling yourself, a scaling matrix consisting of
sx 0 0 0
0 sy 0 0
0 0 sz 0
0 0 0 1
should do the trick.
So if you wanted to rotate the camera say PI/2 radians around the z axis, you would convert this angle, axis pair to a quaternion, then convert the quaternion to the rotationMatrix. Then to translate the camera, create your transformation matrix for whatever x,y and z you want. Next retrieve the modelview matrix and multiple it by the translation matrix then by the rotation matrix (the reverse order of the way you want the operations performed).
Evidently you know how to do rotations by keeping a rotation quaternion, converting it to a matrix and multiplying the modelview matrix by the rotation matrix.
To do a translation, simply multiply the matrix or vector by a translation matrix composed of:
1 0 0 0
0 1 0 0
0 0 1 0
x y z 1
where x,y and z are the distance to translate the previous transformation matrix
if you wanted to handle scaling yourself, a scaling matrix consisting of
sx 0 0 0
0 sy 0 0
0 0 sz 0
0 0 0 1
should do the trick.
So if you wanted to rotate the camera say PI/2 radians around the z axis, you would convert this angle, axis pair to a quaternion, then convert the quaternion to the rotationMatrix. Then to translate the camera, create your transformation matrix for whatever x,y and z you want. Next retrieve the modelview matrix and multiple it by the translation matrix then by the rotation matrix (the reverse order of the way you want the operations performed).
Another tip: Keep track of your camera (or object)''s up, right and direction vectors. This makes it easy to transform movement relative to the camera or object frame into world coordinates. Previously I had a problem where my camera controls were locked onto the x, y and z axes regardless of where the camera was pointing, which made camera control a real pain and in some cases impossible. Now it flies around in true 6-d.o.f. descent style
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement