I was getting in more in depth about matrix implementations, and I found in OpenSceneGraph matrix inverse computation the comment:
We note that this matrix can be split into three matrices.
mat = rot * trans * corr, where rot is rotation part, trans is translation part, and corr is the correction due to perspective (if any).
The fact that the modelview matrix is broken down into a matrix rotation and translation seems reasonable, but the correction matrix makes me curious about…
The corr matrix is the modelview matrix reset to identity except the fourth line (using OpenGL notation). For instance:
corr = [ 1 0 0 0
0 1 0 0
0 0 1 0
x y z s ]
Normally, the vector c=[x y z s] equals to {0 0 0 1}, indeed it doesn’t contribute in vertex transformations. But, since they are involved, how is correction vector used?
What are the concrete applications of the c correction vector? What is the effect on transformed vertices with a such matrix (having perspective correction)?
The way 4×4 matrices work in 3D computer graphics is: after all your matrix transformations, you divide the 4-vector by the fourth (
w) coordinate to get your screen coordinates:From the following simplified diagram, you can see that the geometry of perspective projection requires division by a depth value:
The fourth line of the matrix determines the
wcoordinate of the result, so that the final division can perform the perspective projection. The values[x/w, y/w]are proportional to the actual screen coordinates, and[z/w]is typically used for the depth buffer (although it is actually more like the reciprocal of the depth).