Hello I am relatively new to the forums (but not OpenGL) and have made a few 2D games.
I was working on a 3D ‘flight’ simulator, but I had a problem. The goal is to have the user be able to fly (heading,pitch,roll) through a world, like any spaceship simulator. There will be no ‘gravity’ or drag.
I had code for heading (y rotation) and pitch (x rotation) but which order do I roll (z rotation)? Do I rotate, then translate, or rotate?
Here is my code:
xp += cos(DEG_TO_RAD * (heading - 90.0f ) ) * sin(DEG_TO_RAD * roll + 90.0f) * airspeed * dt; zp += sin(DEG_TO_RAD * (heading - 90.0f) ) * airspeed * dt; yp += sin(DEG_TO_RAD * -pitch ) * cos(DEG_TO_RAD * -roll) * airspeed * dt;
glRotatef(pitch, 1.0f, 0.0f, 0.0f); glRotatef(roll, 0.0f,0.0f,1.0f); glRotatef(heading, 0.0f, 1.0f, 0.0f); glTranslatef(-xp,0.0f,0.0f); glTranslatef(0.0f,-yp,0.0f); glTranslatef(0.0f,0.0f,-zp);
I kept the three translates seperate so I can move them easily.