gluLookAt specification

I have some problems understanding the specification for gluLookAt. For example the z-axis is defined as:

F = ( centerX - eyeX, centerY - eyeY, centerZ - eyeZ )

with center being the point the camera looks at and eye being the position the camera is at.

f = F / |F|

and the View-Matrix M is defined as:

( x[0]   x[1]   x[2]  0 )
( y[0]   y[1]   y[2]  0 )
(-f[0]  -f[1]  -f[2]  0 )
( 0        0      0   1 )

with x and y being the x,y-axis and f being the z-axis

If my camera is positioned at (0, 0, 5) and the camera looks at the center. Then f would look along the negative z-axis because of the first equation (center - eye) the f-vector would be: (0,0,0) - (0,0,5) = (0,0,-5)

So far everything makes sense to me, but then the f-vector is multiplied by -1 in the M-Matrix above. That way the f-vector looks along the positive z-axis and away from the center.

I found that the perspective matrix gluPerspective will also multiply the z-axis of the camrea with -1 which turns the z-axis again and makes it look toward the world's negative z-axis.

So what is the point of multiplying it with -1?


Solution 1:

Because gluLookAt is a View Matrix for a right-handed system. In this space, Z-coordinate increments as it goes out of screen, or behind the camera. So all objects that the camera can see have negative Z in view space.

EDIT

You should review your maths. The matrix you exposed lacks the translation to camera position.

Following this