home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Raytracing / Raytracer / LW5VT09.LHA / Toaster / Arexx_examples / lwm / Rot&DistGen.lwm < prev    next >
Encoding:
Text File  |  1996-06-10  |  7.8 KB  |  248 lines

  1. /* CMD: Rotation & Distance Generator         
  2.  
  3.    Co-Authors  : Scott Wheeler 
  4.                  Joe Dox
  5.  
  6.    Date           : November 22nd 1994
  7.  
  8.    Description : 1) Calculates the rotation of an object nessasary to simulate 
  9.                     that object traveling at a user definable speed.  
  10.                  
  11.                  2) If desired it will then create a series of motion paths for 
  12.                     that object.
  13. */
  14.  
  15. libadd = addlib("LWModelerARexx.port",0)
  16. signal on error
  17. signal on syntax
  18.  
  19. call addlib "rexxsupport.library", 0, -30, 0
  20. MATHLIB="rexxmathlib.library"
  21. IF POS(MATHLIB , SHOW('L')) = 0 THEN
  22.   IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
  23.     call notify(1,"!Can't find "MATHLIB)
  24.     exit
  25.     END
  26.  
  27.                     /* Priming variables */
  28. procname           = 'Rotation & Distance Generator v1.0 © 1994 GVASoft'
  29. procname2          = 'Rotation & Distance Generator'
  30. FramesInAnim       = 30
  31. SpeedOfVehicle     = 60.0
  32. RadiusOfWheel      = 30.0
  33. TireCircumference  = 0.0
  34. InchesPerSecond    = 0.0
  35. DistanceTraveled   = 0.0
  36. NumberOfRotations  = 0.0
  37. MovementAxis       = 0
  38. RotationField      = 0
  39. AxisOffset         = 0
  40. MeasurementSystem  = 0
  41. CombinedMotionSave = 0
  42. VehicleMotionSave  = 0
  43. TireMotionSave     = 0 
  44.  
  45. call req_begin procname
  46.  
  47. id_MeasurementSystem  = req_addcontrol('Desired Measurement System','ch','Metric English') 
  48. id_TireMotionSave     = req_addcontrol('Save Seperate Tire Motion?','b',0) 
  49. id_VehicleMotionSave  = req_addcontrol('Save Seperate Vehicle Motion?','b',0) 
  50. id_CombinedMotionSave = req_addcontrol('Save Combined Motion?','b',0) 
  51. call req_setval id_MeasurementSystem, 1
  52. call req_setval id_TireMotionSave, 1 
  53. call req_setval id_VehicleMotionSave, 1 
  54. call CheckCANCEL()
  55.  
  56. MeasurementSystem  = req_getval(id_MeasurementSystem)
  57. CombinedMotionSave = req_getval(id_CombinedMotionSave)
  58. VehicleMotionSave  = req_getval(id_VehicleMotionSave)
  59. TireMotionSave     = req_getval(id_TireMotionSave)
  60. call req_end
  61.  
  62. call req_begin procname2
  63.                     /* Designing window 1 */
  64. if MeasurementSystem = 1 then do    /* Setup Metric controls */
  65.  Distance = 'meters'
  66.  id_radius = req_addcontrol("Radius of Tire (m)", 'n', 0)
  67.  id_speed = req_addcontrol('Speed of Vehicle (kph)','n',0)
  68.  id_frames = req_addcontrol('Frames In Animation','n',0)
  69.  end
  70. else do                    /* Setup English controls */
  71.  Distance = 'feet'
  72.  id_radius = req_addcontrol("Radius of Tire (inches)", 'n', 0)
  73.  id_speed = req_addcontrol('Speed of Vehicle (mph)','n',0)
  74.  id_frames = req_addcontrol('Frames In Animation','n',0)
  75. end 
  76.  
  77.  
  78.                     /* Setting Values from Imput Gadgets */
  79.  
  80. Box = BOUNDINGBOX()
  81. Parse Var Box np x1 x2 y1 y2 z1 z2
  82. RadiusOfWheel = MAX( abs(x1), abs(x2), abs(y1), abs(y2), abs(z1), abs(z2) )
  83. if MeasurementSystem = 2 then RadiusOfWheel = RadiusOfWheel * 39.37  
  84. if ( RadiusOfWheel = 0 ) then RadiusOfWheel = 1
  85. call req_setval id_radius, RadiusOfWheel, RadiusOfWheel
  86. call req_setval id_speed, SpeedOfVehicle, SpeedOfVehicle
  87. call req_setval id_frames, FramesInAnim, FramesInAnim
  88. call CheckCANCEL()
  89.  
  90.                     /* Getting Values back from Gadgets */
  91. RadiusOfTire      = req_getval(id_radius)
  92. SpeedOfVehicle    = req_getval(id_speed)
  93. FramesInAnim      = req_getval(id_frames)
  94.  
  95.  
  96.                     /* Doing the Math */
  97. if MeasurementSystem = 1 then do
  98.  SpeedType="kph"
  99.  TireCircumference = RadiusOfTire*(2*3.141592654)
  100.  MetersPerSecond   = (SpeedOfVehicle/3600)*1000.0
  101.  DistanceTraveled  = MetersPerSecond*(FramesInAnim/30.0)
  102.  NumberOfRotations = (DistanceTraveled/TireCircumference)*360.0
  103.  end
  104. else do
  105.  SpeedType="mph"
  106.  TireCircumference = RadiusOfTire*(2*3.141592654) 
  107.  InchesPerSecond   = ((SpeedOfVehicle/3600)*5280)*12.0
  108.  DistanceTraveled  = InchesPerSecond*(FramesInAnim/30.0)
  109.  NumberOfRotations = (DistanceTraveled/TireCircumference)*360.0
  110.  DistanceTraveled  = DistanceTraveled/12.0
  111. end
  112.  
  113.  
  114.                     /* Cleaning up variables for output */
  115. FramesInAnim       = TRUNC(FramesInAnim)
  116. DistanceTraveled  = TRUNC(DistanceTraveled,2)
  117. NumberOfRotations = TRUNC(NumberOfRotations,2)
  118.  
  119.                     /* Closing first window */
  120. call req_end                
  121.  
  122. if ( MeasurementSystem = 1 ) then do            
  123.  ok=Notify(1,'@Your vehicle will travel 'DistanceTraveled' 'Distance' ('TRUNC((DistanceTraveled*39.37)/12,2)' feet) in 'FramesInAnim' frames.','@The wheels should rotate 'NumberOfRotations'°.')
  124.  end
  125. else do
  126.  ok=Notify(1,'@Your vehicle will travel 'DistanceTraveled' 'Distance' ('TRUNC((DistanceTraveled*12)/39.37,2)' meters) in 'FramesInAnim' frames.','@The wheels should rotate 'NumberOfRotations'°.')
  127. end
  128.                     /* Saving Combined Motion File */
  129. if (CombinedMotionSave = 1)  then do
  130.  call req_begin 'Define Combined Movement Axis and Rotation Field'
  131.  
  132.  id_axis = req_addcontrol('What axis will wheel travel on: ','ch','X Y Z')
  133.  id_rotation = req_addcontrol('What is the field of rotation: ','ch','H P B')
  134.  id_offset = req_addcontrol('Starting position offset (m): ','n',0)
  135.  
  136.  call req_setval id_axis, 3
  137.  call req_setval id_rotation, 2
  138.  call req_setval id_offset, 0
  139.  call CheckCANCEL()
  140.  
  141.  MovementAxis  = req_getval(id_axis)
  142.  RotationField = req_getval(id_rotation)
  143.  AxisOffset    = TRUNC(req_getval(id_offset),2)
  144.  
  145.  call req_end
  146.  ReqName    = "Save Combined Motion File"
  147.  MotionType = "ComdinedMotion"
  148.  call SaveMotion()
  149. end
  150.  
  151.                     /* Saving Vehicle Motion File */
  152. if (VehicleMotionSave = 1) then do
  153.  call req_begin 'Define Vehicle Movement Axis'
  154.  
  155.  id_axis = req_addcontrol('What axis will wheel travel on: ','ch','X Y Z')
  156.  id_offset = req_addcontrol('Starting position offset (m): ','n',0)
  157.  
  158.  call req_setval id_axis, 3
  159.  call req_setval id_offset, 0
  160.  call CheckCANCEL()
  161.  
  162.  MovementAxis      = req_getval(id_axis)
  163.  RotationField     = 1
  164.  NumRots           = NumberOfRotations        
  165.  NumberOfRotations = 0.0
  166.  AxisOffset        = TRUNC(req_getval(id_offset),2)
  167.  
  168.  call req_end
  169.  ReqName           = "Save Vehicle Motion File"
  170.  MotionType        = "VehicleMotion"
  171.  call SaveMotion()
  172. end
  173.  
  174.                     /* Saving Tire Motion File */
  175. if (TireMotionSave = 1) then do
  176.  call req_begin 'Define Tire Rotation Field'
  177.  
  178.  id_rotation = req_addcontrol('What is the field of rotation: ','ch','H P B')
  179.  call req_setval id_rotation, 2
  180.  call CheckCANCEL()
  181.  
  182.  NumberOfRotations = NumRots
  183.  RotationField     = req_getval(id_rotation)
  184.  MovementAxis      = 1
  185.  AxisOffset        = 0.0
  186.  DistanceTraveled  = 0.0
  187.  
  188.  call req_end
  189.  ReqName    = "Save Tire Motion File"
  190.  MotionType = "WheelMotion"
  191.  call SaveMotion()
  192. end
  193.  
  194.  
  195. EXIT                    /* End of Line */
  196.  
  197.  
  198. SaveMotion:
  199.  fname=GETFILENAME(ReqName,'motions',MotionType'.'TRUNC(SpeedOfVehicle,0)SpeedType)
  200.  if ( fname = '(none)' ) then exit
  201.  if ( open(outfile, fname, 'W')) then do
  202.   call Header()
  203.   call VehicleMovement()
  204.   call Rotation()
  205.   call Footer()
  206.  end
  207. return
  208.  
  209.  
  210. Header:
  211.   call writeln outfile, 'LWMO'
  212.   call writeln outfile, '1'
  213.   call writeln outfile, '9'
  214.   call writeln outfile, '2'
  215. return
  216.  
  217.  
  218. VehicleMovement:
  219.  if ( MovementAxis = 1 ) then call writeln outfile, AxisOffset' 0.0 0.0 0.0 0.0 0.0 1.0 1.0 1.0'
  220.  if ( MovementAxis = 2 ) then call writeln outfile, '0.0 'AxisOffset' 0.0 0.0 0.0 0.0 1.0 1.0 1.0'
  221.  if ( MovementAxis = 3 ) then call writeln outfile, '0.0 0.0 'AxisOffset' 0.0 0.0 0.0 1.0 1.0 1.0'
  222.  call writeln outfile, '0 0 0.0 0.0 0.0'
  223.  if ( MovementAxis = 1 ) then call writech outfile, DistanceTraveled+AxisOffset' 0.0 0.0 '
  224.  if ( MovementAxis = 2 ) then call writech outfile, '0.0 'DistanceTraveled+AxisOffset' 0.0 '
  225.  if ( MovementAxis = 3 ) then call writech outfile, '0.0 0.0 'DistanceTraveled+AxisOffset' '
  226. return
  227.  
  228.  
  229. Rotation:
  230.   if ( RotationField = 1 ) then call writech outfile, NumberOfRotations' 0.0 0.0 '
  231.   if ( RotationField = 2 ) then call writech outfile, '0.0 'NumberOfRotations' 0.0 '
  232.   if ( RotationField = 3 ) then call writech outfile, '0.0 0.0 'NumberOfRotations' '
  233. return
  234.  
  235.  
  236. Footer:
  237.   call writeln outfile, '1.0 1.0 1.0'
  238.   call writeln outfile, FramesInAnim' 0 0.0 0.0 0.0'
  239.   call close outfile 
  240. Return
  241.  
  242. CheckCANCEL:                /* Check for cancel out */
  243.  if (~req_post()) then do        
  244.     call req_end 
  245.     ok=Notify(1,'@'procname2,'','A Product of GVASoft International Ltd.','All Rights Reserved')
  246.     exit
  247.  end
  248. return