[3D Basics] understanding of coordinate system transformation in computer 3D graphics __ Graphics

Source: Internet
Author: User

Reprint: http://www.cnblogs.com/shanhaobo/articles/1065380.html

To talk about coordinate system transformation, what is the coordinate system?      In order: Object coordinate system, world coordinate system, camera coordinate system, projection coordinate system and screen coordinate system. What I'm going to talk about is the transformation between these coordinate systems. These coordinate systems do not come out of thin air, and they are all designed to accomplish the most fundamental goal of computer 3D graphics.
The most basic goal of computer 3D graphics is:Display the built 3D objects on 2D screen coordinates.
At first glance it seems to be the original object coordinate system to the screen coordinates can be, why more out of the world coordinate system, camera coordinate system, projection coordinate system. This is because: in a big world there are many objects, each object has its own coordinate system, how to express the relative relationship between these objects, this more out of the world coordinate system; If you only need to see part of the world, here's a camera coordinate system. As for the projection coordinate system that is because it is very complicated to convert the coordinates of the coordinate to the screen coordinates (because they are not only different in dimensions, metric different (screen coordinates are generally pixels, 3D space we can real world meters, centimeters), xy direction is different, in the 2D space to do coordinate system transformation ), so the coordinates of the first dimension are reduced to 2D coordinates, and then the 2D coordinates are converted to the screen coordinates.
Understanding the first step of 3D graphics: Understanding left-handed coordinate system and right-handed coordinate system
Why there is a left-hand coordinate system and the right-hand coordinate system.
In 3D space (yes. is 3D), all 2D coordinate systems are equivalent (that is, they can be converted to each other through a series of affine transformations).
and the 3D coordinate system is not equivalent, by affine transformation, it is impossible to convert the left-handed coordinate system to the right hand coordinate system, that is, the coordinate system is left-handed, and the world coordinate system is in the right hand coordinate system, then the object may not be what we want it to be, it may be upside down, or it may be back to us. So we have to differentiate between left-handed and right-handed coordinates. Perhaps in 4D space, the right-hand coordinate system can transform each other.
Let's get to the point:
First, the object coordinate system-> the world coordinate system is discussed.
In order to describe the relative relationship between multiple objects, we introduce the world coordinate system, so the world coordinate system is a reference coordinate system.
The purpose of this step is to transfer all the points of the object to the world coordinate system, which mainly involves rotation, scaling, translation, and so on.
But I'll explain in detail why and how to use matrices to describe these transformations.
For example: if there are two coordinate systems C and C ', C ' is obtained by rotation θ of c around the z axis. The following are the transformations for each axis:

If the C coordinate is the point P (x, Y, z), and the representation in C ' is

How do you build a matrix? The answer is to tell whether you're using a row vector or a column vector. One might ask why it is not a left-handed or right-handed coordinate system. Because C can be transformed to C ', they must be in the left-hand or right-handed coordinate system, and the transformation can only be done between the coordinate systems that are interchangeable.
If you are using a row vector: because the row vector can only be left by the matrix (note the difference between multiplication and multiply)
So the matrix form should be like this

Only in this way can the form of P ' above be obtained on the left multiplication matrix.

If you are using a column vector: Because the column vector can only be the right multiplication matrix (note the difference between multiplication and multiply)
So the matrix form should be like this

Only in this way can the form of P ' above be obtained on the right multiplication matrix.

As for how to rotate, zoom, translate I don't say more.
....................................... I feel like I'm on the topic. Fortunately, these two coordinate systems are very simple to transform.
We'll talk about the world coordinate system-> camera coordinate system
The goal of introducing a camera is simply to see a part of the world and what can be seen in the camera, and it needs to be screened. Converts an object to a camera coordinate system so that the camera's coordinate system is much simpler to filter. The point here is to build the camera coordinate system.
Object coordinate system, the world coordinate system is the art of drawing in the definition of good. The camera coordinate system is needed to build the program in real time. (Of course this is usually the case, if you want to build a world, the world revolves around you, to change all objects in real time coordinate system, fixed camera coordinate system (in fact, the camera coordinate system is the world coordinate system), to build a geocentrism world, I have no way, your thinking is too different. )
How to build a camera coordinate system. First we need to be clear about the goal: we're going to build a 3D coordinate system (like nonsense), three axes perpendicular to each other (like nonsense).
We usually use UVN cameras. For example: D3D's D3DXMATRIXLOOKATLH,D3DXMATRIXLOOKATRH,OGL Glulookat (right-hand coordinate system).
How to build it? UVN camera? We are going to use the tool of the cross product: two parallel, non-overlapping vectors can get a vector perpendicular to the two vectors.
If you have the position of the camera and the position of the target then we can determine a Z axis (someone asked why the z axis, because the object is far and near we are accustomed to using Z-value). The z axis should be noted that the left-handed or right-handed coordinate systems, the left-right coordinate system XY axis in the same direction, the z-axis in the opposite direction. So the left-hand coordinate system is the target position minus the camera position, while the right-hand coordinate is the camera position minus the target position. Remember normalize
This is where we're going to get the X and y axes. How to find X,y axis.
The General method is:
1, select a temporary y axis,
2, the temporary Y and z-axis of the cross product to obtain an x-axis
3, the X-axis and the z-axis of the cross product, get a y-axis.
With XYZ, you can find the rotated camera matrix.
How to choose a Y axis? Most of the time (0,1,0), but if the camera position E is perpendicular to the target position T (e-t= (0,+/-1,0), then it cannot be used (0,1,0), because the cross product of the two parallel vectors is the 0 vector, so we have to choose another Y axis.
But I think we can change the way.
If the Y axis is not selected, we select a temporary x axis, which is the temporary x-axis (1,0,0).
Then a y-axis is obtained for the temporary x axis and the z-axis as a cross product.
Finally, the y-axis is crossed with the z-axis, and the x-axis is obtained.
This will get the XYZ axis.
Finally, the camera matrix is established based on the row vector and the column vector, and then the translation is done.

Camera coordinate system-> projection coordinate system.
The aim of projection is to reduce dimension.
Two projection modes: orthogonal projection and perspective projection.
Yi Ying has written in our team, I will not say more, everyone to see his article.

Projection coordinate system-> screen coordinate system
This is the simplest. 2d coordinate transformation. And not much to say.

Related Article

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.