C ++ directx11 development Note 5: 3D space coordinate system

Source: Internet
Author: User

In the previous articleArticleIn this example, we know how to draw a 2D image in the 3D coordinate system, that is, draw a triangle, this time, we need to know how to present a 3D image in a 3D coordinate system and how to understand several coordinate systems in a 3D space. These are used in game programming, because every 3D object has its own coordinate system. As for how to convert these coordinates, I think we may need to discuss them in the next section. There is no end to learning. I hope that I can stick to my childhood dream and realize my game dream in the near future.

 

3D space recognition:

In the previous section, the 2D image triangles drawn on the screen are aligned with the screen, just as a triangle is directly attached to the screen, but not all of them apply. In this way, we need a 3D space coordinate system for description and display. In the real world, every item exists in 3D space. This means that to place an item in a special position, we must use a coordinate system and define three coordinates describing a specific position. In computer plotting, the three-dimensional coordinate system generally uses the Cartesian coordinate system. I have seen it in mathematics. It can also be divided into the left-hand or right-hand coordinate system. The left-hand coordinate system points to the top of the Y axis, the X axis points to the right, and the Z axis points to the front, the zaxis is in the opposite direction, as shown in.

Next we will discuss the coordinates of a point in a 3D coordinate system with different dimensions. For example, in one dimension, as shown in, the position of the P point is at the place of the ruler 5 cm. When we move the ruler, the position of the P point changes, maybe at the place of 4 cm or 3 cm. Although point P has not actually moved, it has a new coordinate, that is, it has a different reference object.

Next, let's take a look at the situation in 3D. In a space, we need to define an origin and three axes starting from the origin: X, Y, and Z. In computer plotting, they contain definitions in several spaces: Object Space (Object Space) [model ry Coordinate System], World Space (World Space), and view space (view space ), projection space and screen space ).

 

Primitive coordinate system:

This coordinate system is also called the geometric model coordinate system. It is mainly used for the coordinate system used when 3D modeling is used. When creating a model, the modeler usually models the model around the origin, which will help coordinate transformation, for example, let the model rotate, we will describe the coordinate transformation. For example, a square is defined in such a coordinate system, and its eight vertices will have the following coordinates: (-1, 1,-1), (,-1 ), (-1,-1,-1), (1,-1,-1), (-, 1), (, 1), (-1, -1, 1), (1,-1, 1)
.

Therefore, the geometric coordinate system of the model is the coordinate system defined by the modeling personnel during model design and creation. The model that is kept on the disk also exists in the geometric coordinate system of the model. ApplicationProgramYou can use this model to create a vertex cache object and initialize this cache object through model data. Therefore, a vertex cache object is usually created in the model, which means that the vertex coloring er will obtain vertex data information from the geometric coordinate system.

 

World coordinate system:

The world coordinate system is a coordinate system that shares every model (primitive item) in a scenario. It is usually used to describe the relationships between the models we expect to present. To virtualize a world space coordinate system, we can imagine that we are standing in the southwest corner and facing a room in the north. We define the place where our feet stand in this corner as the origin (0, 0, 0), the X axis points to our right, the Y axis points to the top, and the Z axis points to the front [left-handed coordinate system, this is also the coordinate system used in direct3d. I heard that OpenGL uses the right-hand coordinate system, but OpenGL is not familiar to me.] The Orientation of OpenGL remains unchanged. In this way, all things and items in the room can be uniquely identified using different coordinates XYZ. It can be seen that the purpose of using the world coordinate system is to describe the direct contact between different items.

 

Observe the coordinate system:

The observation coordinate system is sometimes called the photographic coordinate system. It is a bit like the world coordinate system, but the world coordinate system is used to describe the whole scene, and the source of the observation coordinate system is in the eyes or cameras of the observer. The Z axis of the observed coordinate system is the front of the eyes, and the Y axis is relative to the top of the eyes. The X axis is on the right side, and the world coordinate system and the observed coordinate system are displayed.

In the scenario on the left, there is a person in the world coordinate system, just like an object, and a camera is watching him. The red origin and axis represent the world coordinate system. In the picture on the right, the relationship between the observed coordinate system and the world coordinate system is displayed, and the blue axis indicates the observed coordinate system. To better understand them, we can see that the direction of the observed coordinate system is different from that of the world coordinate system. In the world coordinate system, the observed direction is the red Z axis, the orientation in the observed coordinate system is the blue Z axis.

 

Projection coordinate system:

The projection coordinate system is converted by observing the coordinate system. You can imagine that it is the same as taking a photo with a camera. In the projection coordinate system, the X and Y coordinates of the visible object are described between-1 and 1, while the zcoordinate is described between 0 and 1, this section will explain in detail during coordinate conversion.

 

Screen coordinate system:

The screen coordinate system is generally used to reference a frame buffer positioning coordinate list. Because the frame cache is usually a 2D texture, the screen coordinate is a 2D coordinate system. It is actually our monitor. The vertices in the upper left corner are defined as the origin (0, 0), the X axis is horizontal, and the Y axis is vertical. In the cache, the times are described as W pixel width and H pixel height, and the smallest is the coordinate of the pixel in the bottom right corner is (W-1, h-1 ).

 

In this way, we will understand several important spatial coordinate systems in direct3d. Maybe my description is not particularly in line with the general saying, but I am only in the learning stage, blog writing is also designed to better understand and learn direct3d. Many of them are directly translated from the example documents. If you have any mistakes, please correct them. This section is more theoretical. In fact, you can get a rough idea.

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.