Sign in to follow this  
Just Chris

OpenGL Move the camera, or move the world?

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 ^_^

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this