How to implement flight movement?
I want to implement flight movement for a 3d space game called "Galactic journey". I have the animation and the scenery finished. It is based on the "Galactic journey" screensaver which I have developed:
One example of a flight movement would be this:
Move forwards when pressing the up key and backwards
when pressing the down key.
Spin sideways when pressing the left and right keys.
Spin vertical when pressing two other keys.
Or could the flight movement be implemented in a better way?
I know how to respond to key events and how to rotate using the glRotatef method,but I'm not sure how to implement sideways spinning and vertical spinning. Should this only be implemented with the glRotatef method? Flight movement usually works the same way in most games, so there must be some standard way to solve this. Has anyone got a code example for flight movement?
Re: How to implement flight movement?
I came up with a very simple solution that worked. I can actually move anywhere in the 3d game with it. This is my approach:
X rotation with up and down keys(changes cRotX)
Z rotation with left and right keys(changes cRotZ)
Increase speed with Fire button(changes increment of the z variable)
Decrease speed with * button(changes increment of the z variable)
Change direction with # button(changes direction of the z incrementation)
I just do this simple translation and rotations each frame:
glTranslatef(cX - 20, cY - 20, z);
glRotatef(cRotX, 1,0, 1);
glRotatef(cRotZ, 1, 1, 0);