Skip to main content
gamedev.net
🔒 Locked

Height map

Started by Etnu 1 reply 500+ views
Original Post
Etnu
Etnu
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?
---------------------------Hello, and Welcome to some arbitrary temporal location in the space-time continuum.
Eric
Eric
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.