On OpenGL transformation matrix

Source: Internet
Author: User

The matrix used in OpenGL is all a matrix of column vectors.

Refer to OpenGL Transform website for http://www.songho.ca/opengl/gl_transform.html

1. What is the Gl_modelview matrix?

The Gl_modelview matrix is the product of the model matrix and the view matrix, that is, M_modelview = M_view * M_model.

The model matrix is used for transformations from the object coordinate system to the world coordinate system, usually by rotating, panning, or zooming.

The view matrix is used for transformations from the world coordinate system to the camera coordinate system.

The matrix transformation of the vertex is as follows:

Modelview Matrix in OpenGL (column vector-based):

2. Coordinate transformation of normal vectors

Unlike the vertex transformations in Figure 1, the transformation of the normal vector from the object coordinate system to the camera coordinate system is achieved by m_modelview the inverse matrix.

The matrix transformation of the normal vector is as follows:

To this end, many people will have doubts: how to get the transformation formula of the normal vector?

In fact, the formula of the normal vector transformation is based on the plane equation, the concrete derivation process is as follows:

Known normal vector n (NX,NY,NZ,NW), assuming a point on the plane is V (x,y,z,w), then the plane equation is NX * x + ny * y + nz * z + NW * w = 0;

The relationship between the normal vector and the point is transformed into a matrix expression form:

The Gl_modelview matrix conversion is obtained by:

The right part converts the vertex from the object coordinate system to the camera coordinate system, while the left part is the expression that transforms the normal vector into the camera coordinate system, so

That

Reference site for http://www.songho.ca/opengl/gl_normaltransform.html

3. Standard equipment space, in English, is normalized device coordinates (OR NDC), which is obtained by perspective division in the projected coordinate system (clipping space), and the range of x, Y, z is [ -1,1].

Perspective Division English for perspective Division.

4.glViewport (x,y,w,h) command is used to define the rectangle of the rendering area where the final image is mapped.

The Glviewport method is used for rectangles that are fixed in the render area.

5.glDepthRange (n,f) command is used to determine the z value of the window coordinates.

The Gldepthrange method is used to define the Z-values of screen coordinates.

6. Screen coordinates can be obtained according to 4,5:

7. When multiple matrices work together, it is important to pay attention to the sequence of matrix multiplication, the results of different orders are different, for example:

Vertex v is preceded by a matrix M1 transformation, and then by the Matrix M2 transformation to get Vertex v ', the expression in OpenGL is:

V ' = M2 * M1 * V

1 // Note: The actual order of the objects is the advanced translation and then the rotation 2 Glrotatef (angle, 1, 0, 0);   // rotate the object around the x-axis Anlge 3 Gltranslatef (x, y, z);       // Translate objects to (x, Y, z) 4 drawobject ();

8. Projection matrix

There are two kinds of projection methods in OpenGL: Perspective projection and parallel projection (also called orthogonal projection), calculated by Left,right,bottom,top,near,far six parameters.

Details can be found in the next blog, not to be continued .....

On OpenGL transformation matrix

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.