unit Objet;

interface

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

type
  TMove = record
    x, y, z, angle : real;
    saut : boolean;
  end;

  TEventHandler      = System.EventHandler;
  TEventArgs         = System.EventArgs;
  TKeyEventArgs      = System.Windows.Forms.KeyEventArgs;
  TMouseEventArgs    = System.Windows.Forms.MouseEventArgs;
  TPaintEventArgs    = System.Windows.Forms.PaintEventArgs;
  TKeys              = System.Windows.Forms.Keys;
  TForm              = System.Windows.Forms.Form;
  TColor             = System.Drawing.Color;
  TIcon              = System.Drawing.Icon;



  TPerso = class
    private
    public
      move : TMove;
      constructor create;
      procedure OnResetDevice(sender : Tobject ; e : eventArgs);
      procedure Drawmesh();
    private
      mesh      : Mesh;
      Fdevice    : Device;
      MeshMaterials : Array of Microsoft.DirectX.Direct3D.Material ;
      Meshtextures  : Array of Texture ;

  end;

implementation

constructor TPerso.create;
begin
   inherited;
end;

procedure TPerso.OnResetDevice(sender : Tobject ; e : eventArgs);
var
  Materials : array of ExtendedMaterial;     // Tableau des matériaux
  i, taille : integer;
  dev:Device;

begin
  materials := nil ;
  dev := Device(sender);
  dev.RenderState.ZBufferEnable := true;
  dev.RenderState.Ambient := System.Drawing.Color.White;

  mesh := Mesh.FromFile('tiger.x', MeshFlags.SystemMemory, device , materials);
  taille:= high(Materials);
  if (meshTextures = nil) then
     begin
                // We need to extract the material properties and texture names
                meshTextures  := Texture.create(high(materials));
                meshMaterials := Microsoft.DirectX.Direct3D.Material.create[materials.Length];
                for  i:=0 to materials.length do
                  begin

                    meshMaterials[i] := materials[i].Material3D;
                    // Set the ambient color for the material (D3DX does not do this)
                    meshMaterials[i].Ambient := meshMaterials[i].Diffuse;
     
                    // Create the texture
                    meshTextures[i] := TextureLoader.FromFile(dev, materials[i].TextureFilename);
                  end;
    end;


end;




procedure TPerso.Drawmesh();
  var
    i : integer;
  begin
    for i := 0 to high(MeshMaterials) do
      begin
        Fdevice.Material := MeshMaterials[i];
        if Meshtextures[i] <> nil then
          Fdevice.SetTexture(0, Meshtextures[i]);
          mesh.DrawSubset(i);
      end;
  end;


end.
