Game Development Reference
In-Depth Information
private:
...device/vertex buffer etc snipped
int _numVertsPerRow;
int _numVertsPerCol;
int _cellSpacing;
int _numCellsPerRow;
int _numCellsPerCol;
int _width;
int _depth;
int _numVertices;
int _numTriangles;
float _heightScale;
};
See the source code in the companion files for the complete class defi-
nition of Terrain ; it is too big to include here.
From the values passed into the constructor, we can compute these
other variables of the terrain as:
_numCellsPerRow = _numVertsPerRow - 1;
_numCellsPerCol = _numVertsPerCol - 1;
_width = _numCellsPerRow * _cellSpacing;
_depth = _numCellsPerCol * _cellSpacing;
_numVertices = _numVertsPerRow * _numVertsPerCol;
_numTriangles = _numCellsPerRow * _numCellsPerCol * 2;
Also, the vertex structure of our terrain is defined as:
struct TerrainVertex
{
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;
};
const DWORD Terrain::TerrainVertex::FVF = D3DFVF_XYZ | D3DFVF_TEX1;
Note that TerrainVertex is a nested class inside the Terrain class.
This was done because TerrainVertex is not needed outside the
Terrain class.
13.2.1 Computing the Vertices
Refer to Figure 13.4 during this discussion. To compute the vertices of
our triangle grid, we are simply going to begin generating vertices at
start and then go row by row generating vertices until we reach end ,
leaving a gap defined by the cell spacing between the vertices. This will
Search WWH ::




Custom Search