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