When OpenGL illumination is enabled, the normal vector is used to determine the amount of illumination received on a specific vertex or surface. The illumination process acts on the observed coordinate space. Therefore, the normal vector of the model object coordinate system must also be transformed to the observed coordinate system using the gl_modelview matrix.
However, the transformation methods of normal vectors and vertices are different. We cannot simply multiply the gl_modelview matrix by the normal. Suppose the normal vector of vertex (, 0) (, 0 ). If the gl_modelview matrix is two units moving along the Y axis, the vertex coordinates are (, 0 ). However, the normal is still the same (1, 0, 0), instead of (1, 2, 0 ).
To understand how a normal vector is transformed to the observed space, the normal is used as the coefficient of the plane equation, which is perpendicular to the plane.
OpenGL Vector
Suppose a triangle with three vertices: V1-V2-V3, the normal of the homogeneous plane is. (For European space, the normal is .) If we think of a triangle as a homogeneous plane, the plane equation is: (replace X, Y, Z with x/W, Y/W, Z/W, then we multiply both sides by W)
Because the three vertices are on the plane, when we bring these points into the equation, the plane equation is also correct. For example, for vertices, the following conditions are met:
The equivalent matrix of a plane equation is as follows:
The plane equations multiply the transpose normal (NT) by the vertex.
Now, by inserting the gl_modelview matrix M-1M in the middle, we can modify the above equation to obtain the two transformation equation: (the following equation is still equivalent to the above equation, because the M-1M is the matrix of units .)
As you can see, because the equation also changes, the right side of the above equation is the transformation of the space, and the left side is the normal vector in the observation space. This is "in the observation space, the transformed vertex is on the plane after the transformation".
Therefore, use the gl_modelview matrix m to convert the normal from the model object space to the observed space, which is:
Alternatively, change the right multiplication to the left multiplication method:
Http://www.songho.ca/opengl/gl_normaltransform.html.