unit SceneUnit;

interface

Uses
  SysUtils,
  Windows,
  Direct3D9,
  D3DX9,
  GraphUtils;

TYPE
  TGameScene = class
    protected
      Game      : TGame; //Игровой объект
      Parent    : TGameScene;
      ExitScene : LongBool; //Флаг выхода из сцены

      Lights    : array[0..7] of TD3DLight9; //Источники света

      Camera    : TCamera;

    private
    public
      Property GetParent : TGameScene Read Parent;

      Constructor Create(GameObj : TObject; GameScene : TGameScene); Virtual;
      Procedure Free; Virtual;
      Function Process : TGameScene; Virtual;
      Procedure Draw; Virtual;

      Procedure Exit;
  end;

implementation

Uses
  MathUnit;

//============================================================================//
//============================================================================//
//============================================================================//

Constructor TGameScene.Create(GameObj : TObject; GameScene : TGameScene);
begin
  Inherited Create;
  ExitScene := False;
  Game      := GameObj as TGame;
  Parent    := GameScene;
  FillChar(Lights,SizeOf(Lights),$00);
  Camera    := TCamera.Create(Game);
end;

//============================================================================//

Procedure TGameScene.Free;
begin
  if Camera<>nil then
  begin
    Camera.Free;
    Camera:=nil;
  end;
end;

//============================================================================//

Function TGameScene.Process : TGameScene;
begin
  if ExitScene then Result:=GetParent else Result:=Self;
end;

//============================================================================//

Procedure TGameScene.Draw;
begin
  If Camera<>nil then Camera.SetCamera; //Установка значений камеры
  With Game.GetDevice do
  begin
    SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
    SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
    SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
    SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1 );
    SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );

    SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
    SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
    SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR );
    SetSamplerState( 0, D3DSAMP_ADDRESSU,  D3DTADDRESS_CLAMP );
    SetSamplerState( 0, D3DSAMP_ADDRESSV,  D3DTADDRESS_CLAMP );

    SetRenderState( D3DRS_DITHERENABLE, 1 );
    SetRenderState( D3DRS_ZENABLE,      1 );

    SetRenderState(D3DRS_ALPHABLENDENABLE, 0);
    SetRenderState(D3DRS_CLIPPING, Integer(True));

    SetRenderState(D3DRS_LIGHTING, 1);

    SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
    SetRenderState(D3DRS_NORMALIZENORMALS, 1);
  end;
end;

//============================================================================//


Procedure TGameScene.Exit;
begin
  ExitScene:=True;
end;


//============================================================================//
//============================================================================//
//============================================================================//

end.
