unit _SkyBox;

interface

uses      
  OpenGL,
  _Scene,  
  _OpenGL,
  _Forms,
  _Geometry;

type
TSkyBox = class(TRender)
  private
    Quad: array [0..3] of TVector3;
    Color: TVector3;
  public
    constructor Create;
    procedure Render; override;   
    procedure Control; override;
end;

implementation

{$REGION 'SkyBox'}
constructor TSkyBox.Create;
var
  Shift: TVector2;
begin
  Shift.Create(Random(100) - 50, Random(100) - 50);

  Quad[0]:= Vector3(2, 0, 1) + Shift;
  Quad[1]:= Vector3(2, 2, 1) + Shift;
  Quad[2]:= Vector3(0, 2, 1) + Shift;
  Quad[3]:= Vector3(0, 0, 1) + Shift;
  Color.Create(Random(5), Random(5), Random(5));
end;

procedure TSkyBox.Render;
begin
  glColor3fv(@Color);
  glBegin(GL_QUADS);
  glVertex3fv(@Quad[0]);
  glVertex3fv(@Quad[1]);
  glVertex3fv(@Quad[2]);
  glVertex3fv(@Quad[3]);
  glEnd;
end;            

procedure TSkyBox.Control;
var                               
  i: Byte;
  Mouse: TPoint;
  Sides: array [0..3] of TVector2;
begin
  Mouse.Vector2i(Window.Mouse.X, Window.Height - Window.Mouse.Y);
  for i:= 0 to 3 do
     Sides[i]:= TOpenGL.Point_To_Coord(Quad[i]);
  if (TVector2(Mouse).InTriangle(Sides[0], Sides[1], Sides[2])) or
     (TVector2(Mouse).InTriangle(Sides[2], Sides[3], Sides[0])) then
    Color.Create(Random(5), Random(5), Random(5));
  
end;
{$ENDREGION}

end.
