Greetings and Salutations,
I have created a heightmap using a grayscale image to generate points. These points are then saved to a file. When it becomes necissary to display this map, I load the points in this file into a 2D array of points.
The following is some quick psudo-code as I don't have the source right in front of me at the moment :)
The structure is something like this:
typedef struct
{
float x;
float y;
float z;
}Point3D;
The array would look somthing like this:
Point3D HeightMap[200][200];
Anyway, to draw the map I simply itterate thrugh the array and use GL_QUADS and glVertex3f, like so:
for(int x=0; x < 200; x++)
{
for(int y=0; y < 200; y++)
{
glBegin(GL_QUADS);
glVertex3f(HeightMap[x][y].x, HeightMap[x][y].y, HeightMap[x][y].z);
glEnd();
}
}
Works great. But now, I wan't to be able to find an arbitrary point on this mesh and determin it's height. This is so I can make a little character be able to realisticaly go up mountains, down hills, etc.
I would imagine that to do this I should find the nearest vertex to the character, then calculate a slope using that vertex and the midpoint of the other two verticis in the triangle where the character stands. Am I close on this?
Also, does anyone know any good tutotials on doing things like this?
Thanks alot in advance!