Dragon Book 9 Chapter13 14 terrain drawing process and terrain class implementation, particle system Getting started notes

Source: Internet
Author: User

Terrain notes:

implementation process key points : 1. Height graph reading (get y value)--Create a flat mesh (get x z Value)--Generate vertex and index

2. Texture mapping and presets light: Create an empty texture--> map vertex corresponding texture coordinates-map different height corresponding to the color--> according to the Lightdirection calculation unit grid corresponding to the degree of shading

Height of 3.camera: To get the xz known in the unit grid, derive the corresponding y-coordinate

The height graph is considered as a matrix and the elements in the height graph need >=vertex number

Camera Height: The calculation in the book is not clear, this way can also find height, that is, the length of the EE ' AA ' multiplied by Fe ' divided by FA '

The terrain header file in the example:

Class Terrain{public:terrain (idirect3ddevice9* device,std::string heightmapfilename, int numvertsperrow, int   Numvertspercol, int cellspacing,//space between cellsfloat Heightscale); ~terrain (); int getheightmapentry (int row, int col), void setheightmapentry (int row, int col, int value), float getheight (fl Oat x, float z), bool Loadtexture (std::string fileName), bool Gentexture (d3dxvector3* directiontolight), BOOL Draw (D3dxma trix* World, bool drawtris);p rivate:idirect3ddevice9* _device;idirect3dtexture9* _tex;idirect3dvertexbuffer9* _ vb;idirect3dindexbuffer9* _ib;int _numvertsperrow;int _numvertspercol;int _cellspacing;int _numCellsPerRow;int _ Numcellspercol;int _width;int _depth;int _numvertices;int _numtriangles;float _heightscale;//beyond the 0-255 limit std::vector <int> _heightmap;//vertex y//Helper methodsbool readrawfile (std::string fileName);//Read Gray chart bool Computevertices ( ); bool Computeindices (); bool Lightterrain (d3dxvector3* directiontolight); float computeshade (int cEllrow, int cellcol, d3dxvector3* directiontolight);//calculates the degree of light intensity of a texture in a unit grid struct terrainvertex//inline class is only used with terrain { Terrainvertex () {}terrainvertex (float x, float y, float z, float u, float v) {_x = x; _y = y; _z = z; _u = u; _v = v;} Float _x, _y, _z;float _u, _v;static const DWORD FVF;};};

Particle System Notes:

Point Elf, how to map the texture of a single point?? Two modes: one. Corresponds to the entire texture two. Vertex the FVF attribute has texture coordinates, corresponding to the texture coordinates;

Key points: 1. VertexBuffer is divided into several fragments to ensure the full utilization of the graphics card. The CPU copies the vertex data into the graphics processor, and the graphics card is displayed.

For example, there are 10,000 particle vertex, we create a 2000vertex buffer, divided into 4 fragments, define the fragment index

Specifies that the vertexbuffer is dynamic so that the buffer area is not drawn by lock and does not affect the drawing of other parts

Dragon Book 9 Chapter13 14 terrain drawing process and terrain class implementation, particle system Getting started notes

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.