Original article from:
Http://blog.csdn.net/dizuo/article/details/2325279
1. All view transformations and model transformations in OpenGL are 4x4 matrices. Each subsequent glmultimatrix * (N) or transformation function, gltranslate * (), glrotate *(), A new 4x4 matrix is multiplied by the current matrix m. The difference is: the transformation function gltranslate * (), glrotate *() a 4x4 matrix is constructed based on the function parameters, which is also set to n. The two conditions produce the same result: m x n. Note the order here. The subsequent matrix is the right multiplication current matrix.
2. in OpenGL, the coordinate representation is [x, y, z] T (transpose), or in homogeneous coordinates: [X, Y, Z, after W] T standardization, [x/W, Y/W, Z/W, 1.0] T determines that the matrix is also prioritized. Apply the two matrices above to the vertex v, which is expressed as m × n × V. The conditions for matrix multiplication are: [4 × 4] * [4 × 1]. for example:
Glmatrixmode (gl_modelview); glloadidentity (); glmultmatrixf (m); // glscale * (); glmultmatrixf (n); // glrotate * () glmultmatrixf (L ); // gltranslate * (); glbegin (gl_points); glvertex3f (V); glend ();
According to the preceding statement, the transformed vertex is m × n × L × V, which is always a right multiplication. Note the following example:
Glmatrixmode (l_projection); glloadidentity (); gluperspective (45.0, 1.0, 1.0, 20.); // create a projection matrix MP; glmultmatrixf (MS );
The result is: MP × Ms × V (vertex), but if you want the result to be: Ms × MP × V (vertex), the code is:
Glmatrixmode (gl_projection); glloadidentity (); glmultmatrixf (MS); gluperspective (45.0, 1.0, 1.0, 20.); // create a projection matrix MP;