#### Archived

This topic is now archived and is closed to further replies.

# Height map

This topic is 6931 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to impliment a height map In D3D. I want to generate a new map each time the level starts, but the problem that Im having is setting up the vectors properly to make triangles. Does anybody know a good algo?? I need the clockwise vertices. Any help is appreciated. Etnu I am god?

##### Share on other sites
I'm doing something similar in the game I'm working on. Here's what I did initially:

for(WORD iz=0; iz < terrDepth; iz++){
for(WORD ix=0; ix < terrWidth; ix++){
// Get the untransformed vertex position
WORD x = ix * TERR_SCALE;
// terrCoords is basically my height map, initialized earlier
WORD y = terrCoords[ iz * terrWidth + ix ].height;
WORD z = iz * TERR_SCALE;

// go from world space to screen space and store in vert array
terrVertices[ iz * terrWidth + ix ] =
ProjectCoord( x, y, z,
terrCoords[ iz * terrWidth + ix ].lightIndex,
matSet, dwClipWidth, dwClipHeight );

if( iz < terrDepth-1 && ix < terrWidth-1 ){
// each 'square' between height-map coords is filled with two right triangles

// Etnu, I'm using counter-clockwise here

// triangle 1
terrIndices[ numIndices ] = iz * terrWidth + ix;
terrIndices[ numIndices + 1 ] = ( iz + 1 ) * terrWidth + ix;
terrIndices[ numIndices + 2 ] = ( iz + 1 ) * terrWidth + ( ix + 1 );

// triangle 2
terrIndices[ numIndices + 3 ] = iz * terrWidth + ix;
terrIndices[ numIndices + 4 ] = ( iz + 1 ) * terrWidth + ( ix + 1 );
terrIndices[ numIndices + 5 ] = iz * terrWidth + ( ix + 1 );
}
numIndices += 6;
}
}

// later, I call this, which will render all the terrain
m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, terrVertexTypeDesc, terrVertices, terrArea, terrIndices, numIndices, NULL );

BTW, My game won't actually use this method of rendering the height map. I've devised an adjustable-LOD algorithm based on this article by Bryan Turner.

Edited by - Eric on 4/26/00 2:01:31 AM

##### Share on other sites
Thanks for the help I appreciate it.

• 10
• 13
• 52
• 11
• 15