Can someone please explain the concept of a heightmap for me. What I gather so far is that you take a grayscale picture and then take the heights of the grayscale and that is the height of the terrain that your going to create. The problem I have is how does that all come about. I tried to piece through Kenny's heightmap example, but unfortunately couldn't do it... So if he or someone else wants to help me it would be appreciated

Posted on 2001-12-06 19:47:00 by Sliver
Heightmaps are actually very simple... you create an image where you treat every pixel like a hight.

the easiest way to "convert" heightmaps to a mesh is to use the same dimensions for both hightmap and mesh (e.g. if you've got an 128 x 128 pixel hightmap, create an mesh with 128 x 128 vertexes/hights).
now lets assume that the x & z of you mesh tell you where in a plane you are, and y is the hight: just map the value of the pixel in the hightmap at (x,z) to y.

something like this (c++ style pseudo code):
// image[][] is the hightmap
// mesh[][] is you mesh (each element is a vertex)
for( int x = 0; x < image size x; x++ )
for( int z = 0; z < image size z; z++ )
mesh.x = x*scale factor;
mesh.z = z*scale factor;
mesh.y = image*scale factor;

how to draw the mesh is left as an exercice for you :grin: i'd suggest you try using indexes (should be available in both opengl and direct3d)

theres also a good article in game programming gems II, where they also show how to draw the mesh with different LOD & stuff
Posted on 2001-12-08 09:11:26 by CViper