unit ObjectLihgt;

interface

uses
  CustomObject, Vec2f, System.SysUtils, IniFiles, QuadEngine.Color;

type
  TObjectLihgt = class(TCustomObject)
  private
    FRadius: Single;
    FColor: TQuadColor;
    FHeight: Single;
  published
    procedure DrawLight; override;

    procedure Load(Aini: TIniFile); override;
  end;

implementation

uses
  Resources, Level.Map;

procedure TObjectLihgt.Load(Aini: TIniFile);
var
  Str: String;
begin
  inherited;
  Str := 'Obj_' + IntToStr(ID);
  FRadius := Aini.ReadFloat(Str, 'Radius', 1);
  FHeight := Aini.ReadFloat(Str, 'Height', 0.015);
  FColor := StrToInt('$' + Aini.ReadString(Str, 'Color', 'FFFFFFFF'));
end;

procedure TObjectLihgt.DrawLight;
begin
  if Action then
  begin
    TGlobals.QuadCamera.Disable;
    TTextures.QuadGBuffer.DrawLight(
      TVec3f.Create(
        (Position.X - TGlobals.QuadCamera.GetPosition.X) / TGlobals.GWidth,
        (Position.Y - TGlobals.QuadCamera.GetPosition.Y) / TGlobals.GHeight,
        FHeight
      ), FRadius, FColor);
    TGlobals.QuadCamera.Enable;
  end;
end;

end.
