GLM and MVP matrix operations shorthand
Work 15 hours continuously, tired, sleep. include "GLM/GLM.HPP" include "GLM/GTC/MATRIX_TRANSFORM.HPP"
If not specifically stated, the following example assumes that the matrix/vector is four-dimensional
GLM::MAT4 Mat;
GLM::VEC4 VEC;
For VEC, the fourth digit is 1 for the coordinates and 0 for the direction.
Translation matrix
| 1 0 0 X |
| 0 1 0 Y |
| 0 0 1 Z |
| 0 0 0 1 |
Constructing translation matrices
GLM::MAT4 mat = Glm::translate (X, Y, Z);
Stretching matrix
| X 0 0 0 |
| 0 Y 0 0 |
| 0 0 Z 0 |
| 0 0 0 1 |
Constructing the tensile matrix
GLM:MAT4 mat = Glm::scale (x, y, z);
Rotation matrix
If the hinge is x, Y, z, the angle is a
x = x sin (a), y = y sin (a), z = z sin (a), W = cos (a)
| 1-2 (y*y+z*z) | 2 (X*Y+Z*W) | 2 (X*Z-Y*W) | 0 |
| 2 (X*Y-Z*W) | 1-2 (x*x+z*z) | 2 (Y*Z+X*W) | 0 |
| 2 (X*Z+Y*W) | 2 (Y*Z-X*W) | 1-2 (x*x+y*y) | 0 |
| 0 | 0 | 0 | 1 |
Constructing the rotation matrix
GLM::VEC3 axis (x, y, z);
Glm::mat4 Transformedmatrix = Glm::rotate (Mat, A, axis);
The elementary transformation matrix is multiplied by the coordinates to get the transformed coordinates.
Mat * VEC (= VEC)
GLM::VEC4 Transformedvector = Mat * VEC;
Constructing model matrices
GLM::MAT4 mat = transmat3 * TRANSMAT2 * TRANSMAT1 * MAT;
Constructing the View matrix
GLM::MAT4 mat = Glm::lookat (Camerapos, Cameratarget, upvector);
If the camera is set, then Upvector = GLM:VEC3 (0, 1, 0)
Constructing projection matrices
GLM::MAT4 mat = glm::p erspective (FoV, Aspectratio, Nearclipplane, Farclipplane);
Model matrix view matrix projection matrix
Model coordinates ———-> absolute coordinates ———-> camera coordinates ———-> homogeneous coordinates
The final step is to simulate the process of human eye imaging with affine transformation.
GLM:MAT3 MVP = projection * View * model;
Register handle before loop
Gluint Matrixid = glgetuniformlocation (ProgramID, "MVP");
Pass to GLSL in the loop
GLUNIFORMMATRIX4FV (Matrixid, 1, Gl_false, &mvp[0][0]);
GLSL vertex shader End processing
Layout (location = 0) in VEC3 vertexposition_modelspace;
Uniform mat4 MVP;
Void Main () {
Vec4 v = vec4 (vertexposition_modelspace, 1);
Gl_position = MVP * v;
}