unit uobywatele;

interface

uses glvectorfileobjects,glscene,globjects,umklogger,SysUtils,gltexture;

type tobywatele=class
public
        lb:array[1..8] of tglfreeform;
        ludzie:array [1..100] of tglproxyobject;
        radius:real;
        vis:integer;
        baza,przy:tgldummycube;
        log:tmklogger;
        matlib:tglmateriallibrary;
        constructor create;
        procedure init;
        procedure zalosuj;
        procedure zalosujP(h,w:real);
        procedure pokaz;
end;

implementation

constructor tobywatele.create;
begin
end;

procedure tobywatele.init;
var i:integer;
r:integer;
begin
        przy:=tgldummycube.Create(baza);
        przy.Parent:=baza;
        matlib:=tglmateriallibrary.Create(nil);
        matlib.TexturePaths:=getcurrentdir+'\scene';

        for i:=1 to 8 do begin
                lb[i]:=tglfreeform.create(nil);
                lb[i].MaterialLibrary:=matlib;
        end;


        lb[1].loadfromfile('scene\m1_p1.3ds');
        lb[2].loadfromfile('scene\m1_p2.3ds');
        lb[3].loadfromfile('scene\m2_p1.3ds');
        lb[4].loadfromfile('scene\m2_p2.3ds');
        lb[5].loadfromfile('scene\m3_p1.3ds');
        lb[6].loadfromfile('scene\m3_p2.3ds');
        lb[7].loadfromfile('scene\m4_p1.3ds');
        lb[8].loadfromfile('scene\m4_p2.3ds');

        for i:=1 to 100 do begin
                ludzie[i]:=tglproxyobject.create(przy);
                ludzie[i].parent:=przy;
                r:=random(16);
                ludzie[i].masterobject:=lb[2*(r mod 4)+1];
               // log.wriln(format('%d %d',[r mod 2,2*(r mod 2)+1]));
        end;


end;

procedure tobywatele.zalosujP(h,w:real);
var i:integer;
a,r,al:real;
//aaa:tglsphere;
begin
        for i:=1 to 100 do begin
                a:=random(round(h*100))/100-h/2;
                al:=random(round(w*100))/100-w/2;
                //log.wriln(floattostr(a)+' '+floattostr(al));
                r:=random(360);
                ludzie[i].position.x:=a;
                ludzie[i].position.z:=al;

                ludzie[i].up.y:=0;
                ludzie[i].up.z:=-1;
                ludzie[i].up.X:=0;

                ludzie[i].Direction.X:=0;
                ludzie[i].Direction.y:=1;
                ludzie[i].Direction.z:=0;

          {      aaa:=tglsphere.Create(przy);
                aaa.parent:=przy;
                aaa.Position.x:=a;
                aaa.position.z:=al;
                aaa.Radius:=0.1;      }


                ludzie[i].rollangle:=r;

            //    log.wriln(format('LUDZ %.2f    %.2f',[a, al]));


         end;
   {
             log.wriln(format('Przy %.2f %.2f %.2f',[przy.absolutePosition[0],
                                                        przy.absolutePosition[1],
                                                        przy.absolutePosition[2]]));
   }

end;

procedure tobywatele.zalosuj;
var i:integer;
a,r,al:real;
begin
        for i:=1 to 100 do begin
                a:=random(360);
                al:=random(360);
                r:=random(round(radius/3));
                ludzie[i].position.x:=r*sin(a*pi/180);
                ludzie[i].position.z:=r*cos(a*pi/180);

                ludzie[i].up.y:=0;
                ludzie[i].up.z:=-1;
                ludzie[i].up.X:=0;

                ludzie[i].Direction.X:=0;
                ludzie[i].Direction.y:=1;
                ludzie[i].Direction.z:=0;

                ludzie[i].rollangle:=al;
        end;
         {       log.wriln(format('LUDZ %.2f %.2f %.2f',[przy.absolutePosition[0],
                                                        przy.absolutePosition[1],
                                                        przy.absolutePosition[2]]));

        }

end;

procedure tobywatele.pokaz;
var i:integer;
vi:integer;
begin
        vi:=vis;
        if vi>100 then vi:=100;
        for i:=1 to vi do ludzie[i].visible:=true;
        for i:=vi+1 to 100 do ludzie[i].visible:=false;
end;

end.
