Order of matrix multiplication in OpenGL

Source: Internet
Author: User

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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.