Directx11 tutorial 36 texture ing (6)

Source: Internet
Author: User

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

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.