# quick question on rotations and such

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

## Recommended Posts

i am making a game engine, and i need to create a function that gives me rotation about the x, y, and z axis if i give it and up vector and a forward vector. in other words, i need something that tells me the orientation of an object if i give the function a vector for the direction it should be facing and a vector for which way is up. any help is useful, but the more complete the better thanx! note: rotation is done by rotating about the y axis, then x, then z, if it makes a difference.(probably does) also, i'm using glRotatef, if that's important [Edited by - rockwall on November 24, 2005 2:58:22 PM]

##### Share on other sites
It does. It can't type all of the equations right now, but you might want to check out Euler Angles.

##### Share on other sites
actually, i've been using euler angles, but i'm still stuck. i'm rotating with this:
glRotatef(yrot, 0, 1, 0);
glRotatef(xrot, 1, 0, 0);
glRotatef(zrot, 0, 0, 1);

##### Share on other sites
I found this site to be particularly helpful. It's the documentation for some MathWorks library, however it covers the math behind doing all the common conversions between rotation matrices, Euler angles, axis/angle, and quaternions.

The gist behind this conversion is to multiply out the three rotations in symbolic form to get a final matrix representing the rotation, and then solve for the angles given an existing numerical rotation matrix. The site I linked shows how to perform this conversion for the XYZ case. To create the numerical rotation matrix, given the up (U) and forward (F) vectors create the right vector using F x U. Decide which vectors represent the X, Y, and Z axis. Then, create a matrix where the X vector is the first row, the Y vector is the second row, and the Z vector is the third row. That covers 9 of the 16 elements, the rest should take on the form of the identity matrix (all 0 except for element (4,4) which should be 1). It's important to remember that this can degenerate in cases where the Euler angle rotation would cause Gimbal Lock, which manifests itself in this conversion as a division by 0 using atan.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 14
• 11
• 28
• 15
• 41
• ### Forum Statistics

• Total Topics
634837
• Total Posts
3019558
×