- type
- TVector : array[0..2] of single;
- TTriangle = array[0..2] of TVector;
- function GetNeighbor(x,y:integer):TVector;
- const
- VertPos: array[0..3] of array[0..2] of array[0..1] of smallint =
- (
- ((0,0), (1, 0), (0, 1)),
- ((0,0), (0,-1), (1, 0)),
- ((0,0), (-1,0), (0,-1)),
- ((0,0), (0, 1), (-1,0))
- );
- Scale: single = 5;
- var
- Face, Vertex : integer;
- xx,yy : integer;
- n : array[0..3] of TVector;
- t : TTriangle;
- tmp : TVector;
- begin
- tmp := MakeVector(0,0,0);
- for Face := 0 to 3 do begin
- for Vertex := 0 to 2 do begin
- xx := x + VertPos[Face][Vertex][0];
- yy := y + VertPos[Face][Vertex][1];
- if (xx < 0) then xx := 0;
- if (yy < 0) then yy := 0;
- if (xx > 255) then xx := 255;
- if (yy > 255) then yy := 255;
- t[Vertex][0] := xx;
- t[Vertex][1] := yy;
- t[Vertex][2] := GetHeight(xx, yy) * Scale / 256;
- end;
- n[Face] := GetNormal(t);
- //Normale addieren
- tmp := AddVectors(tmp, n[Face]);
- end;
- Normalize(tmp);
- //von Interval -1..0..1 auf 0..255 umrechnen
- tmp := AddVectors(tmp, MakeVector(1, 1, 1));
- tmp := ScaleVector(tmp, 128);
- //Clamp
- if (tmp[0] > 255) then tmp[0] := 255;
- if (tmp[1] > 255) then tmp[1] := 255;
- if (tmp[2] > 255) then tmp[2] := 255;
- result := tmp;
- end;