unit environment;

interface

uses
  perso,
  System.Collections,
  System.ComponentModel,
  System.Data,
  System.Drawing,
  System.Windows.Forms,
  System.IO,
  Microsoft.DirectX,
  Microsoft.DirectX.DirectInput,
  Microsoft.DirectX.Direct3D;

type
  TSpheres = record
    pos : TPos;
    scale : integer;
  end;
  TEnvironment = class
    spheres : array[0..19] of TSPheres;
    mesh : mesh;
    materialarray : array of ExtendedMaterial;
    meshmaterials : array[0..0] of material;
    meshtextures : array[0..0] of texture;
    constructor create;
    procedure initialize( TailleX,TailleZ:integer;device : device);
  end;

implementation

constructor TEnvironment.create;
begin
  inherited;
end;

procedure TEnvironment.initialize( TailleX,TailleZ:integer;device:device);
var
  x : integer;
  vertices : vertexbuffer;
  stream : GraphicsStream;
begin
  x := 0;
  while x < 20 do
  begin
    spheres[x].pos.x := (random(2)-0.5)*2*(random(20)+6+tailleX/2)+tailleX/2;
    spheres[x].pos.z := (random(2)-0.5)*2*(random(20)+6+tailleX/2)+tailleX/2;
    spheres[x].pos.y := (random(40))-20;
    spheres[x].scale := 1/(random(10)+1)
  end;
  mesh := Mesh.FromFile('texture/mesh/' + 'sphere.x', MeshFlags.Managed, device, materialarray);

  meshmaterials[0] := materialarray[0].Material3D;
  meshmaterials[0].Ambient := meshmaterials[0].Diffuse;

  if ((materialarray[0].TextureFilename <> nil) and (materialarray[0].TextureFilename <> '')) then
    meshtextures[0] := TextureLoader.FromFile(device,'texture/mesh/' + materialarray[0].TextureFilename);

  mesh := mesh.Clone(mesh.Options.Value, CustomVertex.PositionNormalTextured.Format, device);
  mesh.ComputeNormals();
  vertices := mesh.VertexBuffer;
  stream := vertices.Lock(0, 0, LockFlags.None);

  vertices.Unlock();
end;

end.
