When it comes to model transformation, it involves matrix operations. Although OpenGL has already packaged various model transformation operations for us to make the matrix transparent to users, we just need to call the API provided by it to implement these operations, but it is necessary to discuss some basic knowledge about the Matrix here, which is about the model matrix (4x4 matrix ), of course, I also agree to use the model conversion API provided by OpenGL. Since people have already packaged it, why don't we use it? You don't have to waste that much.
For details about the OpenGL model matrix, see:
It is different from that in textbooks. It gives priority to columns, and books give priority to rows.
Directly use a matrix for model transformation:
TranslationThe model is moved to the X, Y, and Z directions through M13, m14, and M15 respectively. These values represent the position of the Model System in the global coordinate system. Therefore, if I change M15, that is, Z, the image will not change under parallel projection, the only difference is his depth value. In Perspective Projection, it will increase or decrease because its distance has changed and his depth value has also changed. If M13 and m14 change, the entire model system will be moved to the X axis and Y axis.
ZoomThe scaling of the model is the zooming of X, Y, and Z separately controlled by M1, M6, and M11. This is very simple. For example, I want to increase the scaling of this model system, you only need to multiply M1, M6, and M11 by scale. Of course, you can also scale a single image, but this will make the entire model system deform.
RotateThis is the most complex operation of model transformation. It is controlled by the rotation matrix. We only need to construct the rotation matrix and then use the left Multiplication Model matrix. See the following figures:
Rotate around X axis
Rotate around Y axis
Rotate around the Z axis
They are used to control the rotation of models around the X, Y, and Z axes respectively.
Direct useOpenGL APIConversion:
Translation, Gltranslatef (x, y, z): X, Y, Z indicates the distance to be translated. It is very simple. We don't need to care about any matrix. An API is used for translation.
Zoom,Glscalef (scalex, scaley, scalez): The parameters inside are scaling factors, respectively controlling the zooming sizes of X, Y, and Z.
Rotate, Glrotatef (angle, x, y, z): angle is an angle that rotates counterclockwise. (x, y, z) is a spin axis.
(With OpenGL, life is so simple !)
If the description is incorrect, please leave a message. Thank you very much!