PDA

Click to See Complete Forum and Search --> : Terrain height


pollier
Nov 17th, 2000, 02:49 PM
Using OpenGL, I've made a function to construct a terrain from a grayscale picture. Does anyone have a nice small efficient formula to calculate the height of the terrain in any given point-even between vertexes of the terrain

Here's a very crude diagram:

I hope it formats correctly...

+----+----+----+----+----+
| | | | | |
+----+----+----+----+----+
| | | | | |
+----+----+----+----+----+
| | | A | | |
+----+----+----+----+----+
| | | | | |
+----+----+----+----+----+

Each + is a vertex of the terrain with a different height.
Suppose someone is standing at point A - how do you calculate how high the character is?

Thanks,
pollier

KENNNY
Nov 17th, 2000, 03:11 PM
can't you just store the character's y co-ord?

Fox
Nov 17th, 2000, 05:40 PM
If you know the position you could check the color of your map to calculate the y-pos...

parksie
Nov 17th, 2000, 06:14 PM
How about averaging the four outer points?

A-------D
| |
| P |
| |
B-------C


P = (A + B + C + D) / 4

pollier
Nov 19th, 2000, 01:39 PM
Thanks for the ideas. You were close, but not enough...

+--------+
|..a......|
|..........|
|.....b...|
+--------+

(Each + is a vertex point, or a pixel of my bitmap of the terrain)

All the + have different heights. Therefore, point a is going to be at a different height than point b. How can I calculate this?

Also, can someone tell me how to put formatted text on this forum?

kedaman
Nov 19th, 2000, 03:58 PM
It would be a lot easier with hexagonal tiles, since then you have flat tiles and not any complicated formula you use. Of course you could divide the tile into two and use three vertexes.

Anyway you could calculate the average using the distance as the mass parameter as you do when you calculate central mass point.

_
\
/_ h * (Dx^2+Dy^2)^.5
_______________________
_
\
/_ (Dx^2+Dy^2)^.5