unit utilg;

interface

uses graph;

var gd,gm:integer;

procedure initg;
function rad(x:integer):real;
procedure rotplan(xc,yc,x1,y1:integer;var x,y:integer;unghi:real);
procedure d3d2(x1,y1,z1:integer;var x,y:integer);
procedure d3d2n(x1,y1,z1:integer;var x,y:integer);
procedure citimg(x,y:integer;fdim,fimg:string);
procedure scrimg(x1,y1,x2,y2:integer;fdim,fimg:string;var cod:byte);
procedure d3d2g(alfa,beta,gama:real;x1,y1,z1:real;var x,y:real);

implementation

procedure initg;
  begin
    gd:=detect;
    initgraph(gd,gm,'d:\limbaje\tp7\bgi');
    if graphresult <> grok then
                             begin
                               writeln('copiati fisierul "egavga.bgi" in directorul "c:\limbaje\tp\bgi"');
                               halt(0);
                             end;
  end;

function rad;

  begin
    rad:=pi*x/180;
  end;

procedure d3d2;

  begin
    x:=getmaxy div 2 +round(x1+sqrt(2)*z1/4);
    y:=getmaxy div 2 -round(y1+sqrt(2)*z1/4);
  end;

procedure d3d2n;

  begin
    x:=round(x1+sqrt(2)*z1/4);
    y:=round(y1+sqrt(2)*z1/4);
  end;

procedure rotplan(xc,yc,x1,y1:integer;var x,y:integer;unghi:real);

  begin
    x:=round(xc+(x1-xc)*cos(unghi)-(y1-yc)*sin(unghi));
    y:=round(yc+(x1-xc)*sin(unghi)+(y1-yc)*cos(unghi));
  end;

procedure citimg;

var f1:text;
    f2:file;
    dim:integer;
    a:pointer;

  begin
    assign(f1,fdim);
    assign(f2,fimg);
    reset(f1);
    read(f1,dim);
    reset(f2,dim);
    getmem(a,dim);
    blockread(f2,a^,1);
    putimage(x,y,a^,xorput);
    close(f1);
    close(f2);
  end;

procedure scrimg;

var a:pointer;
    dim:integer;
    f1:text;
    f2:file;

  begin
    assign(f1,fdim);
    assign(f2,fimg);
    dim:=imagesize(x1,y1,x2,y2);
    if dim<>0
      then
        begin
          getmem(a,dim);
          getimage(x1,y1,x2,y2,a^);
          rewrite(f1);
          rewrite(f2,dim);
          write(f1,dim);
          blockwrite(f2,a^,1);
          close(f1);
          close(f2);
          cod:=0;
        end
      else cod:=1;
  end;

procedure d3d2g;

  begin
    x:=x1*cos(alfa)+y1*cos(beta)+z1*cos(gama);
    y:=x1*sin(alfa)+y1*sin(beta)+z1*sin(gama);
  end;

end.