home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / GFX / Raytracing / Raytracer / LightWave.lha / Lightwave / Toaster / Arexx_Examples / lwm / GrassMaker.lwm < prev    next >
Encoding:
Text File  |  1994-08-20  |  4.6 KB  |  209 lines

  1. /* 
  2. ** CMD: Grass Maker
  3. ** 
  4. ** $VER: GrassMaker.lwm v1.2 (August 4,1994)
  5. **
  6. **
  7. ** DESCRIPTION:
  8. ** This Modeler macro creates a rectangular object consist-
  9. ** ing of an array of 2D particles (2-point polygons) 
  10. ** resembling grass (or fibers,carpet,hair,etc.).
  11. **
  12. ** AUTHOR:
  13. ** William Frawley, © 1994 Ecliptic Arts
  14. **
  15. ***********************************************************/
  16.  
  17. /*
  18. ** Initialize System
  19. */
  20.  
  21. address "LWModelerARexx.port"
  22. call addlib "LWModelerARexx.port", 0
  23.  
  24. /* call addlib "rexxsupport.library", 0, -30, 0 */
  25. /* call addlib "rexxmathlib.library", 0, -30, 0 */
  26.  
  27. SIGNAL ON ERROR
  28. SIGNAL ON SYNTAX
  29.  
  30.  
  31.  
  32. /*
  33. ** Initialize Variables
  34. */
  35.  
  36. JList='NONE Tops_Only ALL'
  37. JRange='Low Medium High'
  38. Text1='If intended as "Image Modulator",'
  39. Text2='Width & Depth ratio should be set'
  40. Text3='for a video aspect of 1.342 to 1.'
  41.  
  42.  
  43. /*
  44. ** Configure Requester
  45. */
  46.  
  47. CALL req_begin("Bill's Grass Maker v1.1")
  48.  
  49. id_W = req_addcontrol('Terrain Width', 'n', 1)
  50. id_D = req_addcontrol('Terrain Depth', 'n', 1)
  51. id_H = req_addcontrol('Blade Height', 'n', 1)
  52. id_Seg = req_addcontrol('# of Blade Segments', 'n', 1)
  53. id_Space = req_addcontrol('Blade Spacing', 'n', 1)
  54. id_Jitter = req_addcontrol('Jitter', 'CH', JList)
  55. id_JS = req_addcontrol('Jitter Strength', 'CH', JRange)
  56. id_Center = req_addcontrol('Center?', 'B')
  57. id_NoteA = req_addcontrol(' ', 'T', ' ')
  58. id_NoteB = req_addcontrol('NOTE:', 'T', Text1)
  59. id_NoteC = req_addcontrol(' ', 'T', Text2)
  60. id_NoteD = req_addcontrol(' ', 'T', Text3)
  61. id_NoteE = req_addcontrol(' ', 'T', ' ')
  62.  
  63. CALL req_setval(id_W, 13.42)
  64. CALL req_setval(id_D, 10)
  65. CALL req_setval(id_H, .3)
  66. CALL req_setval(id_Seg, 1)
  67. CALL req_setval(id_Space, .1)
  68. CALL req_setval(id_Jitter, 1)
  69. CALL req_setval(id_JS, 2)
  70. CALL req_setval(id_Center, 1)
  71.  
  72.  
  73. /*
  74. ** Post Requester
  75. */
  76.  
  77. IF (~req_post()) THEN DO
  78.   CALL req_end
  79.   EXIT(5)
  80.   END
  81.  
  82. req=1
  83.  
  84.  
  85. /*
  86. ** Get Input From Requester
  87. */
  88.  
  89. Width = req_getval(id_W)
  90. Depth = req_getval(id_D)
  91. Height = req_getval(id_H)
  92. Segments = req_getval(id_Seg)
  93. Spacing = req_getval(id_Space)
  94. Jit = req_getval(id_Jitter)
  95. JStren = req_getval(id_JS)
  96. Center = req_getval(id_Center)
  97.  
  98. CALL req_end()                      /* End Requester mode */
  99.  
  100.  
  101. /*
  102. ** Make Array Of Blades
  103. */
  104.  
  105. SegH=Height/Segments            /* Height of each segment */
  106. Ops=((Width/Spacing)+1)*((Depth/Spacing)+1)%1  /* # loops */
  107. IF Ops>32124 THEN Ops=32124   /* ~Max# steps meter allows */
  108.  
  109. CALL add_begin()              /* Enter Data Creation mode */
  110. CALL meter_begin(ops,'Building Blade Array','Please Wait..')
  111.  
  112. DO z=0 TO Depth BY Spacing                        /* Rows */
  113.   DO x=0 TO Width BY Spacing                   /* Columns */
  114.     DO y=0 TO Segments-1                /* Blade segments */
  115.       PtIndex.1=add_point(x (y*SegH) z)
  116.       PtIndex.2=add_point(x ((y+1)*SegH) z)
  117.       CALL add_polygon(PtIndex.1 PtIndex.2)  /* Make Line */
  118.     END                                         
  119.   CALL meter_step()       /* Step progress meter by 1/ops */
  120.   END                                           
  121. END                                             
  122.  
  123. CALL meter_end()                      /* Deactivate meter */
  124. CALL add_end()                  /* End Data Creation mode */
  125.                                                 
  126. CALL mergepoints()              /* Merge common points of */
  127.                                 /* multi-segmented blades */
  128.                                 
  129. /*
  130. ** Jitter Blades?
  131. */
  132.  
  133. IF Jit=2 | Jit=3 THEN DO               /* Jitter Routines */
  134.  
  135.   IF Jit=2 THEN DO              /* Select top points only */
  136.     CALL sel_mode(USER)
  137.     xL=0-Spacing/2
  138.     yL=Height-SegH/2
  139.     zL=0-Spacing/2
  140.     xR=Width+Spacing/2
  141.     yR=Height+SegH/2
  142.     zR=Depth+Spacing/2
  143.     CALL sel_point(SET,VOLUME, xL yL zL , xR yR zR)
  144.     END
  145.   
  146.   IF JStren=1 THEN DO
  147.     jxz = (Spacing * .5)
  148.     jy = (Spacing * .15)
  149.     END
  150.  
  151.   IF JStren=2 THEN DO
  152.     jxz = (Spacing * 1)
  153.     jy = (Spacing * .3)
  154.     END
  155.         
  156.   IF JStren=3 THEN DO
  157.     jxz = (Spacing * 1.5)
  158.     jy = (Spacing * .45)
  159.     END
  160.  
  161.   CALL jitter(jxz jy jxz)
  162.  
  163.   IF Jit=2 THEN DO
  164.     CALL sel_point(CLEAR)          /* Unselect all points */
  165.     CALL end_all()      /* Reset Selection mode to Global */
  166.     END
  167.     
  168.   END                                  /* End Jit=2|Jit=3 */
  169.  
  170.  
  171. /*
  172. ** Center On XZ Plane?
  173. */
  174.  
  175. IF Center=1 THEN DO
  176.   Box=boundingbox()   /* Returns bounding box information */
  177.   PARSE VAR Box n xL xR yL yR zL zR    /* n= no.of points */
  178.   cx=-(xR+xL)/2
  179.   cz=-(zR+zL)/2
  180.   CALL move(cx 0 cz)
  181.   END
  182.  
  183.  
  184. /*
  185. ** Wrap It Up
  186. */
  187.  
  188. CALL changesurface("Grass")
  189.  
  190. CALL notify(1,'!Done!', 'Time to water the lawn...')
  191.  
  192. EXIT(0)
  193.  
  194.  
  195. /*
  196. ** INTERNAL FUNCTIONS
  197. */
  198.  
  199. SYNTAX:
  200.  
  201. ERROR:
  202.  
  203.   T1='!Total Bummer Dude!'
  204.   T2='!An error has been detected.'
  205.   t=notify(1,T1,T2,'@'ErrorText(rc),'Line 'SIGL)
  206.  
  207.   IF req THEN CALL req_end()
  208.  
  209.   EXIT(20)