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.