Problem with camera's concept! Help me fast!

I’ve been started programming OpenGL 1 month ago, and there’s something I really can’t understand. Would you mind helping me answer them?

  1. Does gluLookAt modify the projection matrix? Or it really only deal with a series of translation and rotation?
    I came to that question when trying to move the camera (view point, maybe?) around the scene.
  • First, I set the camera at (2,2,2), point toward (0,0,0), up along y axis, using gluLookAt.
  • Simply, I drew a 3D grid which I expected to be the world coordinates system’s representation.
  • Then, when I use gluLookAt again to move the camera to (1.5,1.5,1.5) (everything else stay the same), and guess what? The 3D grid, instead of moving directly closer to me, move away, nearly out of the viewport! Ofcorse, when I use glLoadIdentity before using gluLookAt, things go fine! But why? I thought that the camera is descripted using world coordinates, and hence we do not need to load the identity matrix.
  1. Assume that we don’t have GLU library, and as I read in your book, there’s only one projection transformation function: glFrustum. If it’s so, then:
  • Where’s the camera location in this function?
  • If there’s no function to set up the camera location, then what can I do to view some object far away to the negative z axis? Assume that they’re so far that the view point must place behind the origin along the z axis! If only glFrustum can be use, how can I specify that camera location (view point)?

Pleaseeeeeeeee!

gluLookAt alters the currently active matrix, the one set with glMatrixMode(). If the projection matrix is set, then yes, it’s changed. But you should always enable the modelview matrix and load the idenity matrix before calling gluLookAt.

glFurstum is for setting up the viewing volume, and does only tell OpenGL things like the field of view, and the dimensions of the viewing volume, not it’s position.

And no, there is no functions for setting up the camera in OpenGL, simply because the is no camera. Only a point of view. If you don’t want to use gluLookAt, you can call a series of glRotatef and glTranslatef to move the world around the point of view.

I really suggest you read the read book or something similar on how the projection matrix and the modelview matrix works. It’s difficult, I know, but it’s an essential part.

The Red book can be found online here , and the Suberbible here .

Thank for your advice!
Now there’s one thing I need to make sure:

  • If there wasn’t a camera, then can I say there’s only one viewpoint, and this view point is always located at the origin of the grand-fixed world coordinates system? Any modification of modelview matrix, actually just translate,rotate or scale the being-drawn primitives, to achieve the effects of changing viewpoint, don’t they?
  • When I build a 3D scene and want to move the viewpoint around, I MUST modify modelview matrix using glLookAt before drawing all the scene, musn’t I? Is there anyway, say, for more convenient, to draw all objects first, then simply setup the viewpoint and direction?

Your first statement is very correct. This is how it works. Can add that the viewpoint is looking down the Z-axis, and upvector is along the Y-axis.

Second statement is somewhat diffuse, because you can interpretate it in at least two ways. Do you mean you must change the matrix with gluLookAt only, or MUST it be the modelview matrix you change (sorry if I messed it up
even more, hope you know what I’m trying to say).

But yes, you SHOULD modify the modelview matrix, but you don’t HAVE to. If you know what you are doing, and this is what you want to do, you can do it in the projection matrix. But I don’t recomend it, because it will screw normal-depending features and fog up. And yes, you MUST alter the matrix BEFORE drawing your object. OpenGL renders the primitimes as they arrive to the pipeline, and if you haven’t set the viewpoint, you’re doomed. And no, you don’t have to use gluLookAt to set viewpoint. gluLookAt is just a glTranslatef and a glMultMatrix. If you want to do your own routine to “move the camera”, just call a glTranslate to move the world istead. Same with rotation. But remember to move/rotate the world in the oposite direction.

Great! It’s so much brighter now :slight_smile:
Actually, I’ve been reading “Computer Graphics” and “OpenGL Programing Guide” all days and nights… Everything seems to be easy until I have to deal with OpenGL “viewpoint” section! My small project runs properly now, with all kind of “camera” modifications
OpenGL pipeline is indeed important!
Anyway, one more thing: I read that light position is considered in eye coordinates. What is this “eye coordinates”? I used lights in my project, all of them do exactly what I want them to, and I only see that lights are just placed in scene as if they were primitives! Even moving, rotating… So what is really “eye coordinates”?

Thanks,
Lunar,

P.S: Oh, can you tell me how to display two or more different viewports on just one GL window, base on the same scene (just with different viewpoint)? This’s a myst, is it not?

Eye coordinates mean coordinate relative to where the point of view is placed. If you place your light at (0,0,0), the light will always be placed at the same spot as the point of view. Place it at (0,0,1) will place it one unit from the point of view in the positive Z-direction.

But depending on where in your code you place you light, it will give you different results. Place the light before you setup your point of view, and you will place the light in eye coordinates. Place the light after the viewpoint is set, and you will place the light in world coordinates. The light position is transformed using the modelview matrix to obtain the actual position.

And it’s very easy to setup two viewports. Just call glViewport and set your screencoordinates for the first window, draw the scene, and then set a new viewport and draw the second scene. Remember to rebuild the modelview, and maybe even the projection matrix, before rendering, from scratch that is.