Program mujeng;

Uses
  mygraph,
  Types,   { Inertia type declarations     }
  Inertia, { the 3d engine                 }
  Mode13h, { Basic Mode 13h graphics unit  }
  Crt;
Var
  View : ViewObject;   { The View System }
  Obj1,Obj2,Obj3  : VectorObject; { A vector object }
  vx,vy,vz:longint;
  tx,ty,tz,tr:longint;
  romx,romy,romz:integer;
  i:integer;

Procedure SetPalette2;
var I:integer;
begin
 for i:= 0 to 255 do SetPal(i,ActivePal[i,1],ActivePal[i,2],ActivePal[i,3]);
end;

procedure detectkeyboard;
var a:integer;
begin
 begin
   if port[$60]=$01 then
   begin
    FreeView(View);         { Free the view's allocated memory }
    FreeVectorObject(Obj1);
    FreeVectorObject(Obj2);
    FreeVectorObject(Obj3);
    FreeIntensityTable;     { free the intensity table from memory }
    FreeTexture(1);         { Free the phong map }
    setmode($03);
    halt(0);
   end;
 end;
end;

Begin
    If (LoadPCXTexture(1, 'copprenv.PCX', 0) <> I_OK)
    Then Begin
      Writeln('Error loading texture.');
      Halt(0);
    End;
  GetTexturePalette(1);

  If (LoadIntensityTable('COPPRENV.IT', 0) <> I_OK) { load intensity table }
    Then Begin
      Writeln('Error loading Intensity table.');
      Halt(0);
    End;


  If (LoadGVO(Obj1, 'plocha.GVO', 0) <> I_OK)
    Then Begin
      Writeln('Error loading  object.');
      Halt(0);
    End;

  If (LoadGVO(Obj2, 'kvadr.GVO', 0) <> I_OK)         { load the vector object }
    Then Begin
      Writeln('Error loading  object.');
      Halt(0);
    End;

   If (LoadGVO(Obj3, 'romulan.GVO', 0) <> I_OK)         { load the vector object }
    Then Begin
      Writeln('Error loading  object.');
      Halt(0);
    End;






  If (InitView(View, 300) <> I_OK) { init the view }
    Then Begin
      Writeln('Error Initializing view.');
      Halt(0);
    End;
  SetMode($13);              { Set graphics mode }
  SetPalette(GlobalPalette); { Set the palette }


  SetAbsoluteLocation(Obj1, 900, -120, 3200); { Set the object's location }

  SetAbsoluteLocation(Obj2, 880, 139,2140);

  romx:=729;romy:=459; romz:=2219;
  SetAbsoluteLocation(Obj3, romx, romy , romz);

  PushLightSource(View, 0, 2, -1);  { Add a light source }

  SetObjectTexture(Obj1, 1);
  SetSurface(Obj1, reflection);
  SetCull(Obj1, true);
  SetShading(Obj1, gouraud);

  SetSurface(Obj2, SMOOTH);
  SetShading(Obj2, gouraud);

  SetSurface(Obj3, SMOOTH);
  SetShading(Obj3, lambert);


  SetBaseColor(Obj1, 36);      { set the object's color }

  SetBaseColor(Obj2, 40);

  SetBaseColor(Obj3, 45);

  vx:=1200;vy:=900;vz:= -700;
  tx:=0;ty:=0;tz:=6000;tr:=0;
  SetViewLocation(View, vx,vy,vz);
  SetFocusPoint(View, tx, ty,tz,tr);

  Setdeltarotation(Obj1, 0, 800, 0);
  Setdeltarotation(Obj2, -25,0, 250);
  Setdeltarotation(Obj3, 270,0,0);

    getpalette;
    nullpalette;
    setpalette2;
    AddtoRenderList(View, Obj1);
    AddtoRenderList(View, Obj2);
    AddtoRenderList(View, Obj3);
    Render(View, VirtualPage);       { render to the virtual page }
    waitretrace;
    flip;
    fadein(30);
    DELAY(3000);



{ZACATEK MOVE1}
  for i:= 1 to 30 do
   begin
    dec(vx,20);
    dec(vy,20);
    inc(vz,20);
    dec(tz,20);
    SetViewLocation(View, vx,vy,vz);
    SetFocusPoint(View, tx, ty,tz,tr);
    AddtoRenderList(View, Obj1);
    AddtoRenderList(View, Obj2);
    AddtoRenderList(View, Obj3);
    Render(View, VirtualPage);       { render to the virtual page }
    detectkeyboard;
    waitretrace;
    Flip;                            { Copy the page over }
    DELAY(10);
   END;

   for i:= 1 to 100 do
   begin
    inc(vz,10);
    dec(vx,70);
    inc(tx,70);
    inc(vy,10);
    SetViewLocation(View, vx,vy,vz);
    SetFocusPoint(View, tx, ty,tz,tr);
    AddtoRenderList(View, Obj1);
    AddtoRenderList(View, Obj2);
    AddtoRenderList(View, Obj3);
    Render(View, VirtualPage);       { render to the virtual page }
    detectkeyboard;
    waitretrace;
    Flip;                            { Copy the page over }
    delay(10);
   end;


   for i:= 1 to 100 do
   begin
    inc(vx,60);
    dec(tx,30);
    dec(tz,10);
    dec(vy,6);
    SetViewLocation(View, vx,vy,vz);
    SetFocusPoint(View, tx, ty,tz,tr);
    AddtoRenderList(View, Obj1);
    AddtoRenderList(View, Obj2);
    AddtoRenderList(View, Obj3);
    Render(View, VirtualPage);       { render to the virtual page }
    detectkeyboard;
    waitretrace;
    Flip;                            { Copy the page over }
    delay(10);
   end;

   for i:= 1 to 160 do
   begin
    inc(vx,1);
    inc(vz,7);
    dec(tx,4);
    dec(tz,10);
    rotatelightsource(view,0,50,0,0);
    delay(10);
    SetViewLocation(View, vx,vy,vz);
    SetFocusPoint(View, tx, ty,tz,tr);
    AddtoRenderList(View, Obj1);
    AddtoRenderList(View, Obj2);
    AddtoRenderList(View, Obj3);
    Render(View, VirtualPage);
    detectkeyboard;
    delay(10);
    waitretrace;
    Flip;

   end;



  for i:= 1 to 90 do
   begin
    rotatelightsource(view,0,50,0,0);
    AddtoRenderList(View, Obj1);
    AddtoRenderList(View, Obj2);
    AddtoRenderList(View, Obj3);
    Render(View, VirtualPage);
    detectkeyboard;
    delay(10);
    waitretrace;
    Flip;
    delay(10);
   end;
{KONEC MOVE1}

  vx:=-240;
  vy:=700;
  vz:=2020;
  tx:=3360;
  ty:=0;
  tz:=2800;

  SetViewLocation(View, vx,vy,vz);
  SetFocusPoint(View, tx, ty,tz,tr);


   for i:= 1 to 100 do
   begin
    inc(romy,1);
    setabsolutelocation(obj3,romx,romy,romz);
    AddtoRenderList(View, Obj3);
    AddtoRenderList(View, Obj2);
    AddtoRenderList(View, Obj3);
    Render(View, VirtualPage);
    detectkeyboard;
    waitretrace;
    Flip;
    delay(20);
   end;





   for i:= 1 to 140 do
   begin
    setdeltarotation(obj3,10,7,0);
    AddtoRenderList(View, Obj1);
    AddtoRenderList(View, Obj2);
    AddtoRenderList(View, Obj3);
    Render(View, VirtualPage);
    detectkeyboard;
    waitretrace;
    Flip;
    delay(20);
   end;


   for i:= 1 to 40 do
   begin
    setdeltarotation(obj3,10,0,-4);
    AddtoRenderList(View, Obj1);
    AddtoRenderList(View, Obj2);
    AddtoRenderList(View, Obj3);
    Render(View, VirtualPage);
    detectkeyboard;
    waitretrace;
    Flip;
    delay(20);
   end;

   for i:= 1 to 200 do
   begin
    inc(romx,13);
    inc(romy,2);
    inc(romz,3);
    setabsolutelocation(obj3,romx,romy,romz);
    AddtoRenderList(View, Obj1);
    AddtoRenderList(View, Obj2);
    AddtoRenderList(View, Obj3);
    Render(View, VirtualPage);
    detectkeyboard;
    waitretrace;
    Flip;
    delay(20);
   end;





    AddtoRenderList(View, Obj1);
    AddtoRenderList(View, Obj2);
    AddtoRenderList(View, Obj3);
    Render(View, VirtualPage);
    detectkeyboard;
    waitretrace;
    Flip;
    delay(2000);

  FreeView(View);         { Free the view's allocated memory }
  FreeVectorObject(Obj1);
  FreeVectorObject(Obj2);
  FreeVectorObject(Obj3);
  FreeIntensityTable;     { free the intensity table from memory }
  FreeTexture(1);         { Free the phong map }

  getpalette;
  fadeout(30);

  SetMode($03);           { return to text mode }
End.
