I’m setting up a flying game, with the viewpoint as the aircraft. I have forward movement (translating along negative z-axis) set up automatically at X-rate per frame), there is a user joystick input which allows rotation for roll & pitch (yaw is derived from roll separately). So, it is my understanding, (which I have tested) that the following is true:
glRotatef (pitch, 1.0, 0.0,0.0) //user joystick input - (pitch in this example)
glTranslatef (0.0,0.0,x); // automatic forward motion
This results in a change in the line of sight (rotation) following by a translation along this line of sight. Basically a change in heading - which is what I want. However, the rotation axis remains fixed at the origin, rather than shifting with the translation. so if you pitch up after having pitched down the rotation occurs from a point far behind where you are current positioned.
I realise this can be solved using:
glTranslatef (0.0, 0.0, x); // automatic forward motion
glRotatef (pitch, 1.0, 0.0, 0.0); // user input
However, this (unsurprisingly) no longer changes your heading, and translation continues to occur in the same direction, NOT along the line of sight. Instead rotation just changes where you are looking as using GluLookAt would.
My issue is in how to combine these two opposing functions so that the ‘plane’ rotates about it’s current position AND the subsequent translations move along the line of sight. Any suggestions or pointing me in the right direction would be much appreciated. I’ve read a great deal on this matter but copious reading nor many hours of trial and error hasn’t provided a solution yet.