View Full Version : I need an equation....

12-16-2002, 03:55 PM
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.

12-16-2002, 05:56 PM
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".


12-18-2002, 05:44 AM
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)
// Do all your glRotatef and glTranslatef stuff
glGetFloatv (GL_MODELVIEW_MATRIX, myMatrix);

This will make the "up" arrow always move the object "forward".