Complete source for moving the camera

I already know that there isn’t real a camera in opengl, but you can move the world. Now i want to know the source code to do these things:
On keypress[n] move v units in direction made up of the angle around the x- y- and zaxes.

Can someone please send me the source code for this? I don’t need initialization for lighting such stuff. Thanks - Post the sourcecode would be the best, but you can also send it to (simple copy/paste)
Thanks in advance - Ls

Down in your windows message look at where you catch input and put this:

if(VM_UP) {
movfwd += 0.25; // this with your own speed
if(VM_DOWN) {
movfwd -= 0.25; // notice - instead of +
if(VM_LEFT) {
movright -= 0.25;
if(VM_RIGHT) {
movright += 0.25;

Then where you do all of your drawing, before you draw anything to the screen do:
glRotatef(0.0, movright, 0.0);
glTranslatef(0.0f, 0.0f, movfwd);

This will get you moving forward and backwards, left and right. You should be able to figure out the rest on your own.

Hope this helps.


If you’re using GLUT, I have a complete example at my GLUT tutorial


Maybe you want to do your own rotations/translations. You can the position the the camera where you want using gluLookAt();. Now is not the world translated but your camera.

I wrote a tutorial on this matter, called ‘a first person camera tutorial for OpenGL’.

Hope this helps,

Daniel Palomo van Es

DPalomo: That didn’t work. I cant say why, cause I did all how you said. Now, does anyone have working code? I already have my own class, but i will use anyone other’s class that works. The best would be, if it’s not using glut or glu, i’m only using opengl with mingw32, and sometime use allegro( or )
Thanks in advance.

Hey, and wire, I already got that far. My problem is the angle around the z-axes (roll or twist called) and the strafing. Thx in advance.

Ahhhh…, ok…
just do glTranslatef(slide, 0.0f, 0.0f);
and in your message loop put something like i showed you above. Just be sure to set everything to zero after each loop unless you want to speed around forever.


SLIDE??? Are you crazy? Thats as easy as … uhm… very very easy! It isn’t real sliding, cause it’s not affected by the zangle - and thats what i need!!!

Don’t yell at me, geez, your the one that didn’t make it clear what you needed!