Question about gluLookAt()

For the following functions:
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

glPushMatrix();
glColor3f(0.98, 0.625, 0.12);    
glTranslatef(100.0, 100.0, 100.0);
glutSolidSphere(30.0, 10.0, 10.0);
glPopMatrix();

glPushMatrix();
glColor3f(0.0, 1.0, 0.0);
glTranslatef(100.0, 300.0, 0.0);
glutSolidCone(100.0, 50.0 * sqrt(3), 4, 1);
glPopMatrix();

glutSwapBuffers();

}

void init()
{
glClearColor(0.60, 0.40, 0.70, 0.0);
glMatrixMode(GL_PROJECTION);
glOrtho(-1024.0, 1024.0, -768.0, 768.0, -1000, 1000.0);
glMatrixMode(GL_MODELVIEW);
}

Since I have the eye of the camera positioned at (1, 1, 1), why am I able to see the other objects? They are positioned at (100, 100, 0), (100, 300, 0). Shouldn’t they be behind the camera? If I have misunderstood the gluLookAt function, please help. Thank you.

Using gluLookAt in orthographic mode can be tricky. Since you have set the near clip plane to -1000 and the far plane at 1000, it means you can see from 1000 units “behind” the viepwoint to 1000 units in front of the viewpoint.

But let’s say I had said
glOrtho(0, 300.0, 0.0, 500.0, -100, 100.0);
What would happen? Doesn’t the “eye” value tell where the camera is? And everything behind the camera shouldn’t be visible, right? I’m sorry, but I don’t have a compiler at hand right now.

Your camera is looking from +1 Z to 0 Z as set by glulookat, which makes you camera looking in the negitive direction.

Your first object is glTranslatef(100.0, 100.0, 100.0); which is +100 Z, camera only starts looking at +1 Z looking into the negitive, so this object is behind where the camera is looking at.

Next object glTranslatef(100.0, 300.0, 0.0);
glutSolidCone(100.0, 50.0 * sqrt(3), 4, 1);

Same problem… y direction +1 to 0…
You object is drawn at +300 on the y, object is again behind the camera.

Originally posted by gluDontLookAt:
[b]For the following functions:
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

glPushMatrix();
glColor3f(0.98, 0.625, 0.12);    
glTranslatef(100.0, 100.0, 100.0);
glutSolidSphere(30.0, 10.0, 10.0);
glPopMatrix();

glPushMatrix();
glColor3f(0.0, 1.0, 0.0);
glTranslatef(100.0, 300.0, 0.0);
glutSolidCone(100.0, 50.0 * sqrt(3), 4, 1);
glPopMatrix();

glutSwapBuffers();

}

void init()
{
glClearColor(0.60, 0.40, 0.70, 0.0);
glMatrixMode(GL_PROJECTION);
glOrtho(-1024.0, 1024.0, -768.0, 768.0, -1000, 1000.0);
glMatrixMode(GL_MODELVIEW);
}

Since I have the eye of the camera positioned at (1, 1, 1), why am I able to see the other objects? They are positioned at (100, 100, 0), (100, 300, 0). Shouldn’t they be behind the camera? If I have misunderstood the gluLookAt function, please help. Thank you.[/b]

[This message has been edited by nexusone (edited 10-21-2002).]

Doesn’t the “eye” value tell where the camera is? And everything behind the camera shouldn’t be visible, right?

What is visible and what is not is not determined by the viwepoint (or position of the camera if you like) alone. What is visible is determined by the viewpoint AND the projection matrix. The eye value palces the viepwoint at desired position, yes. But your near plane is still set to a negative value, which means behind the viewpoint. The eye value is where the corodinate (0,0,0) in the view volume is located. From there (assuming your latest glOrtho-call), your view volume extends 0 units in the negative X-direction, 300 units in the positive X-direction, 0 units in the negative Y-direction, 500 units in the positive -direction, -100 units in the positive Z-direction (this is behind the viewpoint), and 100 units in the negative Z-direction (this is in front of the viewpoint). This is why you can see behind the viewpoint, cause the view volume starts behind the viewpoint.

As I said above, using gluLookAt in an orthographic projection can be tricky. In a perspective projection, there’s a viepwoint and a view direction. But in orthographic projection, there’s really no viepwoint, but a view direction only.

If you don’t want to see anything behind the viepwoint, set the near clip plane to zero.

[This message has been edited by Bob (edited 10-22-2002).]

So, if I use gluLookAt with gluPerspective, the camera should be in its right place, right?

gluPerspective only effects the view projection. Given the scene a 3D depth look.

gluLookAt is camera direction, the camera Will be where ever you put it.

You still need to make sure ether your camera is faceing the correct direction or that you have drawn your object in front of it.

Your problem was you where looking away from you objects, changing to gluPerspective will not change that!

Originally posted by gluLookAtreturns:
So, if I use gluLookAt with gluPerspective, the camera should be in its right place, right?

Ok, that helps. Thank you.