This chapter mainly organizes the code and does the following two tasks:
1. Place the calculation of the world coordinate matrix in the rendering function of graphicsclass, and put it in d3dclass before, and only returns a matrix of units, which has no effect. If you want to make it work, you need to set each model class separately, which is very troublesome. For example, if I want to draw two color cubes, wouldn't I create two model classes, the world coordinate matrix is different.
In the render function, we mainly use some d3d matrix change functions to calculate the world coordinate system. For example:
// Perform the translation operation to obtain the final model world matrix.
D3dxmatrixtranslation (& worldmatrix1, 4.0, 0.0, 0.0 );
A world matrix with four units moving along the X axis is obtained. In this way, to render multiple cubes, we only need to change the world matrix and then execute the shader rendering.
For example, the following code draws two color cubes:
// Place model vertices and index Buffering in the pipeline for rendering.
M_model-> render (m_d3d-> getdevicecontext ());
// Perform the translation operation to obtain the final model world matrix.
D3dxmatrixtranslation (& worldmatrix1, 4.0, 0.0, 0.0 );
// Use the shader for rendering.
Result = m_colorshader-> render (m_d3d-> getdevicecontext (), m_model-> getindexcount (), worldmatrix1, viewmatrix, projectionmatrix );
If (! Result)
{
Return false;
}
// Perform the translation operation to obtain the final model world matrix.
D3dxmatrixtranslation (& worldmatrix1, 8.0, 0.0, 0.0 );
// Use the shader for rendering.
Result = m_colorshader-> render (m_d3d-> getdevicecontext (), m_model-> getindexcount (), worldmatrix1, viewmatrix, projectionmatrix );
If (! Result)
{
Return false;
}
After running, the interface is as follows:
2. Modify planemodelclass. Previously we only drew two large triangles. Now we have changed to a grid to facilitate texture textures, such as pasting grass textures.
Complete code can be found:
Project File mytutoriald3d11_29
Download Code:
Http://files.cnblogs.com/mikewolf2002/d3d1127-28.zip
Http://files.cnblogs.com/mikewolf2002/pictures.zip