Code:
// receives the terrain height(y) at point x,z
function TTerrain.GetHeight(x,z:single) : single;
var
rx, rz : integer;
fx, fz,
A, B, C, D : single;
begin
if (x <0> (TerrainMaxX-1)) or (z <0> (TerrainMaxZ-1)) then
begin
result := 0.0;
exit;
end;
rx := trunc(x);
rz := trunc(z);
fx := x - rx;
fz := z - rz;
A := HeightMap[rx ,rz];
B := HeightMap[rx+1 ,rz];
C := HeightMap[rx ,rz+1];
D := HeightMap[rx+1 ,rz+1];
result := (A + (B -A) * fx) + ((C + (D - C) * fx) - (A + (B - A) * fx)) * fz;
end;
Heightmap is a 2dimensional array containing the heights at your "vertices". calling this function gives the height at any point within the terraindimensions.
Greetings,
Dirk
Bookmarks