3D computer Grapihcs Using OpenGL-13 optimization matrix

Source: Internet
Author: User

The previous section said that matrices can be combined, and that multiplication is done in reverse order of application. Before we initialized Translationmatrix and Rotationmatrix, the first parameter was an initial matrix glm::matrix4 () used, and we could actually refine the code slightly to make the initialization process leaner.

Compare the code before and after optimization:

Before:

1Glm::mat4 ProjectionMatrix = glm::p erspective (30.0f, ((float) width ())/height (),0.1f,10.0f);2Glm::mat4 Translationmatrix = Glm::translate (Glm::mat4 (), GLM::VEC3 (0.0f,0.0f,-3.0f));3Glm::mat4 Rotationmatrix = Glm::rotate (Glm::mat4 (),54.0f, GLM::VEC3 (1.0f,0.0f,0.0f));4 5GLM::MAT4 Fulltransformmatrix = ProjectionMatrix * Translationmatrix * ROTATIONMATRIX;

After:

1 glm::mat4 ProjectionMatrix = glm::p erspective (30.0f, ((float0.1f10.0f ); 2 glm::mat4 Translationmatrix = glm::translate (ProjectionMatrix, GLM::VEC3 (0.0f0.0f,- 3.0f )); 3 54.0f, GLM::VEC3 (1.0f0.0f0.0f));

The first variable we used when initializing Tranlationmatrix and Fulltransformmatrix was the previous transformation matrix, and the benefit was that it ultimately reduced the intermediate variable of a rotaitionmatrix.

The compilation runs the same result as the previous section.

3D computer Grapihcs Using OpenGL-13 optimization matrix

Related Article

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.