{
  Main game unit

  Mefistofel
  23.03.2012
}
unit _World;

interface

Uses
  _Geometry,
  Frost.Engine, 
  Frost.Forms,
  Frost.Utils,
  Frost.Renderers,
  OpenGL,
  Frost.GL;

type
TWorld = class(TScene)
  private
//    MoveVector: TVector3;
//    Scale: Shortint;
//    PrevMouseCoord: TPoint;
  public
    procedure Render;
    procedure OnStart; override;
    procedure OnUpdate(delta: Double); override;
  end;

var
  World:TWorld;    
  temp,
  temp2,
  temp3: TGameObject;
  Answer: Integer;

implementation

 //World
{$REGION 'World'}
procedure TWorld.OnStart;
begin
  FCameraController.LocalPosition := Vector3(0,0,10);

  TGameObject.Create(nil).AddComponent(TMeshRenderer.Create); 
  TGameObject.Create(nil, Vector3(3, 0, 0), Vector3(50, 20, 0)).AddComponent(TMeshRenderer.Create);
  temp := TGameObject.Create(nil, Vector3(0, 2, 0), VECTOR3_NULL);
  temp.AddComponent(TMeshRenderer.Create);
  temp2 := TGameObject.Create(temp, Vector3(0, 2, 0), VECTOR3_NULL);
  temp2.AddComponent(TMeshRenderer.Create);    
  temp3 := TGameObject.Create(temp2, Vector3(0, 2, 0), VECTOR3_NULL);
  temp3.AddComponent(TMeshRenderer.Create);
end;

procedure TWorld.Render;
begin

end;

var a:single;

procedure TWorld.OnUpdate(delta: Double);
begin
  //WriteLn(123);
  if Control.Key[KEY_ESC] then
    Application.Close;   
  if Control.Key[KEY_SPACE] then
    Application.Close;
  a:= a + 0.05;                                                      
  temp.LocalPosition := temp.LocalPosition + Vector3(0, Sin(a) * 0.05, 0);
  temp.LocalRotation := temp.LocalRotation * Rotate(1.5, Vector3(0, 0, 1));
//  temp2.LocalPosition := temp2.LocalPosition + Vector3(Sin(a) * 0.05, 0, 0);
  temp2.LocalRotation := temp2.LocalRotation * Rotate(3, Vector3(0, 0, 1));
//  temp3.LocalPosition := temp3.LocalPosition + Vector3(Sin(a * 2) * 0.1, 0, 0);
  temp3.LocalRotation := temp3.LocalRotation * Rotate(3, Vector3(0, 1, 0));


  if (Control.Key[KEY_UP]) or (Control.Key[KEY_W]) then
    FCameraController.LocalPosition := FCameraController.LocalPosition + Vector3( 0, 1 * delta, 0);
  if (Control.Key[KEY_DOWN]) or (Control.Key[KEY_S]) then
    FCameraController.LocalPosition := FCameraController.LocalPosition + Vector3( 0,-1 * delta, 0);
  if (Control.Key[KEY_LEFT]) or (Control.Key[KEY_A]) then
    FCameraController.LocalPosition := FCameraController.LocalPosition + Vector3(-1 * delta, 0, 0);
  if (Control.Key[KEY_RIGHT]) or (Control.Key[KEY_D]) then
    FCameraController.LocalPosition := FCameraController.LocalPosition + Vector3( 1 * delta, 0, 0);

  if Control.Mouse.Wheel < 0 then
    FCameraController.LocalPosition := FCameraController.LocalPosition + Vector3( 0, 0, 4 * delta);
  if Control.Mouse.Wheel > 0 then
    FCameraController.LocalPosition := FCameraController.LocalPosition + Vector3( 0, 0,-4 * delta);

  if (Control.Key[KEY_Q]) then
    FCameraController.LocalRotation := FCameraController.LocalRotation * Rotate(3, Vector3(0, 1 * delta, 0));
  if (Control.Key[KEY_E]) then
    FCameraController.LocalRotation := FCameraController.LocalRotation * Rotate(-3, Vector3(0, 1 * delta, 0));
  //TDOD - Set enum  
  Control.Mouse.Wheel := 0;
 { Self.FParentScene.Camera.Position:=
      Self.FParentScene.Camera.Position +
      Rotate(Self.FParentScene.Camera.Angles.X, Vector3(0, 0, 1)) * MoveVector * 1 * Delta;      }
end;
{$ENDREGION}

end.
