3D Game basic direct3d (3) Transformation of fixed Pipelines

Source: Internet
Author: User
As mentioned in the previous chapter, in a fixed pipeline, the first step is to perform coordinate transformation on the elements. The so-called primitive is a pile of vertices that constitute a specific geometric shape, which is called an element.

Therefore, after all, the object we transform is vertex.
In a fixed pipeline, the transformation is divided into two steps:
The local coordinate system goes to the world coordinate system and the world coordinate system to the observed coordinate system.
Local Coordinate System: A modeling coordinate system defined by tools such as 3dmax During modeling;
World coordinate system: Used to unify the location, size, and other specifications of each object in a scenario;
Observation coordinate system: that is, the coordinate system of the camera.

Local Coordinate System to world coordinate system transformation:
This transformation aims to unify the models designed with different modeling tools or modeling sizes of different specifications into a general coordinate system. The role of this action is the same as that of Qin Shihuang's unified measurement and balance. The movement from the local coordinate system to the world coordinate system is usually calculated in advance by game tools (such as the Scenario Editor) during game design, A transformation matrix (that is, the size, orientation, and position of the model in game scenarios) is calculated for each model, which is called the world coordinate transformation matrix. During rendering, these matrices are applied in real time for calculation:
D3dxmatrix worldmatrix; // This matrix is read from the file.
Device-> settransform (d3dts_world, & worldmatrix );
Note: Use the macro d3dts_world

From the world coordinate system to the observed Coordinate System Transformation:
This transformation is actually done to simplify the operation. After this transformation, all vertices can be directly converted to vectors, which is very convenient for some calculations. This action is usually to translate the camera to the origin of the world coordinate system, and then rotate the camera so that its optical axis is consistent with the Z axis of the world coordinate system. At the same time, all the geometries in the space must be transformed along with the camera to ensure that the camera's field of view remains unchanged. This transformation is called the landscape transformation. After the transformation, the observed coordinate system is obtained.
The statement is as follows:
D3dxmatrix viewmatrix;
D3dxvector3 position, targetpoint, worldup;
D3dxmatrixlookatlh (& viewmatrix, // [out], the computed Transformation Matrix
& Position, // camera position
& Targetpoint, // camera orientation
& Worldup); // The y orientation of the camera, that is, the head orientation.
Device-> settransform (d3dts_view, & viewmatrix );
Attention macro, d3dts_view
In fact, the d3dxmatrixlookatlh () function is just similar to one of the function functions. Note that the suffix LH indicates the left-hand coordinate system, which corresponds to a right-hand coordinate system. The difference between them is that the left-hand coordinate system has a positive Z axis; the right hand is outward positive.

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.