问题
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?
回答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 notation let's do:
Obtain f normalized, up normalized, s normalized, and u=sn x f. Notice that s must be normalized because f and up may be not be perpendicular and then their cross-product is not a vector of length=1. This is not mentioned in the link above.
Form the matrix and pre-multiply by the translation to camera position, L= M · T
The resulting lookAt matrix is:
s.x s.y s.z -dot(s, eye)
u.x u.y u.z -dot(u, eye)
-f.x -f.y -f.z dot(up, eye)
0 0 0 1
With your data: camera=(0,0,5), target=(0,0,0), up=(0,1,0) the matrix is:
1 0 0 0
0 -1 0 0
0 0 1 -5
0 0 0 1
Let's apply this transformation a the point A=(0,0,4). We get A'=(0,0,-1).
Again for B=(0,0,20), B'=(0,0,15).
A' has a negative Z, so the camera sees it. B' has a positive value, the camera can not see it.
来源:https://stackoverflow.com/questions/42977477/glulookat-specification