Local Coordinate System and Global Coordinate System

Source: Internet
Author: User

Overview

The global coordinate system is the coordinate system where three-dimensional objects are located. The vertex coordinates of the model are expressed based on the coordinate system. The local coordinate system is a hypothetical coordinate system. The relative position of the coordinate system and the object remains unchanged from the beginning to the end, the purpose of the hypothetical coordinate system is to positively understand the "Translation and rotation" operations performed on objects in 3D scenes. When using the local coordinate system to understand the model transformation, all the transformation operations work directly with the local coordinate system, because the local coordinate system and the object's relative location is not correct, therefore, when the local coordinate system is "translated", "rotated", and "scaled", the position and shape of the object in the scene also change accordingly.

Notes

(1) "global coordinate system" and "Local Coordinate System" are two ways to understand model transformation.

(2) When there is a "Scaling" transformation, you should use the "global coordinate system" and "reverse" to read the code. If there is a scaling transformation, especially when the scaling is uneven, using the "local coordinate system" may cause problems. After uneven scaling, the coordinate system is stretched. Therefore, when translating a vertex, the distance moving along each axis increases (decreases) the corresponding scaling factor. If the rotation and transformation are performed at the same time of uneven scaling, the axes of the local coordinate system may not be perpendicular to each other.

(3) When "Translation" and "Scaling" operations are used for multiple exchanges, you should read the code using "Local Coordinate System" and "forward.

(4) For objects like tree structures, such as robots, the solar system, the recommendations of the red book are from the "local coordinate system.

Why do I need to read the code in the reverse way when using the global coordinate system?

Let's take a look at the following code:

1 void draw ()
2 {
3 glmatrixmode (gl_modelview );
4 glloadidentity (); // The current matrix is set as the unit matrix.
5 glrotatef (45.0f, 0.0, 0.0, 1.0); // rotate 45 degrees around the Z axis
6 gltranslatef (2.0, 2.0, 2.0); // pan to [2.0, 2.0, 2.0]
7 glbegin (...); // start to draw a 3D object
8...
9...
10...
11 glend ();
12}

R is the matrix generated by glrotatef (45.0f, 0.0, 0.0, 1.0.

T is the matrix generated by gltranslatef (2.0, 2.0, 2.0.

E is the unit matrix, and m is the viewpoint model transformation matrix after rotation and translation.

M = E * r * t [This is a right Multiplication operation of a matrix]

Theoretically, this is the transformation process of a coordinate system. The R * T matrix is actually the transformation of the original coordinate system to the current coordinate system. At this time, the point P of the Original Coordinate System will be converted to Q.

Q = (R * t) * P [T and P first multiply to get an Intermediate Vector, r then multiply with this vector, and finally calculate the Q vector]

According to the global coordinate system, the transformation process is the opposite, which is quite understandable. after drawing the object in the current world coordinate system, to move it to the correct position, you must first translate the object to [2.0, 2.0, 2.0], and then rotate the object 45 degrees around the Z axis. This is an inverse transformation process.

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.