# Problem with plane simulator rotations

im trying to program a little plane simulator
but i cant do the right rotations.

im using this code before drawing my objects

glRotated(-Roll,0.0,0.0,1.0);
glRotated(-Pitch,1.0,0.0,0.0);
glTranslated(-XPos,-YPos,-ZPos);

but it works only if at least 1 angle =0

can someone help me with that…

You’re general method is flawed for a flight simulator approch. You’re method is better for a first person shooter where speed is more critical and full 3d motion is not allowed. The prefered method for flight simulator would be to use Quaternion rotations. This will prevent Gimbal lock which could be what you’re running into when you start rotating you’re 3rd axis. I good place to learn the basics about gimbal lock and quaternion space is at http://www.gamasutra.com/features/programming/19980703/quaternions_01.htm

Hope that helps.

Change the order.
Translation first then
Remember it is the coordinate system you are moving.
Regarding quaternions you want need them for the drawing, just for the dynamical equations since the derivatives for the Euler angles (heading,pitch,roll) are undefined when pitch is equal to ±90 degrees…

Hope it helps…

a similar discussion regarding rotations with Euler angles, Gimbal lock, and overcoming these has taken place in the advance forum. perhaps this discussion could shed some light?

http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/000541.html

thanx to all

Hi,

I think your order of rotations is correct, because you are doint exactly the opposite than it is usual in flight mechanics (usual is first, yaw, then pitch and finally roll). Because you want to draw the scenery from the body axes of the plane, I think you are right. Have a look to the command gluLookAt. It is very usefull.

Regarding quaternions I have found a nice report from the Naval Postgraduate School which exactly explains what you need for flight simulations. Its title is: “NPSNET: Flight Simulation Dynamic Modeling using quaternions” written by Joseph M. Cooke, Michael J. Zyda, David R. Pratt and Robert B. McGhee. I have found it in the net, but I don’t remember the address. But I was using www.google.com to find it, so I would recommend you to start there.

Miguel