unit uAdd;

interface

uses zglHeader,
     uVar;

Function Less(v1, v2 : real) : boolean; inline;
function r(x, y, w, h : single) : zglTRect; inline;
function c(x, y, r : single) : zglTCircle; inline;
function pt(x, y : single) : zglTPoint2d; inline;

function CalcX2D( const X : Single ) : Single; inline;
function CalcY2D( const Y : Single ) : Single; inline;

function CvsC(c1, c2 : zglTCircle): boolean;

procedure Blur(tex : zglPTexture; passes : byte);

implementation

Function Less(v1, v2 : real) : boolean; inline;
begin
  result := true;
  if (v1 >= v2) then result := false;
end;

function r(x, y, w, h : single) : zglTRect; inline;
begin
  result.X := x;
  result.Y := y;
  result.W := w;
  result.H := h;
end;

function c(x, y, r : single) : zglTCircle; inline;
begin
  result.cX := x;
  result.cY := y;
  result.Radius := r;
end;

function pt(x, y : single) : zglTPoint2d; inline;
begin
  result.X := x;
  result.Y := y;
end;


function CalcX2D( const X : Single ) : Single; inline;
begin
  Result := ( X - SCREEN_WIDTH / 2 ) * ( 1 / SCREEN_WIDTH / 2 );
end;

function CalcY2D( const Y : Single ) : Single; inline;
begin
  Result := ( Y - SCREEN_HEIGHT / 2 ) * ( 1 / SCREEN_HEIGHT / 2 );
end;

function CvsC(c1, c2 : zglTCircle): boolean;
var d : single;
begin
  result := false;
  d := m_Distance(c1.cX, c1.cY, c2.cX, c2.cY);
  if d <= (c1.Radius + c2.Radius) then result := true;
end;

procedure Blur(tex : zglPTexture; passes : byte);
var texCoords : array[0..3] of zglTPoint2d;
    x, y, i   : integer;
begin
  for I := 0 to passes - 1 do
    for x := 0 to 2 do
      begin
      for y := 0 to 2 do
        begin
          texCoords[3].X := 0 + (x-0.5)/800;
          texCoords[3].Y := 0 + (y-0.5)/600;
          texCoords[2].X := 1 + (x-0.5)/800;
          texCoords[2].Y := 0 + (y-0.5)/600;
          texCoords[1].X := 1 + (x-0.5)/800;
          texCoords[1].Y := 1 + (y-0.5)/600;
          texCoords[0].X := 0 + (x-0.5)/800;
          texCoords[0].Y := 1 + (y-0.5)/600;


       //   pr2d_triList(tex, @trilist[0], @texcoords[0], 0, 3, $00ff00, 255,pr2d_fill);

          texture2d_draw(tex, texCoords, 0, -424, 1024, 1024, 0,round(255/(x + y + 3)), FX_BLEND );
        end;
      end;
end;

end.
