Move the camera, or move the world?

Started by
7 comments, last by LilBudyWizer 18 years, 4 months ago
Movement of a camera in 3D is something I haven't done too much of. How is camera motion achieved in openGL? I know that with 2D, the notion of a camera is largely absent since you're only looking at one orientation and direction all the time. And scrolling in 2D is done with moving all the objects in the same speed and direction. Does this idea apply to 3D as well? Should one leave the position of the objects alone and change the viewport, or are the objects all moved in the same matrix to create the illusion that the camera is moving? Currently I have a rudimentary camera view system where pressing the arrow keys moves a "camera" though it's actually translating the position of all the objects.
Advertisement
In 3d engines it is better to have a camera object that you translate around and then the 3d renderer, in your case OpenGL, does the rest to gluLookAt and gluPerspective. I am no expert in OpenGL so if there is another way to do this let me know.
"Imagination is more important than knowledge" - A. Einstein
My first guess would be that rather than translating the position of every single object in your scene, it would be faster (on the cpu) to just translate the camera. You seem to know already about the viewing matrix, which is used for camera "motion". Try experimenting a bit with gluLookAt(), it might be the beginning of a simple solution to all your camera needs ^_^

Edit: Aurvandil beat me to it ^_^
Or, alternatively you can create your own camera that uses built in opengl functions if you don't want to include GLUT. I've got an example (though there is a really silly bug in looking up or down and moving, this should be easy to fix. Left-right works fine.)

This is probably not a very good example as I did it a year ago or so and wasn't familiar with OpenGL when I did it... However if you look at the top project on that page (entitled openglproject.zip) you can check out the source for my camera.

http://www.mutedvision.net/program
_______________________"You're using a screwdriver to nail some glue to a ming vase. " -ToohrVyk
Quote:Original post by M2tM
Or, alternatively you can create your own camera that uses built in opengl functions if you don't want to include GLUT. I've got an example (though there is a really silly bug in looking up or down and moving, this should be easy to fix. Left-right works fine.)

This is probably not a very good example as I did it a year ago or so and wasn't familiar with OpenGL when I did it... However if you look at the top project on that page (entitled openglproject.zip) you can check out the source for my camera.

http://www.mutedvision.net/program


I'm not positive but I'm pretty sure gluLookAt() does not require GLUT.
<a href="http://ruggles.hopto.org>My Personal Website
*edit: My bad, it belongs to GLU, not GLUT
_______________________"You're using a screwdriver to nail some glue to a ming vase. " -ToohrVyk
You might be interested in my topics on a simple GL camera and a description of a more physical camera.
enum Bool { True, False, FileNotFound };
Its is my understanding that OpenGL does not have a camera as such, and much like you reffered to in 2D the view position is fixed and indeed you do move everything around the camera to give the illusion of movement. However you do not have to translate the position of every object on the CPU, by doing a glRotate() and glTranslate() before rendering any objects you are infact rotating or translating the entire world hence nothing really has to be done on the CPU and the GPU should take care of all this.

Thats how i understand it anyway, hope that helps ;)

Please anyone, if i am wrong correct me.
What's moving and what's not is relative to your frame of referance. Generally you define a world coordinate system that is your fixed point of referance. Your first transform is world to camera done with a call such as gluLookAt. You then do object to world transforms on top of that to position your objects within the world. You might also position objects relative to other objects such as the moon orbiting the earth as the earth orbits the sun.
Keys to success: Ability, ambition and opportunity.

This topic is closed to new replies.

Advertisement