Game Development Reference
In-Depth Information
TerrainVertex::FVF,
D3DPOOL_MANAGED,
&_vb,
0);
if(FAILED(hr))
return false;
// coordinates to start generating vertices at
int startX = -_width / 2;
int startZ = _depth / 2;
// coordinates to end generating vertices at
int endX = _width / 2;
int endZ = -_depth / 2;
// compute the increment size of the texture coordinates
// from one vertex to the next.
float uCoordIncrementSize = 1.0f / (float)_numCellsPerRow;
float vCoordIncrementSize = 1.0f / (float)_numCellsPerCol;
TerrainVertex*v=0;
_vb->Lock(0, 0, (void**)&v, 0);
inti=0;
for(int z = startZ; z >= endZ; z -= _cellSpacing)
{
intj=0;
for(int x = startX; x <= endX; x += _cellSpacing)
{
// compute the correct index into the vertex buffer
// and heightmap based on where we are in the nested
// loop.
int index=i*_numVertsPerRow + j;
v[index] = TerrainVertex(
(float)x,
(float)_heightmap[index],
(float)z,
(float)j * uCoordIncrementSize,
(float)i * vCoordIncrementSize);
j++; // next column
}
i++; // next row
}
_vb->Unlock();
return true;
}
Search WWH ::




Custom Search