View Full Version : Few questions concerning camera..

02-22-2001, 06:52 AM
Well.. I'm fairly new to OpenGL but have a strong background in programming and such.. Although, I'm still getting used to the whole model view matrix and such.. But anyway, right to the questions..

1. If I use gluLookAt with the camera, will any and all translates after that only effect the modelling coordinates and retain the camera in the same position..

2. Would it be better to create a world by using normal translates and rotates w/ combinations of push and pops to keep the desired view, or should I just use gluLookAt?

3. If I seem confused, I'd appreciate any help to steer me in the right direction. Thanks


02-22-2001, 12:43 PM

gluLookAt will set up a transformation to take the camera from it defined location at the origin looking down -z axis to some point you specifiy. You're "effectively" moving the camera, but you're not, really. Hold this thought; next train of thought: if you're in a train and look out the window and see the neighbouring train move, are YOU moving, or is the other train moving? OK, it might be important to know this if you're on the train (because they TAKE you places, you know <nods wisely> ), but the visual effect is the same. Anyway, back to the previous train of thought... you're not really moving the observer to the new place, but rather moving the WORLD *around* the observer. (so, the camera is sitting in a stationary train, and the neighbour train is the thing that's moving, but its still giving the camera the impression of being moved around).

The trick behind the glLookAt, then, is to initialise the modelview matrix stack with the camera transform first... so the entire world is moved after its been set up to accomdoate moving the observer around the place. So, in answer to your first question: your gluLookAt isn't moving the camera, anyway; and it will only affect the modelling coordinates, because that's what it does.

In reference to yoru second questrion, then... it.. really doesn't matter (?!) how you set up the modelview matrix. gluLookAt() will post multiply the current matrix (whcih should, after all, be the modelview matrix (c.f. some posts on this topic)). but you can just as well do the same transform yourself with the corresponding glTranslate yadda yadda. an example!!

gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glTranslatef(1.0, 2.0, 3.0);
glRotatef(4.0, 5.0, 6.0, 7.0);

is JUST the same as:

glTranslatef(0.0, 0.0, -10.0); /* same thing as the lookat above, in this SIMPLE case */
glPushMatrix(); /* just for the hell of it */
glTranslatef(1.0, 2.0, 3.0);
glPushMatrix(); /* to emphasise a point =) */
glRotatef(4.0, 5.0, 6.0, 7.0);

this works because the gluLookAT is effectively moving the observer back, right? Well, we can get the same effect by explicility putting a translate to do that, anyway. (but, what transform do you want for some more complicated gluLookAt()?! that's why the function exists, after all=)

in summary: gluLookAt() is a substitute for a set of transformations. but its just that: an easy alias for a set of translates/rotates, and not something magical.

3. er, this isn't a question =) but i hope this info helps!!


02-23-2001, 07:28 AM
Yes, actually that did help a lot. For some reason, I was led to believe that using the gluLookAt command somehow seperated the a 'camera' frame from the default model frame and stayed stationary (until moved with gluLookAt) as the model frame freely moved around. I suppose it seemed inefficient to me that everytime a different view is desired, that ALL objects in the scene are moved. But then again, I figured, all the objects are constantly redrawn relative to the world frame anyway. So, it really doesn't matter.

Also.. Is there a certain command necessary so that anything that's not in the current view is not rendered by OpenGL, or is always in effect? Like, if I draw a cube and then move along the X axis to the right so the cube is no longer in view, will OpenGL continue to pass it through the rendering pipeline? Thanks a lot.


[This message has been edited by guitardave (edited 02-23-2001).]

02-23-2001, 07:57 AM
OpenGL does not know anything about objects. It only knows about primitives (points, lines and triangles). If you pass an object to OpenGL, you actuallt pass a collection of triangles, that we se as a car for example.

The process of determining if the car is visible or not is up to you to determing. Of course, OpenGL does not draw anything that is not visible. But if you can help OpenGL by saying, "Hey, this car is not visible, so why ask OpenGL to draw it at all?", you can save some time. When you draw it, each primitive will be clipped to the viewfrustum, and if it's not visible, nothing will be drawn. But notice, even though the primitives won't be drawn, they are still processed by OpenGL.

In other words, it's a difference between not drawing (as in saying "Opps, this primitive was not visible", for each primitive in the object after it has been processed), and not drawing (as in saying, "This object is not visible, so we skip it").

You should search for a nice article about frustum culling. There are some nice ones, but don't remember any links, sorry.