OpenGL: Model Transformation

Source: Internet
Author: User

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!

 

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.