PDA

View Full Version : gluLookAt - does it work? (or am i too stupid :-)



Schleppi
04-23-2001, 06:20 AM
I have a little problem with this function:

My little program (from a tutorial) works fine, i can see the 2D-polygon.

glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25, 0.25, -0.20);
glVertex3f(0.75, 0.25, -0.20);
glVertex3f(0.75, 0.75, -0.20);
glVertex3f(0.25, 0.75, -0.20);
glEnd();

But when i try to change my view to the objects by adding the line

gluLookAt(0,0,-15,0,0,0,0,1,0);

in front of the glOrtho i can't see anything.
But when looking from (0,0,-15) to (0,0,0) i'm still looking in the z-axis and should see the polygon in the (x,y)-plane.

Perhaps i misunderstood something in using this function.

(Just for explanation:
i need to draw a cube with glutSolidCube() but the cube is automatically not centered, so i need to center it myselfe -with glOrtho- and then hope to be able to view it from different directions -with gluLookAt-)
Or are there any other way to do this?

Any suggestions and help is welcome.

Deiussum
04-23-2001, 11:07 AM
You're pushing the quad behind the far clip plane. You're clip plane goes from -1.0 to 1.0. gluLookAt basically just does the opposite that a set of glTranslate and glRotates would do.

Also, by default the z axis increases coming out of the screen and decreases going into the screen so you are also viewing the quad from the other side with that code. Try make it 15 instead and increase your far clip plane to something like 20.

Also with glOrtho, you aren't going to see the quad get smaller... it's going to look exactly the same. glOrtho doesn't setup any perspective calculations for you. For that you'll need to use glFrustum or gluPerspective instead.

Another thing wrong with your code is that you should be doing the glOrtho (or glFrustum/gluPerspective) with the projection matrix, and gluLook at in the model view matrix.

To sum it all up, your code should look like so.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 15.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25, 0.25, -0.20);
glVertex3f(0.75, 0.25, -0.20);
glVertex3f(0.75, 0.75, -0.20);
glVertex3f(0.25, 0.75, -0.20);
glEnd();