home *** CD-ROM | disk | FTP | other *** search
/ Virtual Reality Homebrewer's Handbook / vr.iso / vroom / toyfac.pas < prev    next >
Pascal/Delphi Source File  |  1996-03-19  |  15KB  |  507 lines

  1. program toyfac;
  2.  
  3. uses swoop, swoop_discrete, swoop_vr, vroom, store, cyberman;
  4.  
  5. var bodystore, wheelstore, paintstore : vbar;
  6.     source_car1, source_car2, source_carbody, source_wheel1, source_wheel2, source_carwheel, source_box : file_object3d;
  7.  
  8.     bodyslicemach, wheelslicemach, body_here, wheel_here, worker : resource;
  9.     body_stamp, wheel_stamp, arm, body_spray : resource3d;
  10.     body_stampb, wheel_stampb, floor : file_object3d;
  11.     body_worker, body_worker_box, wheel_worker, wheel_worker_box, crate_worker : file_object3d;
  12.     boxslicemachpic, wheelslicemachpic, armb, cratingpic, sprayb, spraypic1, spraypic2 : file_object3d;
  13.  
  14.     s1,s2,dw : process;
  15.     b : array[1..37] of process;
  16.     w : array[1..45] of process;
  17.     bw,ww : array[1..6] of process;
  18.     p : array[1..5] of process;
  19.     i, c : integer;
  20.     t, paint_out, paint_in : real;
  21.     paint : statevar;
  22.     manual_control, mouse, cyberm : boolean;
  23.  
  24. {$F+}
  25. procedure Calculate;
  26. begin
  27.      if paint.state>15 then paint_in:=0;
  28.      if not(manual_control) and (paint.state<2) then paint_in:=1;
  29.      paint.dot:=-paint_out+paint_in;
  30. end;
  31.  
  32. procedure Update_Screen;
  33. var junk1 : boolean;
  34. begin
  35.      if abs(paintstore.value-(paint.state-1))>0.1 then paintstore.update(paint.state-1);
  36.      if mouse then junk1:=Mouse_Check;
  37.      if cyberm then junk1:=Cyberman_Check;
  38.      junk1:=KeyBoard_Check;
  39.      redraw_scene;
  40. end;
  41.  
  42. function My_KeyCheck(key : char) : boolean;
  43. var f : text;
  44. begin
  45.      if (key='t') and manual_control then if paint_in>0 then paint_in:=0 else paint_in:=2;
  46.      if key='m' then manual_control:=not(manual_control);
  47. end;
  48.  
  49. procedure wheel_to_stamp;
  50. var temppic : object3d_ptr;
  51. begin
  52.      simulation.thisentity^.ChangeTime(simulation.TIME+8);
  53.      temppic:=simulation.thisentity^.picture;
  54.      temppic^.MoveTo(85,80,0);
  55.      temppic^.Timed_MoveTo(85,95,0,now,2);
  56.      temppic^.Timed_RotateZ_About(-90,105,95,0,now+2,5);
  57. end;
  58.  
  59. procedure body_stamp_proc(f_ob,b_ob : object3d_ptr);
  60. begin
  61.      b_ob^.Timed_Translate(0,0,-40,now,2.5);
  62.      b_ob^.Timed_Translate(0,0,40,now+2.5,2.5);
  63. end;
  64.  
  65. procedure wheel_stamp_proc(f_ob,b_ob : object3d_ptr);
  66. begin
  67.      b_ob^.Timed_Translate(0,0,-40,now,2);
  68.      b_ob^.Timed_Translate(0,0,40,now+2,2);
  69. end;
  70.  
  71. procedure seize_arm_proc(f_ob,b_ob : object3d_ptr);
  72. begin
  73.      b_ob^.Timed_RotateZ(180,now,2);
  74.      b_ob^.Timed_RotateZ(-180,now+2,2)
  75. end;
  76.  
  77. procedure body_worker_in;
  78. begin
  79.      simulation.thisentity^.ChangeTime(simulation.TIME+30);
  80.      body_worker.Show;
  81.      body_worker_box.Show;
  82.      body_worker.Timed_MoveTo(35,-16,0,now,30);
  83. end;
  84.  
  85. procedure add_body_to_store;
  86. var n : integer;
  87.     temp : entityptr;
  88. begin
  89.      simulation.thisentity^.ChangeTime(simulation.TIME+3);
  90.      n:=random(5)+5;
  91.      for i:=1 to n do temp:=new(entityptr,Init(simulation.time,b[1]));
  92.      bodystore.Update(bodystore.value+n);
  93.      body_worker_box.Hide;
  94. end;
  95.  
  96. procedure body_worker_out;
  97. begin
  98.      simulation.thisentity^.ChangeTime(simulation.TIME+30);
  99.      body_worker.Timed_RotateZ(180,now,3);
  100.      body_worker.Timed_MoveTo(35,-300,0,now+3,27);
  101. end;
  102.  
  103. procedure body_worker_hide;
  104. begin
  105.      body_worker.RotateZ(180);
  106.      body_worker.Hide;
  107. end;
  108.  
  109. procedure shrink_body_store;
  110. begin
  111.      bodystore.update(bodystore.value-1);
  112. end;
  113.  
  114. procedure wheel_worker_in;
  115. begin
  116.      simulation.thisentity^.ChangeTime(simulation.TIME+30);
  117.      wheel_worker.Show;
  118.      wheel_worker_box.Show;
  119.      wheel_worker.Timed_MoveTo(85,-10,0,now,30);
  120. end;
  121.  
  122. procedure add_wheel_to_store;
  123. var n,i : integer;
  124.     temp : entityptr;
  125. begin
  126.      simulation.thisentity^.ChangeTime(simulation.TIME+3);
  127.      n:=(random(5)+5)*2;
  128.      for i:=1 to n do temp:=new(entityptr,Init(simulation.time,w[1]));
  129.      wheelstore.Update(wheelstore.value+n);
  130.      wheel_worker_box.Hide;
  131. end;
  132.  
  133. procedure wheel_worker_out;
  134. begin
  135.      simulation.thisentity^.ChangeTime(simulation.TIME+30);
  136.      wheel_worker.Timed_RotateZ(180,now,3);
  137.      wheel_worker.Timed_MoveTo(85,-300,0,now+3,27);
  138. end;
  139.  
  140. procedure wheel_worker_hide;
  141. begin
  142.      wheel_worker.RotateZ(180);
  143.      wheel_worker.Hide;
  144. end;
  145.  
  146. procedure shrink_wheel_store;
  147. begin
  148.      wheelstore.update(wheelstore.value-1);
  149. end;
  150.  
  151. procedure crate_to_worker;
  152. var temppic : object3d_ptr;
  153. begin
  154.      simulation.thisentity^.ChangeTime(simulation.TIME+5);
  155.      temppic:=simulation.thisentity^.picture;
  156.      temppic^.Timed_RotateZ_About(90,240,40,0,now,5);
  157. end;
  158.  
  159. procedure crate_worker_away;
  160. var t : real;
  161. begin
  162.      crate_worker.Timed_RotateZ(180,now,3);
  163.      t:=normal(50,10,0);
  164.      crate_worker.Timed_MoveTo(240,-1000,0,now+3,t);
  165.      simulation.thisentity^.ChangeTime(simulation.TIME+3+t);
  166. end;
  167.  
  168. procedure crate_worker_back;
  169. var t : real;
  170. begin
  171.      crate_worker.RotateZ(180);
  172.      t:=normal(50,10,0);
  173.      crate_worker.Timed_MoveTo(240,-3.5,0,now,t);
  174.      simulation.thisentity^.ChangeTime(simulation.TIME+t);
  175. end;
  176.  
  177. procedure start_spray;
  178. begin
  179.      paint_out:=0.1;
  180. end;
  181.  
  182. procedure stop_spray;
  183. begin
  184.      paint_out:=0;
  185. end;
  186.  
  187. procedure no_paint;
  188. begin
  189.      body_spray.first_resource_item^.screen_position^.busypic:=nil;
  190. end;
  191.  
  192. procedure paint_again;
  193. begin
  194.      body_spray.first_resource_item^.screen_position^.busypic:=@sprayb;
  195. end;
  196.  
  197. {$F-}
  198.  
  199.  
  200. begin
  201.      cyberm:=false;
  202.      mouse:=false;
  203.      if Cyberman_Available then
  204.      begin
  205.           writeln('Cyberman found');
  206.           cyberm:=true;
  207.      end
  208.      else
  209.      if mouse_available then
  210.      begin
  211.           writeln('Mouse found');
  212.           mouse:=true;
  213.      end;
  214.  
  215.      simulation.Init;
  216.      init_system;
  217.      set_for_swoop;
  218.  
  219.      graphics_time:=@simulation.time;
  220.  
  221.      Set_Ambient_Intensity(0.5);
  222.      Set_Light(0.75,0,-1,-0.75);
  223.      Set_View(-700,1500,350,119.5,-12,0);
  224.  
  225.      Store_Settings;
  226.  
  227.      Set_View(140,80,2000,-90,-90,0);
  228.  
  229.      Set_Window(-20,-15,20,15);
  230.  
  231.      User_KeyCheck_Proc(My_KeyCheck);
  232.  
  233.      simulation.Continuous(0.1,0.1,0,Calculate);
  234.      simulation.Integrate_Method(Euler);
  235.      simulation.Run_Time(Update_Screen);
  236.  
  237.      s1:=create(constant,0.1,0,0,1);
  238.      s2:=delay(constant,0.1,0,0);
  239.  
  240.      s1^.Link(s2);
  241.      s2^.Link(s2);
  242.  
  243.      manual_control:=false;
  244.      source_car1.Init('car1.3d');
  245.      source_car1.Set_Reference_Point(5.5,7.5,0);
  246.      source_car1.Hide;
  247.      source_car2.Init('car2.3d');
  248.      source_car2.Set_Reference_Point(5.5,2.5,0);
  249.      source_car2.Hide;
  250.      source_carbody.Init('carbody.3d');
  251.      source_carbody.Set_Reference_Point(0.725,1.8,0);
  252.      source_carbody.RotateZ(90);
  253.      source_carbody.Hide;
  254.      source_wheel1.Init('carw1.3d');
  255.      source_wheel1.Set_Reference_Point(-0.725,-1.5,0);
  256.      source_wheel1.Hide;
  257.      source_wheel2.Init('carw2.3d');
  258.      source_wheel2.Set_Reference_Point(-0.725,-1.5,0);
  259.      source_wheel2.Hide;
  260.      source_carwheel.Init('carwheel.3d');
  261.      source_carwheel.Set_Reference_Point(0.725,1.5,0);
  262.      source_carwheel.RotateZ(90);
  263.      source_carwheel.Hide;
  264.      source_box.Init('box.3d');
  265.      source_box.Set_Reference_Point(5,5,0);
  266.      source_box.Change_Colour(5,1);
  267.      source_box.Scale(0.5,0.5,0.5);
  268.      source_box.Hide;
  269.  
  270.      body_stampb.Init('Hex1.3d');
  271.      body_stampb.Scale(2,2,2);
  272.      body_stampb.RotateX(-90);
  273.  
  274.      wheel_stampb.Init('Hex1.3d');
  275.      wheel_stampb.Scale(1.5,1.5,1.5);
  276.      wheel_stampb.RotateX(-90);
  277.  
  278.      armb.Init('Arm.3d');
  279.      armb.Scale(0.8,0.8,0.8);
  280.      armb.RotateZ(90);
  281.  
  282.      bodyslicemach.Set_Capacity(1);
  283.      wheelslicemach.Set_Capacity(1);
  284.      body_stamp.Set_Capacity(1);
  285.      body_stamp.Add_Position(90,155,40,@body_stampb,@body_stampb);
  286.      sprayb.Init('spray.3d');
  287.      body_stamp.Add_Seize_Procedure(body_stamp_proc);
  288.      body_spray.Set_Capacity(1);
  289.      body_spray.Add_Position(135,160,2.5,nil,@sprayb);
  290.      body_here.Set_Capacity(0);
  291.      arm.Set_Capacity(1);
  292.      arm.Add_Position(165,135,-25,@armb,@armb);
  293.      arm.Add_Seize_Procedure(seize_arm_proc);
  294.      wheel_stamp.Set_Capacity(1);
  295.      wheel_stamp.Add_Position(115,115,40,@wheel_stampb,@wheel_stampb);
  296.      wheel_stamp.Add_Seize_Procedure(wheel_stamp_proc);
  297.      wheel_here.Set_Capacity(1);
  298.      worker.Set_Capacity(1);
  299.  
  300.      boxslicemachpic.Init('box.3d');
  301.      boxslicemachpic.Set_Reference_Point(5,5,0);
  302.      boxslicemachpic.Scale(1.7,1.5,1);
  303.      boxslicemachpic.Change_Colour(10,1);
  304.      boxslicemachpic.MoveTo(35,100,-0.1);
  305.  
  306.      wheelslicemachpic.Init('box.3d');
  307.      wheelslicemachpic.Set_Reference_Point(5,5,0);
  308.      wheelslicemachpic.Scale(0.5,0.7,0.5);
  309.      wheelslicemachpic.Change_Colour(10,1);
  310.      wheelslicemachpic.MoveTo(85,80,-0.1);
  311.  
  312.      cratingpic.Init('box.3d');
  313.      cratingpic.Set_Reference_Point(5,5,0);
  314.      cratingpic.Change_Colour(12,1);
  315.      cratingpic.MoveTo(200,115,0);
  316.  
  317.      spraypic1.Init('box.3d');
  318.      spraypic1.Set_Reference_Point(5,5,0);
  319.      spraypic1.Change_Colour(9,1);
  320.      spraypic1.Scale(0.75,0.5,0.5);
  321.      spraypic1.MoveTo(135,162.5,0);
  322.  
  323.      spraypic2.Init('box.3d');
  324.      spraypic2.Set_Reference_Point(5,5,0);
  325.      spraypic2.Change_Colour(9,1);
  326.      spraypic2.Scale(0.75,0.5,0.5);
  327.      spraypic2.MoveTo(135,147.5,0);
  328.  
  329.      body_worker.Init('worker.3d');
  330.      body_worker.Set_Reference_Point(-1,0,6);
  331.      body_worker.MoveTo(35,-300,0);
  332.      body_worker.RotateZ(90);
  333.      body_worker.Hide;
  334.      body_worker_box.Init('Box.3d');
  335.      body_worker_box.Change_Colour(0,1);
  336.      body_worker_box.Set_Reference_Point(5,5,5);
  337.      body_worker_box.Scale(1.1,1.5,0.5);
  338.      body_worker.AddChild(@body_worker_box);
  339.      body_worker_box.MoveTo(35,-291.5,2.5);
  340.      body_worker_box.Hide;
  341.      wheel_worker.Init('worker.3d');
  342.      wheel_worker.Set_Reference_Point(-1,0,6);
  343.      wheel_worker.MoveTo(85,-300,0);
  344.      wheel_worker.RotateZ(90);
  345.      wheel_worker.Hide;
  346.      wheel_worker_box.Init('Box.3d');
  347.      wheel_worker_box.Change_Colour(4,1);
  348.      wheel_worker_box.Set_Reference_Point(5,5,5);
  349.      wheel_worker_box.Scale(0.15,0.3,0.2);
  350.      wheel_worker.AddChild(@wheel_worker_box);
  351.      wheel_worker_box.MoveTo(85,-296,2.5);
  352.      wheel_worker_box.Hide;
  353.      crate_worker.Init('worker.3d');
  354.      crate_worker.Set_Reference_Point(-1,0,6);
  355.      crate_worker.MoveTo(240,-3.5,0);
  356.      crate_worker.RotateZ(90);
  357.  
  358.  
  359.      bodystore.Init(0.5);
  360.      bodystore.Update(0);
  361.      wheelstore.Init(0.5);
  362.      wheelstore.Update(0);
  363.      paintstore.Init(1);
  364.      paintstore.Change_Colour(1,1);
  365.      paint.Initial_Value(10);
  366.      paint.dot:=0;
  367.      paint_out:=0;
  368.      paint_in:=0;
  369.      paintstore.Update(paint.state-1);
  370.      bodystore.moveTo(35,15,0);
  371.      wheelstore.moveto(85,15,0);
  372.      paintstore.Scale(0.5,0.5,1);
  373.      paintstore.moveto(135,180,0);
  374.  
  375.  
  376.      bw[1]:=create(uniform,60,120,0,1);
  377.      bw[2]:=userproc(body_worker_in);
  378.      bw[3]:=userproc(add_body_to_store);
  379.      bw[4]:=userproc(body_worker_out);
  380.      bw[5]:=userproc(body_worker_hide);
  381.      bw[6]:=delay(uniform,150,250,0);
  382.  
  383.      ww[1]:=create(uniform,0,60,0,1);
  384.      ww[2]:=userproc(wheel_worker_in);
  385.      ww[3]:=userproc(add_wheel_to_store);
  386.      ww[4]:=userproc(wheel_worker_out);
  387.      ww[5]:=userproc(wheel_worker_hide);
  388.      ww[6]:=delay(uniform,100,130,0);
  389.  
  390.  
  391.      b[1]:=seize(@bodyslicemach,infinity,1);
  392.      b[2]:=userproc(shrink_body_store);
  393.      b[3]:=copy_picture3d(@source_car1);
  394.      b[4]:=route3d(constant,5,0,0,35,37.5,0,35,100,0);
  395.      b[5]:=destroy_picture3d;
  396.      b[6]:=delay(constant,5,0,0);
  397.      b[7]:=replicate;
  398.      b[8]:=delay(constant,5,0,0);
  399.      b[9]:=replicate;
  400.      b[10]:=delay(constant,5,0,0);
  401.      b[11]:=release(@bodyslicemach);
  402.      b[12]:=copy_picture3d(@source_car2);
  403.      b[13]:=route3d(constant,5,0,0,35,100,0,35,155,0);
  404.      b[14]:=route3d(constant,4,0,0,35,155,0,70,155,0);
  405.      b[15]:=drawn_seize3d(@body_stamp,infinity,1,70,155,0,70,255,0);
  406.      b[16]:=route3d(constant,2.5,0,0,70,155,0,90,155,0);
  407.      b[17]:=destroy_picture3d;
  408.      b[18]:=copy_picture3d(@source_carbody);
  409.      b[19]:=route3d(constant,2.5,0,0,90,155,0,120,155,0);
  410.      b[20]:=release(@body_stamp);
  411.      b[21]:=drawn_seize3d(@body_spray,infinity,1,120,155,0,120,255,0);
  412.      b[22]:=userproc(start_spray);
  413.      b[23]:=route3d(constant,2.5,0,0,120,155,0,135,155,0);
  414.      b[24]:=change_picture3d_colour(1,1);
  415.      b[25]:=route3d(constant,5,0,0,135,155,0,165,155,0);
  416.      b[26]:=release(@body_spray);
  417.      b[27]:=userproc(stop_spray);
  418.      b[28]:=drawn_seize3d(@body_here,infinity,1,165,155,0,165,255,0);
  419.      b[29]:=decrease_capacity(@body_here);
  420.      b[30]:=seize(@arm,infinity,1);
  421.      b[31]:=delay(constant,2,0,0);
  422.      b[32]:=translate_picture3d(0,0,0.6);
  423.      b[33]:=Add_As_Child_To(@armb);
  424.      b[34]:=delay(constant,2,0,0);
  425.      b[35]:=Remove_As_Child_From(@armb);
  426.      b[36]:=release(@arm);
  427.      b[37]:=release(@body_here);
  428.  
  429.      w[1]:=seize(@wheelslicemach,infinity,1);
  430.      w[2]:=userproc(shrink_wheel_store);
  431.      w[3]:=copy_picture3d(@source_wheel1);
  432.      w[4]:=route3d(constant,5,0,0,85,37.5,0,85,80,0);
  433.      w[5]:=destroy_picture3d;
  434.      w[6]:=delay(constant,5,0,0);
  435.      w[7]:=copy_picture3d(@source_wheel2);
  436.      w[8]:=release(@wheelslicemach);
  437.      w[9]:=userproc(wheel_to_stamp);
  438.      w[10]:=drawn_seize3d(@wheel_stamp,infinity,1,105,115,0,105,15,0);
  439.      w[11]:=route3d(constant,2,0,0,105,115,0,115,115,0);
  440.      w[12]:=destroy_picture3d;
  441.      w[13]:=copy_picture3d(@source_carwheel);
  442.      w[14]:=route3d(constant,2,0,0,115,115,0,125,115,0);
  443.      w[15]:=release(@wheel_stamp);
  444.      w[16]:=route3d(constant,5,0,0,125,115,0,150,115,0);
  445.      w[17]:=drawn_seize3d(@wheel_here,infinity,1,150,115,0,150,15,0);
  446.      w[18]:=route3d(constant,5,0,0,150,115,0,165,115,0);
  447.      w[19]:=increase_capacity(@body_here);
  448.      w[20]:=group3d;
  449.      w[21]:=route3d(constant,2,0,0,165,115,0,180,115,0);
  450.      w[22]:=release(@wheel_here);
  451.      w[23]:=route3d(constant,5,0,0,180,115,0,200,115,0);
  452.      w[24]:=split3d;
  453.      w[25]:=destroy_picture3d;
  454.      w[26]:=group;
  455.      w[27]:=group;
  456.      w[28]:=group;
  457.      w[29]:=split;
  458.      w[30]:=split;
  459.      w[31]:=split;
  460.      w[32]:=split;
  461.      w[33]:=split;
  462.      w[34]:=split;
  463.      w[35]:=split;
  464.      w[36]:=copy_picture3d(@source_box);
  465.      w[37]:=route3d(constant,5,0,0,200,115,0,200,40,0);
  466.      w[38]:=userproc(crate_to_worker);
  467.      w[39]:=drawn_seize3d(@worker,infinity,1,240,0,0,240,150,0);
  468.      w[40]:=Add_As_Child_To(@crate_worker);
  469.      w[41]:=userproc(crate_worker_away);
  470.      w[42]:=Remove_As_Child_From(@crate_worker);
  471.      w[43]:=destroy_picture3d;
  472.      w[44]:=userproc(crate_worker_back);
  473.      w[45]:=release(@worker);
  474.  
  475.      p[1]:=create(constant,0,0,0,1);
  476.      p[2]:=delay_until(@paint.state,lt,0.8,0.1,2);
  477.      p[3]:=decrease_capacity(@body_spray);
  478.      p[4]:=delay_until(@paint.state,gt,5,0.1,2);
  479.      p[5]:=increase_capacity(@body_spray);
  480.  
  481.      dw:=destroy_picture3d;
  482.  
  483.      for i:=1 to 36 do b[i]^.Link(b[i+1]);
  484.      for i:=1 to 44 do w[i]^.Link(w[i+1]);
  485.      for i:=1 to 5 do bw[i]^.Link(bw[i+1]);
  486.      for i:=1 to 5 do ww[i]^.Link(ww[i+1]);
  487.      for i:=1 to 4 do p[i]^.Link(p[i+1]);
  488.  
  489.      b[7]^.Link2(b[12]);
  490.      b[9]^.Link2(b[12]);
  491.      w[24]^.Link2(dw);
  492.      b[37]^.Link(w[20]);
  493.      bw[6]^.Link(bw[2]);
  494.      ww[6]^.Link(ww[2]);
  495.      p[5]^.Link(p[1]);
  496.  
  497.      Redraw_Scene;
  498.  
  499.      simulation.Execute(10000);
  500.  
  501.      stop_graphics;
  502.  
  503.      writeln('Simulation finished');
  504.  
  505. end.
  506.  
  507.