View Full Version : gluLookAt() Z Axis

02-17-2006, 04:20 AM
Why, in the gluLookAt() function, is the Z axis reversed?

I would have thought that if I wanted my camera to be at the origin but one unit backwards in the Z axis I would do...

gluLookAt(0.0f, 0.0f, -1.0f...

But apparently that moves the camera forward in the Z axis one unit and instead, to move the camera backwards I need to do...

gluLookAt(0.0f, 0.0f, 1.0f...

Why is this?

02-17-2006, 04:37 AM
in gluLookAt(0., 0., 1., 0., 0., 0., 0., 1., 0.)
the eye position is (0.,0.,1.), and you are looking towards (0.,0.,0.), so the view direction is negative z-direction: (0., 0., -1.)

imagine that you draw a 2d x-y-coordinate system on a piece of paper and hold it in front of your face with the y axis pointing upwards. then your eye position is at a positive z-coordinate, and you're looking into negative z-direction. that's what you get if you use gluLookAt with the above values.

02-17-2006, 07:22 AM
Just adding a comment;
By default, when modelview matrix is initialized by identity matrix, you(or camera) are looking to -Z axis direction.
Therefore, moving forward is decreasing Z value, and moving backward is increasing Z value for gluLookAt().