3D graphics: Coordinate Transformation

Source: Internet
Author: User
Introduction

In 3D graphics, coordinate transformation is often required. Therefore, as a learner, it is necessary to master the principle of coordinate transformation. There are many transformations in the 3D rendering pipeline, basically from one coordinate space to another. Since there are so many coordinate transformations used in 3D, we should have a detailed understanding of the principle of coordinate transformation. This helps us understand the various transformation processes in the 3D assembly line.



Coordinate Transformation

In the DirectX 9.0 Reading Note (1) vector article, we detail how to change the coordinate point in the coordinate system A to the coordinate system B. Here we use the article's conclusion: if we have a vector or point in the coordinate system, how can we represent this vector or point in the B coordinate system? For a vector, assume that the vector represented in the coordinate system is Q (x, y, z), and the three base coordinates in the coordinate system are u (UX, uy, uz), V (VX, Vy, VZ) and W (wx, Wy, WZ ), then we can use the following formula to obtain the coordinates of the Q vector in the B Coordinate System: QB = x * u + y * V + z * W; because the vector can be translated, vertices cannot be translated. Therefore, for vertices Q (x, y, z) in space A, our formula is changed to the following: QB = x * u + y * V + z * w + O. Here, O is the coordinate representation of the origin of the coordinate system in the B coordinate system.

Well, through the above formula, we naturally know how to perform coordinate transformation.



Matrix Representation of coordinate transformation

We know that most of the time in a 3D assembly line, a matrix is used for coordinate transformation. Therefore, we need to know how to construct a matrix through the above conclusions to transform coordinates into the space we want.

Before describing the coordinate transformation of a matrix, let's look at the multiplication of vectors and matrices.

Note that the row vector used here, so the multiplication operation of the vector and matrix can only be (vector * matrix), rather than (matrix * vector ). Different representation methods are different for the constructed matrix. You need to differentiate them by yourself.

Vector Q (x, y, z) and a 3*3 matrix m =, the result is Q * m = x * u + y * V + z * w.

What do you think of when you see this result? Yes, for vector space transformation, we only need to represent the corresponding coordinate base, such as U, V, W in the above example, according to the Representation Method of matrix m. Then multiply the vector by this matrix to get the transformed coordinates.

However, we also need to consider that in the above formula, only vectors can be transformed. If it is a vertex, there is no way. Therefore, we naturally want to use homogeneous coordinates for representation. Homogeneous coordinates, compared with common 3D coordinates, has one more component. Q (x, y, z, W ). When the value of W is 0, it indicates that Q represents a vector, and how W is 1 indicates that Q represents a vertex. Then, the matrix needs to be changed accordingly.

For the matrix in, you only need to convert it into a 4*4 homogeneous matrix. If you are familiar with d3d, you should know that I am talking about the following matrix:

Well, this is all done. The matrix representation of our coordinate transformation is like this.

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.