unit Objet;

interface

uses
  System.Drawing,
  System.Windows.Forms,
  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;
      FVertexBuffer : VertexBuffer;
      constructor create;
      //procedure initialize(FDevice : Device);
      procedure OnCreateVertexBuffer(sender: TObject; e: TEventArgs);
      procedure OnCreateDevice(sender: TObject; e: TEventArgs);
      procedure OnResetDevice(sender: TObject; e: TEventArgs);
  end;

implementation

constructor TPerso.create;
begin
   inherited;
end;

//procedure TPerso.initialize(FDevice : Device);
//begin
//    TPerso.OnCreateDevice(FDevice,nil);
//    TPerso.OnResetDevice(FDevice, nil);
//end;

procedure TPerso.OnCreateVertexBuffer(sender: System.Object; e: EventArgs);
var
  verts: array[0..35]  of CustomVertex.PositionColored;
  stm: GraphicsStream;
begin
   Self.FVertexBuffer := VertexBuffer( sender ) ;
  stm := Self.FVertexBuffer.Lock( 0, 0, LockFlags( 0 ) );

  // 1er face

  verts[ 0 ] := CustomVertex.PositionColored.Create( 0 , 0, 0, TColor.Blue.ToArgb );
  verts[ 1 ] := CustomVertex.PositionColored.Create(  1, 0, 0, TColor.Blue.ToArgb );
  verts[ 2 ] := CustomVertex.PositionColored.Create( 0,  1, 0, TColor.Blue.ToArgb );
  verts[ 3 ] := verts [ 2 ];
  verts[ 4 ] := verts [ 1 ];
  verts[ 5 ] := CustomVertex.PositionColored.Create(  1,  1, 0, TColor.Blue.ToArgb );

  // 2eme face

  verts[ 6 ] := CustomVertex.PositionColored.Create(0, 0, 1, TColor.Gray.ToArgb );
  verts[ 7 ] := CustomVertex.PositionColored.Create(  1, 0, 1, TColor.Gray.ToArgb );
  verts[ 8 ] := CustomVertex.PositionColored.Create( 0,  1, 1, TColor.Gray.ToArgb );
  verts[ 9 ] :=  verts [ 8];
  verts[ 10 ] := verts [ 7 ];
  verts[ 11 ] := CustomVertex.PositionColored.Create(  1,  1, 1, TColor.Gray.ToArgb );

  // 3eme face

  verts[ 12 ] := verts [ 2 ];
  verts[ 13 ] := verts [ 5 ];
  verts[ 14 ] := verts [ 8 ];
  verts[ 15 ] := verts [ 8 ];
  verts[ 16 ] := verts [ 5 ];
  verts[ 17 ] := verts [ 11 ];

    // 4eme face - Face du dessous

  verts[ 18 ] := verts [ 0 ];
  verts[ 19 ] := verts [ 1 ];
  verts[ 20 ] := verts [ 6 ];
  verts[ 21 ] := verts [ 6 ];
  verts[ 22 ] := verts [ 1 ];
  verts[ 23 ] := verts [ 7 ];

    // 5eme face

  verts[ 24 ] := verts [ 1 ];
  verts[ 25 ] := verts [ 5 ];
  verts[ 26 ] := verts [ 7 ];
  verts[ 27 ] := verts [ 7 ];
  verts[ 28 ] := verts [ 5 ];
  verts[ 29 ] := verts [ 11 ];

    // 6eme face

  verts[ 30 ] := verts [ 0 ];
  verts[ 31 ] := verts [ 2 ];
  verts[ 32 ] := verts [ 6 ];
  verts[ 33 ] := verts [ 6 ];
  verts[ 34 ] := verts [ 2 ];
  verts[ 35 ] := verts [ 8 ];

  stm.Write(verts);
  Self.FVertexBuffer.Unlock;
end;

procedure TPerso.OnCreateDevice(sender: System.Object; e: EventArgs);
var
  dev: Device;
begin
  dev := Device( sender );
  // Now Create the VB
  Self.FVertexBuffer := VertexBuffer.Create( TypeOf( CustomVertex.PositionColored ), 36, dev, Usage( 0 ), CustomVertex.PositionColored.Format, Pool.Default );
  //Include( Self.FVertexBuffer.Created, TPerso.OnCreateVertexBuffer );
  Self.OnCreateVertexBuffer( Self.FVertexBuffer, nil );
end;

procedure TPerso.OnResetDevice(sender: TObject; e: TEventArgs);
var
  dev: Device;
begin
  dev := Device( sender );
  // Turn off culling, so we see the front and back of the triangle
  //dev.RenderState.CullMode := Cull.None;
  // Turn off D3D lighting, since we are providing our own vertex colors
  dev.RenderState.Lighting := False;
end;

end.
