PDA

View Full Version : 6 degress of freedom for flight sims



lsdi
12-31-2001, 07:14 PM
I wrote this to make a 6DF game, but something its wrong:

- I CANT PITCH MORE THEM 90
- THE ROLL ITS NOT SMOOTH - ITS LIKE WAVES
- I DONT KNOW TO MOVE IN THE CAMERAS DIRECTION

Can Anyone help me or tell me where I found more info?

here is the code:

ps. sorry for bad english.

struct Camera
{
float x, y, z;
float yaw, pitch, roll;
} cam;
float tx, ty, tz=0.0f;
float rx, ry, rz=0.0f;


void mundo(void)
{
tx=cam.x+cos(cam.yaw)*0.5;
ty=cam.y+sin(cam.pitch)*0.5;
tz=cam.z+sin(cam.yaw)*0.5;
rx=sin(cam.roll)*0.5;
ry=cos(cam.roll)*0.5;
rz=0.0f;
glPushMatrix();
gluLookAt(cam.x,cam.y,cam.z,
tx,ty,tz,
rx,ry,rz);
glCallList(Lground);
glPopMatrix();
}

nutball
01-02-2002, 07:56 AM
If you want to write a flight sim., then I don't think maintaining seperate yaw, pitch and roll angles is a good idea. You get all sorts of headaches this way (eg. gimbal lock, and how to compute "up").

Try using quaternions, or update your model-view matrix directly (though there are issues with conditioning of the matrix with this approach I think).

jwatte
01-02-2002, 08:50 AM
Using a quaternion for your orientation is certainly one popular way of making sure you don't get these problems. When rolling/pitching/yawing, you just add in an appropriate new quaternion (oriented in the reference frame of your current).

An alternate mechanism is to keep two vectors; say "right" and "up". When you yaw, you rotate "right" around "up". When you pitch, you rotate "up" around "right". And, last, when you roll, you rotate both right and up around (right cross up). Make sure you re-normalize these vectors ever so often (every frame is probably OK if it's only for one object).

Adjust your cross production function and/or vector math based on the left- or right-handedness of your coordinate system.

Going from these vectors to a viewing matrix is pretty simple: right, up and (right x up) represent the three x/y/z rows of your viewing matrix; just slam translation in there and go!