Sign in to follow this  
rockwall

quick question on rotations and such

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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this