I need an equation....

I have an object that I want to move around. When the left arrow is press I have: newY -= 90.0 and for right key: newY += 90.0; The up and down arrows move the object along the z and x axis. Is there an equation people use to determine what direction the object is facing? I know this is more of a programming problem but it’s easier for OpenGL users to understand, but does anyone have an equation like this they used in their projects? The direction of the object will determine if i should change the x or z variable.

Assign a direction vector to your object. Your view vector is (0, 0, -1)
Do a dot product.

Not sure if that answers your question, but that is one way to know an “object’s direction”.

V-man

If it’s “car-driving” movement you want, do a forum search for “correct transformations”. What you basically want to do is to store the object’s matrix between each frame, and then reload it the next. Like this:

float myMatrix[16];
while (1)
{
LoadIdentity();
LoadMatrix(myMatrix)
// Do all your glRotatef and glTranslatef stuff
glGetFloatv (GL_MODELVIEW_MATRIX, myMatrix);
}

This will make the “up” arrow always move the object “forward”.