Scene transform |2d and 3D mutual conversion in OpenGL

Source: Internet
Author: User

Scene transform |2d and 3D mutual conversion in OpenGL

we live in a three-dimensional world-if we want to observe an object, we can:
1, from a different position to observe it. (View transform)
2, move or rotate it, of course, if it is only the object inside the computer, we can also enlarge or reduce it. (Model Transformation)
3, if the object is drawn down, we can choose: whether a "near-large far small" perspective effect is required. In addition, we may only want to see part of the object, not all (clipping). (Projection transformation)
4. We may want to draw the entire picture, but it only occupies part of the paper, not all of it. (Viewport transform)

All of this can be achieved in OpenGL.


Mercator coordinate transformation


OPENGL-----3D to 2D coordinate transformations


OPENGL-----2D to 3D coordinate transformations


The 3D conversion is actually a 3D to 2D inverse transformation

1. Viewport transformations

Use Glviewport to define viewports. The first two parameters define the left bottom of the viewport (0,0 represents the leftmost bottom), and the last two parameters are width and height respectively.

The glviewport is responsible for displaying the images captured by the scene as high and wide as they appear on the screen.

Effect


2. Perspective projection

Glmatrixmode (gl_projection);                      // sets the current matrix as the projection matrix.  

Glmatrixmode Setting the current matrix mode:

Gl_modelview, the subsequent matrix operation is applied to the Model view matrix stack.

gl_projection, the subsequent matrix operation is applied to the projection matrix.

Gl_texture, the subsequent matrix operation is applied to the texture matrix heap stack.
//

Moves the origin of the current user coordinate system to the center of the screen: similar to a reset operation.

Glloadidentity the function is to reset the currently specified matrix to the unit matrix. Semantically, it is equivalent to calling Glloadmatrix with the unit matrix.

    Glfrustum (L, R, B, T, N, f);   // multiplies the current matrix by a perspective matrix and transforms the current matrix into a perspective  matrix

This function constructs a visual body to be used to project the model, to crop the model, and to decide which of the models are in the visual body, which is outside the visual body and is not visible outside the scene.

Note: Typically,Glmatrixmode and glloadidentity are used together for matrix mode switching.

3. Model transformations

    Glmatrixmode (gl_modelview);      Glloadidentity ();      Glscissor (00, iwidth, iheight);  

Glscissor the clipping function to specify the width of the crop.

gltranslate*, multiplies the current matrix and a matrix that represents the moving object. The three parameters represent the displacement values at three coordinates, respectively.

glrotate*, multiplies the current matrix and a matrix that represents a rotating object. The object will rotate counterclockwise around (0,0,0) to a straight line (x, Y, z), and the parameter angle represents the angle of rotation.

glscale*, multiplies the current matrix and a matrix that represents the scaling object. x, y, and Z indicate the scaling in that direction, respectively.

Reference URL:

http://blog.csdn.net/a49688448/article/details/17999923

Conversion of scene transform |2d and 3D in OpenGL (RPM)

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.