Translations with Quaternions

I am writing an engine to do 3D rotations and movements in 3D space. I’m using quaternions to do the rotations based on yaw pitch and roll and have gotten my ship in space to rotate fine. However what I want to do is to have it move in the direction of the final angle. Only problem is all I have to work with is just one angle. How can I use this to set up a direction to tell my plane to move in? Thanks for the help.

-Dan

Convert your quaternion into a rotation matrix and you have your local x, y and z unit axes there.

I already know how ot get the x y and z unit angle axes but this does not get me anywhere. They are only used for specifying rotation numbers and vectors. I need something to help me actually move the camera in that direction in a distance I can specify. As far as I can tell there is no way of doing this.

Is not one of those unit vectors pointing in the camera’s forward direction? Just scale it by the amount you want to move and add it to the camera’s current position.

[This message has been edited by DFrey (edited 07-29-2000).]

I’m not sure what the three numbers i’m left with represent exactly but they are used as the x, y, and z values in the glRotate command which point me in the right direction. I’ve tried scaling them and using them in glTranslate but this does not work right. I must be missing some key information from the quaternion calculations.

Hmm, if you have the camera rotation angles, which are normally used in some glRotate calls in your program, you have all necessary informations. Let’s assume the camera look in the direction of the positive z-axis in a left handed coordinate syste, than simply feed a vector (0,0,1) through the upper left 3x3 of the 4x4 OpenGL matrix and the result is the direction vector in which your camera points in world coordinates.
Now scale this vector by the amount of distance you want to move the camera and translate this onto the camera position in world space and you should end up at the desired location.

I’m not quite sure I understood that last post. Thing is, I don’t have all the angles, its just one angle and then 3 vector numbers that range from -1 to 1 that are put into the single glRotate call. What I need to end up with are 3 numbers I can use for a glTranslatef call to move in all three directions. One final number like you said is not enough. If i could wind up with three actual angles between 0 and 360 in the x, y and z directions then I could probably use sine and cosine functions to determine vector numbers to move by in the glTranslatef call.

http://www.tasteofhoney.freeserve.co.uk/vectorframe.html

Sorry for the misunderstanding.
I Referred to this sentence and thought you had the angles for all three axis.
>>I already know how ot get the x y and z unit angle axes but this does not get me anywhere. They are only used for specifying rotation numbers and vectors. <<

Nevertheless, if you have the orientation stored as angle and rotation axis, you can convert this to a matrix representation (like with quaternions).
Send a vector (0,0,1) through this matrix and you’ll end up with the vector which represents the local z-axis in form of a world vector. The rest was said in the previous post.

Okay, now my question is how exactly do you send the vector (0,0,1) into the matrix? Also what exactly do I read from the resulting matrix that gives me my final world coordinates to change by? I guess my misunderstanding is due to my lack of being able to truly figure out matrices and how they work specifically. Thanks for the help.

The calculation would go like this:
v’ = M * v
with v’ the desired direction in world space, M describing your 4x4 orientation matrix and v = (0,0,1,1).

Lots of room for optimizations here!
As only the z-component of the vector contributes to the final direction, this direction is already in the orientation matrix at v’ = (m13, m23, m33) (third column of the upper left 3x3 matrix.

[This message has been edited by Relic (edited 08-01-2000).]

Won’t this do the trick?

GLfloat forward[3];

forward[0] = M[2];
forward[1] = M[6];
forward[2] = M[10];
normalize(forward); //just in case =)

If I’m not misstaken the third column of the camera-matrix is the forward vector.

You can also do the following:
forward[0] = sin(e)*cos(a);
forward[1] = sin(e)*sin(a);
forward[2] = cos(e);

Where a is the azimuth (jaw) angle and e is the elevation (pitch) angle.

Yes, that is what I meant.
Watch out, I’m not sure about the matrix order in your example.
OpenGL matrices are stored column-major like this

m0, m4, m8, m12
m1, m5, m9, m13
m2, m6, m10, m14
m3, m7, m11, m15

so your example takes the third row, not the third column.

I just hope then that my quaternion matrix is similar to the matrix you guys are describing. If it is, then do I just use the first three values in the third row to tell my program to move by? Thanks for all the help.

I got arount to trying out that matrix stuff and it worked beautifully. The matrix in my program worked just as you said Relic with the third row holding values for the forward vector. I also found something that may have prevented other methods I thought might work from working. Apparently I had some other code left in the program that was changing the x y and z values as well through a different. After taking this out and reading the values for the third row I got everything to move just as it should. Thanks everyone for all the help.