View Full Version : Flight Simulator
03-05-2000, 11:53 AM
I'm working on a flight simulator for a college class, and it's almost all done. I just have one problem left. I'm trying to have an alternate view of the plane, meaning instead of being in the cockpit, to show the plane from the outside.
So I have the plane coordinates, and when I draw the plane, and start flying, the plane stays in place and the camera continues to fly. here's a bit of my code:
glTranslated(...) // camera rotations and
tranlslation by plane
drawLand(); //this is fine
drawPlane();//in drawPlane I'm drawing the plane using the plane coordinates, but it just stays in place when I start flying.
I tried using glPushMatrix() and then glLoadIdentity and then drawing the plane and I tried without it, and many other options, but nothing works. Please Help!!
Thanks in advance.
It seems like the translation isn't applied when you draw your plane. Are you sure you aren't doing something that cancel the translation in drawLand or in DrawPlane?
03-06-2000, 02:53 AM
In drawLand() I just draw the land using glVertex calls, with a triangle strip (in a display list).
Then in drawPlane I draw the plane using glVertex and triangles, using the plane coordinates.
I tried all combinations of glPushMatrix and PopMatrix, and LoadIdentity and Rotations, and what not. I have no idea what's wrong with it.
I'm trying now to convert it to using gluLookAt instead of glRotated and glTranslated statements, but i'm still having problems with the up vector. Maybe when I do that, it'll work better. (But I'm still open for suggestions about how to fix it using rotations and translations http://www.opengl.org/discussion_boards/ubb/smile.gif )
[This message has been edited by Tidhar (edited 03-06-2000).]
03-07-2000, 06:00 AM
Originally posted by Tidhar:
I tried all combinations of glPushMatrix and PopMatrix, and LoadIdentity and Rotations, and what not.
This is not clever... I too had my bad times, randomly trying some solution on my code... some time ago, but then if it worked, I never could understand what was the real solution.
So, I suggest that you take the red-book, and read the chapter on transformations. Try to understand the different stages: from object-space to world-space, on to the eye-space. The point you are missing is the interaction between world-space and eye-space: from your description it seems that plane and ground are transformed by the same matrix. The camera is a higher level in the hierarchy of transformations. You should separate camera/plane matrices, and you'll get ability to easily implement different camera locations on the scene, independently from the plane.
I.e. it's an error to have a camera depend on an object transform.
03-07-2000, 07:11 AM
As I understand it, all I have is one matrix (MODELVIEW, not talking about projection now), which is used for the whole world. I do the rotations and translations using the current plane location, and then I draw the land and plane. So, if the land is drawn using world coordinates after the rotations, why would the plane be any different? To change the plane coordinates I just do some calculations of the angles and then get the next postition for it. Then when I go back to the display function I do the transformations and rotations, and draw the land and the plane again. What am I missing???
03-09-2000, 04:48 AM
ok, I got the plane to fly with the camera http://www.opengl.org/discussion_boards/ubb/smile.gif
It worked if I just don't do a push matrix and anything else, just draw the plane (I don't know how, it didn't work the first time I tried it like this http://www.opengl.org/discussion_boards/ubb/smile.gif ). Anyways, now when I fly, say I turn to the right, the plane stays horizontal, and it doesn't even stay in the middle of the screen, it goes left (it actually stays in place while the camera turns right).
Any ideas how to fix this?
03-10-2000, 06:54 AM
Originally posted by Tidhar:
It worked if I just don't do a push matrix and anything else, just draw the plane.
Obviously. If you don't push the matrix you are transforming by the same matrix of the camera.
Anyways, now when I fly, say I turn to the right, the plane stays horizontal, and it doesn't even stay in the middle of the screen, it goes left (it actually stays in place while the camera turns right).
There is quite a lot of confusion in this argument. Let's try to clarify things.
Plane is the airplane.
Turning right means you are rolling the plane, right? That is you are applying a rotation on the local (plane's longitudinal) Z axis to the plane object.
The camera is an abstraction simulated by the use of the stack of MODELVIEW matrices.
Each object has it's own position and orientation in the world.
For the camera you should also keep position/orientation.
When the camera moves, it's like all world object were moved in the opposite direction by the same amount. Idem for rotations.
Now, the land has alway the same position/orientation. The plane is continuously updated. The camera should be updated as needed: if it's on the interior of the plane, it should track the plane's position/orientation; otherwise it could change freely.
- set camera pos/rot on the matrix
- for each object in the world (does not matter if it's a plane or a pigeon):
- set object pos/rot
- render object
Note that camera matrix is translated/rotated to negative values (see above), so when you are looping to render the plane (viewing from inside) it happens that the plane and camera pos/rot are the same, but being the camera transformed negative respect to its values will exactly compensate for the plane transform: this results in the plane maintaining a fixed position relative to the camera, but everything else will get correctly transformed.
03-13-2000, 04:07 AM
It works great now.
Thanks for straightening me out.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.