Several large coordinate transformations

Source: Internet
Author: User

World coordinate system transformations:

The World coordinate system transformation is actually moving vertices from the geometric model coordinate system to the world coordinate system, in the game is to build the game scene, put the items into a scene. Usually when the world coordinate system is converted, it will also change the size to control the enlargement or reduction of the primitive object, by changing the direction to set the rotation, by changing the position to change. In a scene, each object has its own world coordinate system transformation matrix, because each object has its own size, orientation, and position.

Observe coordinate system transformations:

After all vertices have been converted to the world coordinate system, observe that the coordinate system transformation converts it from the world coordinate system to the observation coordinate system. As we said before, observing the coordinate system is in the world coordinate system, from the observer or camera angle perspective can see the image, in the observation coordinate system, the observer will stand at the origin (or the observer as the origin), the direction of the perspective is the z axis direction, that is, the direction of observation is the z-axis direction.

It is worth noting that while observing coordinate space is a framework that is visible from the observer in the world coordinate system, the observing coordinate system matrix is populated by fixed points rather than observers. So, the data that the observation matrix fills is exactly the opposite of the observer or the camera, for example, if we want to move the camera 4 units in the z direction, then we have to calculate the z-axis direction of the point of view matrix conversion exactly 4 units. Although the camera moves in the opposite direction, the image in the camera is reversed. There is a method in Direct3D that can be used to calculate this observation matrix, that is, the XMMATRIXLOOKATLH () method, we just need to tell him where the observer is, where he is watching, and tell him that the observer is upward, and that the observation matrix can be computed.

Projected coordinate system transformations:

A projected coordinate system transformation is the conversion of a fixed point from a 3D coordinate system such as the world and the observing coordinate system to a projected coordinate system, in which the x and y coordinates of a vertex are obtained based on the ratio of x/z and y/z in 3D space. Let's start by looking at a diagram that will help us understand the concept as follows:

In 3D, according to the perspective method, the closer the object is larger, from the above figure can be seen, a tall H unit in the distance away from the observation point D units of the tree, and a height of 2h units from the observation point 2d location of the tree is the same size. As a result, vertices are rendered on a 2D screen based on the ratios of x/z and y/z.

In Direct3D, one is called the FOV (Field-of-view), which determines whether a particular position's vertex is visible in a particular direction. Everyone has a FOV, of course it's in front of us, because we can't see the back, if two objects are too close or too far away to see. In computer graphics, the FOV is contained in a viewport, and in 3D the viewport is defined as a hexahedral, with two faces parallel to the XY plane, which are called near-Z-plane and far-Z-view planes. Other faces are defined as the observer's horizontal and vertical visual interface, the larger the FOV, the larger the size of the viewport, and of course, the more objects it holds, as shown in the figure below.

The GPU filters the outside of the viewport so that it doesn't waste the parts that don't need to be displayed, which is called clipping, and the GPU will convert vertices to projection vertices, so you know if you're in the viewport. In Direct3D 11, these line breaks are done by a method, that is XMMATRIXPERSPECTIVEFOVLH (), we will increase the 4 parameters, Fovy, ratio, Zn and ZF can get the projection matrix. Where Fovy is the projection angle in the y direction, the ratio is wide and high, and Zn and ZF are the size of myopic and farsighted surfaces respectively.

To draw a 3D graphic:

With the above theoretical knowledge, we can draw 3D graphics on the screen. In the previous example we learned how to draw a triangle, here we will draw a cube. As we know from the previous example, the vertex of the GPU triangle needs to be told in the computer drawing, so we need to define the vertex of the cube first, so we can define an array because the cube has 8 vertices. And we also need to tell the pixel shader color, so we can first define a structure with the following code: struct SIMPLEVERTEX
{
XMFLOAT3 Pos;
XMFLOAT4 Color;
};
Simplevertex vertices[] =
{
{XMFLOAT3 (-1.0f, 1.0f,-1.0f), XMFLOAT4 (0.0f, 0.0f, 1.0f, 1.0f)},
{XMFLOAT3 (1.0f, 1.0f,-1.0f), XMFLOAT4 (0.0f, 1.0f, 0.0f, 1.0f)},
{XMFLOAT3 (1.0f, 1.0f, 1.0f), XMFLOAT4 (0.0f, 1.0f, 1.0f, 1.0f)},
{XMFLOAT3 (-1.0f, 1.0f, 1.0f), XMFLOAT4 (1.0f, 0.0f, 0.0f, 1.0f)},
{XMFLOAT3 (-1.0f,-1.0f,-1.0f), XMFLOAT4 (1.0f, 0.0f, 1.0f, 1.0f)},
{XMFLOAT3 (1.0f,-1.0f,-1.0f), XMFLOAT4 (1.0f, 1.0f, 0.0f, 1.0f)},
{XMFLOAT3 (1.0f,-1.0f, 1.0f), XMFLOAT4 (1.0f, 1.0f, 1.0f, 1.0f)},
{XMFLOAT3 (-1.0f,-1.0f, 1.0f), XMFLOAT4 (0.0f, 0.0f, 0.0f, 1.0f)},
};

We know that the smallest geometric unit of GPU recognition is a triangle (except for dots), and we tell the GPU cube that the vertices are not drawn, so we're going to switch. The cube has 6 faces, that is, 12 triangles, that is 36 vertices, above we define eight vertices, is not enough. We also know in the previous section that polygons can be shared with two vertices, so we can define an index to describe the vertex, whose code is as follows: WORD indices[] =
{
3, 1, 0,
2, 1, 3,

0, 5, 4,
1, 5, 0,

3, 4, 7,
0, 4, 3,

1, 6, 5,
2, 6, 1,

2, 7, 6,
3, 7, 2,

6, 4, 5,
7, 4, 6,
};

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.