I’ve been trying to figgure this out for a while now. The rotations are easy enough, but how do you move in the direction your faceing? I would like to eventualy make a flying game, but this has got me stumped so any help would be appreciated.
glLoadIndentity();
glLoadMatrix(camera); // camera is a float camera[16]
glRotate(roll_angle, 0.0f,0.0f,1.0f);
glRotate(yaw_angle, 0.0f,1.0f,0.0f);
glRotate(pitch_angle, 1.0f,0.0f,0.0f);
glTranslatef(strafe,jump,dir);
glGetFloatv(GL_MODELVIEW_MATRIX, camera);
strafe: is the side to side movement.
jump: is the up down hover type movement,think helicopter going up or down.
dir: is the direction you’re pointing at, this is your forward movement, if it’s 1.0f you will move 1.0f in the direction you’re looking.
in your main rendering loop, you can then do something like this:
glClearBuffer(…);
glLoadIdentity();
gluLookAt(camera[12],camera[13],camera[14], // position of camera
camera[12]+camera[8],camera[13]+camera[9], camera[14]+camera[15], //look at dir
camera[4], camera[5], camera[6] // up dir
);
Et Voila! I encourage you to find out more on the encoding of the matrices. And maybe later on learn quaternions.
Hope this helps.
le-Wolf
[This message has been edited by The Wolf (edited 10-12-2001).]
It is “quick and dirty” because it uses a glGet. These are slow operations not meant for realtime use. I would call it “slow and dirty”.
My suggestion is, don’t use angles. Use vectors that point in the direction you want to go. That way, all you need to do is take the vector, multiply it by the speed/time, and add that to the current position.
x = cos ( pitch ) * cos ( yaw )
y = sin ( yaw )
z = sin ( pitch ) * cos ( yaw )
Btw, beware of the angle unit (use radians) and the signs of the angles; you’ll probably have to play with the values til it moves in the correct direction.
Thanks everybody for your replies. I haven’t tried everything yet. I tried the quick and dirty method, but I need to learn more about matrixes so I can understand whats going on. Also thanks for the link. If anybody else know of any sites I can look at, send them to me. For some reason none of the search engins could find much on flight sims.