-
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
-
can't you just store the character's y co-ord?
-
If you know the position you could check the color of your map to calculate the y-pos...
-
How about averaging the four outer points?
Code:
A-------D
| |
| P |
| |
B-------C
P = (A + B + C + D) / 4
-
Not what I meant...
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?
-
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.
Code:
_
\
/_ h * (Dx^2+Dy^2)^.5
_______________________
_
\
/_ (Dx^2+Dy^2)^.5