View Full Version : Complete source for moving the camera

11-25-2000, 07:55 AM
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 lightsabresoftware@yahoo.com (simple copy/paste)
Thanks in advance - Ls

11-25-2000, 12:54 PM
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.


11-25-2000, 06:37 PM
If you're using GLUT, I have a complete example at my GLUT tutorial


11-25-2000, 10:09 PM
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'. http://www.liacs.nl/~dpalomo/camtut/camtut.html

Hope this helps,

Daniel Palomo van Es

11-26-2000, 01:09 AM
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( www.allegro.cc (http://www.allegro.cc) or www.talula.demon.co.uk (http://www.talula.demon.co.uk) )
Thanks in advance.

11-26-2000, 01:10 AM
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.

11-26-2000, 06:10 AM
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.


11-26-2000, 08:05 AM
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!!!

11-26-2000, 03:29 PM
Don't yell at me, geez, your the one that didn't make it clear what you needed!