Can someone help me on a 3D movement problem…I got my code to move me in whatever direction I’m facing, however, when I turn, “I” rotate around my 3d world instead of it rotating around me. (Does that make sense?) I don’t pivot in place…I’m struggling with the Trig for this so any help would be greatly appreciated…Thanks again…My code for what I have is below…
Obviously, like in everything in this world, there are two ways to do something: the one you want and the opposite.
Murphy says that the first one you’ll find is the one you’re not looking for.
Your code is right, except for a detail: you are not moving what you would want. Maybe I’m a bit slow early in the morning, but xPos and yPos are in your code coords of each object in your world, or rather of the world transform matrix, effecting over everything at once? Both are going to work, but the ‘pivot’ isn’t gonna be the same.
I use the following set of calls to position the “Camera” (ie. Me) and then I draw the objects…
fZoom is just a way of changing the “Zoom” of the camera (typically set to 0.5).
// Set up the projection matrix.
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-fZoom, fZoom, -fZoom, fZoom, 2.0, 2000);
glRotatef(Rot.xAng, 1.0f, 0.0f, 0.0f);
glRotatef(Rot.yAng, 0.0f, 1.0f, 0.0f);
glTranslatef(Pos.xPos, Pos.yPos, Pos.zPos);
glMatrixMode(GL_MODELVIEW);
If I draw all my objects now (with their transformations) then they appear in the correct position. It is IMPORTANT that I use glLoadIdentity() (or glPush/PopMatrix) to reset the transformation back to the center of the OpenGL universe before drawing each object. The critical call may be the glMatrixMode(GL_MODELVIEW);.