Grid (1)

Source: Internet
Author: User

Here we will plotCubeThe object mesh is used as an example.

Topics covered by creating a cube mesh include:

Create an empty Grid Object;

Write the Cube's Patch data to the grid cache;

Specify the subset of each slice in the grid;

Generate the adjacent information of the grid;

Optimize the grid;

Draw a grid.

 

First, initialize the following global variables:

Id3dxmesh * mesh = 0;

Const DWORD numsubsets = 3;

Idirect3dtexture9 * textures [3] = {0, 0, 0 };

STD: ofstream OUTFILE;

 

Here we initialize a pointer mesh, which will point to the mesh object created later. We also defined that the mesh will have three of its own formats. In this example, each subset uses a different texture. In this way, the I index in the texture array is associated with the I subset in the grid. Finally, the object outfile of the ofstream class is used to write grid-related data into a text file. We can pass this object as a parameter to the dump * function.

 

The main work in this routine is completed in the setup function. First, create an empty grid.

Next, we need to write the vertex and index information describing the cube into the vertex cache and index cache of the mesh object respectively. Lock the vertex cache and index cache, and manually write the data to achieve this goal easily.

After the slice data of the mesh is written to the corresponding cache, we must specify the subset of each slice. In this way, we have created a grid containing valid data. Now, we can start to draw the grid. But we want to optimize it first. Note that the optimization of such a relatively simple cube mesh will not have any effect. To optimize a grid, you must first calculate the adjacent information of the grid. Then, we optimized the mesh.

Now, all grid settings have been completed.

Finally, we can use the followingCodeYou can easily draw a grid. Essentially, we just traverse each subset through loops, set relevant textures for each user, and draw them.

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.