PDA

View Full Version : Flight Simulation transformation problem



AlepGraphics
02-14-2007, 10:07 AM
hey ..
i'm starting a simple flight simulator .. take the following pic for example:
http://i32.photobucket.com/albums/d17/Merza/1.jpg

the view angle (in red) is about 100deg, and the red object is drawn by :
glTranslate3f(5,0,-5);
draw();

and for the ship filght simulation i used this function ( mentioned in OpenGL redbook, edition 5 ), which mimics ship's movement in moving the environment on the contrary .. and this func is called before sart drawing any object in the scene :

void PlaneView(GLfloat planeX, GLfloat planeY, GLfloat planeZ, // the plane’s position
GLfloat roll, GLfloat pitch, GLfloat yaw) // orientation
{
// roll is rotation about the z axis
glRotatef(roll, 0.0f, 0.0f, 1.0f);
// yaw, or heading, is rotation about the y axis
glRotatef(yaw, 0.0f, 1.0f, 0.0f);
// pitch is rotation about the x axis
glRotatef(pitch, 1.0f, 0.0f, 0.0f);
// move the plane to the plane’s world coordinates
glTranslatef(-planeX, -planeY, -planeZ);
}

so for now, when i'm trying to move to ship toward the red object (or moving the object closer to ship) .. the red object is going naturally on the new Z-Axis as shown ..
http://i32.photobucket.com/albums/d17/Merza/2.jpg

how can this be solved, achieving that whatever the environment is rotated, moving forward is done toward the view center ?!
thankfully ...

plasmonster
02-15-2007, 04:13 AM
You might want to look at quaternions for this kind of thing; they don't suffer from the shortcomings of a fixed rotation sequence, and they're just plain cool :-) Basically just accumulate your quaternion transformations, and normalize after each update. The forward axis, say Z, is the 3rd column of the resulting rotation matrix.

Hope it helps.

AlepGraphics
02-16-2007, 03:23 AM
well, i dont feel like to change my theory-infrastructure .. further more, since this way is mentioned in both "redbook" and "game programming", i thought it's recommended, but failed to make it come true correctly ..
anyone tried it successfully ?!
p.s. thx anyway ;)

plasmonster
02-16-2007, 07:31 AM
I think you're missing the intent of the example (pilotView?); it simply illustrates the use of viewing transformations with a airplane pilot as an example. It's not meant to be a full-blown flight sim ;)

Understand that the Redbook in particular is targeted at those interested in the OpenGL API, so it was probably felt that the subject of quaternions, and the chapters required to explain and code their applications, would have gone a bit afield; whereas Euler angles and basic rotation sequences are (or should be) at least familiar to anyone pursuing graphics, and they are an intrinsic part of the OpenGL API besides.

As time goes by, you may find quaternions nicer to work with and more flexible in this context. In addition to being free of singularities ("Gimbal Lock", which can arise in Euler angle rotation sequences), they lend themselves particularly well to interpolation (smooth camera motion, animation, etc.).

Anyhoo, to do what you're asking, if I understand it correctly, requires that something be accumulated incrementally, either by transforming the world or the camera (I prefer the camera). Try thinking in terms of incremental rotations and translations based on increments of time, rather than absolute angles in a fixed rotation/translation sequence (it's just not going to work that way).

Hth