unit uMap;

interface

uses uGlobal, Windows, Graphics, uObjects;

const
  MapRadius = 500;

var
  Map: TBitmap;
  Wind: integer;

  procedure MapInit;
  function MapZ(X, Y: Double): Double;

implementation

uses uGame, uMaterials;

procedure MapInit;
var
  x, y: array of double;
begin
  //Sky
  call('glObjectAdd',[otSkyDome, 'sky']);
  call('glRotation', ['sky', 0,0,90]) ;
  call('glPosition', ['sky', 0,-20,0]) ;
  SetLength(X, 10); SetLength(Y, 10);
  // Begin angle, r, g, b, a
  // end angle, r, g, b, a
  X[0]:=-90; X[1]:=1; X[2]:=1; X[3]:=1; X[4]:=1;
  X[5]:= 30; X[6]:=0.8; X[7]:=0.8; X[8]:=1; X[9]:=1;
  Y[0]:=30 ; Y[1]:=0.8; Y[2]:=0.8; Y[3]:=1; Y[4]:=1;
  Y[5]:=90; Y[6]:=0.3; Y[7]:=0.5; Y[8]:=0.8; Y[9]:=1;
  call('glObjectParams', ['sky', x, y]);

  //Land
  call('glObjectAdd',[otTerrain, 'terrain']);
  call('glScale', ['terrain', 1,1,0.1]) ;
  call('glRotation', ['terrain', 0,0,90]) ;
  call('glObjectParams', ['terrain', 'data\maps\0.bmp', tsTesselated, 10, 5000, 100]);
  Call('glObjectMaterial', ['terrain', 'ground_sand']);

  call('glObjectAdd',[otLensFlare, 'LensFlare', -1]);
  call('glPosition', ['LensFlare', -5000, 2000, 5000]) ;
  call('glObjectParams', ['LensFlare', 100]);

  Map:= TBitmap.Create;
  Map.LoadFromFile('data\maps\0.bmp');

  //============================================================================
end;

function MapZ(X, Y: Double): Double;
var
  mx, my: integer;
begin
  mx:=round(X-trunc(X/(Map.Width))*(Map.Width));
  mY:=round(Y-trunc(Y/(Map.Height))*(Map.Height));

  if mX<0 then mX:=(Map.Width)+mX;
  if mY<0 then mY:=(Map.Height)+mY;

  Result:=(GetRValue(Map.Canvas.Pixels[mX, mY]));
  Result:=Result/10;
end;

end.
