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

  1. /* CMD: ½CreateCone                                                     */
  2. /* By Brett Evan Hester      13032 Copenhill Rd. Dallas, Tx. 75240-5302 */
  3.     MacrosName = "CreateCone"
  4. /* Macro Type:                                                          */
  5. /* CREATES     * OBJECTS   * LAYER NEEDED * REMEMBERS                   */
  6. /* Description:                                                         */
  7.  
  8. Info1A = "!Create Cone Angle ©           Information 1 of 2"
  9. Info1B = ""
  10. Info1C = "@This macro creates cones, given a source point, "
  11. Info1D = "@angle, and depth. This is the format used in the"
  12. Info1E = "@layout area when adding and modifing lights.    "
  13. Info1F = ""
  14. Info1G = "þ SOURCE POINT is the location of the cones tip."
  15. Info1H = "þ CONE ANGLE is half of the entire cone angle.  "
  16. Info1I = "þ CONE DEPTH is from the cone's base to the tip."
  17. Info1J = "þ NUMBER OF SIDES is the smoothness of the cone."
  18. Info1K = "þ NUMBER OF SEGMENTS are breaks from base to tip"
  19. Info1L = "þ ROTATION rotates the cone upon completion. The"
  20. Info1M = "¤ cone must be created on a empty layer or have "
  21. Info1N = "¤ a empty layer available for this process.     "
  22.  
  23. Info2A = "!Create Cone Angle ©           Information 2 of 2"
  24. Info2B = "@               Plug-Ins and Go! ©               "
  25. Info2C = "                           Hester and associates"
  26. Info2D = "                           13032 Copenhill Road "
  27. Info2E = "                           Dallas, Texas 75240  "
  28. Info2F = "@Special Thanks to:                              "
  29. Info2G = "Arnie Cachelin  Henry Ribron    Mark J. Holland "
  30. Info2H = "J. Phil Kelso   Terry Wester    Steven K. Simms "
  31. Info2I = "Kevin DeRita    Greg Glaser     William S. Hawes"
  32. Info2J = "NewTek ©        Commodore ©     INOVAtronics ©  "
  33. Info2K = ""
  34. Info2L = "@This macro represents a lot of time & hard work."
  35. Info2M = "@Encourage people to create new ones and not kill"
  36. Info2N = "@that possibility by stealing those that are out."
  37.  
  38. /* -------------------------------------------------------------------- */
  39.                                      /* Start Error Detection (See End) */
  40. SIGNAL ON ERROR
  41. SIGNAL ON SYNTAX
  42.                                                    /* Address LightWave */
  43. VT3DLib = ADDLIB("LWModelerARexx.port",0)
  44. ADDRESS "LWModelerARexx.port"
  45.                                                   /* Add Math Functions */
  46. MATHLIB="rexxmathlib.library"
  47. IF POS(MATHLIB , SHOW('L')) = 0 THEN
  48.     IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
  49.         CALL notify(1,"!Can't find "MATHLIB)
  50.         EXIT
  51.     END
  52.  
  53. /* -------------------------------------------------------------------- */
  54.                                     /* Reading Global Macro Preferences */
  55. BEHDefaultFilePath = "Sys:"
  56. BEHSettingsSavedTo = "T:"
  57. BEHSpeechAndSound = "1"
  58.  
  59. IF (EXISTS("S:PlugInPrefs")) THEN DO
  60.     IF (~OPEN(PlugInPrefs, "S:PlugInPrefs", 'R')) THEN BREAK
  61.     IF (READLN(PlugInPrefs) ~= "PlugInPrefs") THEN BREAK
  62.     BEHDefaultFilePath = READLN(PlugInPrefs)
  63.     BEHSettingsSavedTo = READLN(PlugInPrefs)
  64.     BEHSpeechAndSound = READLN(PlugInPrefs)
  65.     CALL CLOSE PlugInPrefs
  66. END
  67.  
  68. /* -------------------------------------------------------------------- */
  69.                                             /* Recalling Macro Settings */
  70. ReqSource = 0 0 0
  71. ReqAngle = 30
  72. ReqDepth = 1
  73. ReqSides = 20
  74. ReqSegs = 1
  75. ReqHPB = 0 0 0
  76.  
  77. PrefsFileName = BEHSettingsSavedTo||MacrosName||".PLUG"
  78.  
  79. IF (EXISTS(PrefsFileName)) THEN DO
  80.     IF (~OPEN(PrefsFile, PrefsFileName, 'R')) THEN BREAK
  81.     IF (READLN(PrefsFile) ~= MacrosName) THEN BREAK
  82.  
  83.     ReqSource = READLN(PrefsFile)
  84.     ReqAngle = READLN(PrefsFile)
  85.     ReqDepth = READLN(PrefsFile)
  86.     ReqSides = READLN(PrefsFile)
  87.     ReqSegs = READLN(PrefsFile)
  88.     ReqHPB = READLN(PrefsFile)
  89.  
  90.     CALL CLOSE PrefsFile
  91. END
  92.  
  93. /* -------------------------------------------------------------------- */
  94.                                               /* For Information Window */
  95. BEHInfo = 1
  96.                       /* For Coming Back to Main Menu after Info Window */
  97. DO WHILE BEHInfo
  98.  
  99. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  */
  100.                                                       /* User Interface */
  101.     CALL Req_Begin("Create Cone Angle ©                 By Brett Hester")
  102.  
  103.     ReqA = Req_AddControl("Source Point",'v',1)
  104.     ReqB = Req_AddControl("Cone Angle",'N',0)
  105.     ReqC = Req_AddControl("Cone Depth",'N',1)
  106.     ReqD = Req_AddControl("Number of Sides",'N',0)
  107.     ReqE = Req_AddControl("Number of Segments",'N',0)
  108.     ReqF = Req_AddControl("Rotation (H P B)",'v',0)
  109.     CALL Req_AddControl("",'T', "")
  110.     ReqG = Req_AddControl("",'CH', "Information")
  111.  
  112.     CALL Req_SetVal(ReqA, ReqSource)
  113.     CALL Req_SetVal(ReqB, ReqAngle)
  114.     CALL Req_SetVal(ReqC, ReqDepth)
  115.     CALL Req_SetVal(ReqD, ReqSides)
  116.     CALL Req_SetVal(ReqE, ReqSegs)
  117.     CALL Req_SetVal(ReqF, ReqHPB)
  118.     CALL Req_SetVal(ReqG, 0)
  119.  
  120.     IF Req_Post() = 0 THEN CALL Exiting
  121.  
  122.     PARSE VALUE Req_GetVal(ReqA) WITH ReqSPntX ReqSPntY ReqSPntZ
  123.     ReqAngle = Req_GetVal(ReqB)
  124.     ReqDepth = Req_GetVal(ReqC)
  125.     ReqSides = Req_GetVal(ReqD)
  126.     ReqSegs = Req_GetVal(ReqE)
  127.     PARSE VALUE Req_GetVal(ReqF) WITH ReqRotH ReqRotP ReqRotB
  128.     BEHInfo = Req_GetVal(ReqG)
  129.  
  130.     CALL Req_End()
  131.  
  132.     ReqSides = TRUNC(ABS(ReqSides))
  133.     ReqSegs = TRUNC(ABS(ReqSegs))
  134.  
  135.     IF BEHInfo = 1 THEN CALL InformationWindows
  136.  
  137. END
  138.  
  139. /* -------------------------------------------------------------------- */
  140.                                              /* Setting Fixed Variables */
  141. PI = 3.141592653589793238462643
  142. RadToDeg = 180 / PI
  143. DegToRad = PI / 180
  144.  
  145. /* ******************************************************************** */
  146.                                                    /* Main Body Of Code */
  147. ThirdAngle = 90 - ReqAngle
  148.  
  149. CalcA = SIN((ReqAngle * DegToRad)) * RadToDeg
  150. CalcB = SIN((ThirdAngle * DegToRad)) * RadToDeg
  151.  
  152. BEHRadius = (ReqDepth * CalcA) / CalcB
  153. BEHRadialDepth = ReqDepth / 2
  154. BEHDepth = ReqDepth + ReqSPntZ
  155. FinalRadius = BEHRadius BEHRadius BEHRadialDepth
  156.  
  157. BEHCX = ReqSPntX
  158. BEHCY = ReqSPntY
  159. BEHCZ = ReqSPntZ + (ReqDepth / 2)
  160.  
  161. FinalCenter = BEHCX BEHCY BEHCZ
  162.  
  163. IF ReqRotH + ReqRotP + ReqRotB = 0 THEN DO      /* No Rotation Involved */
  164.     CALL MakeCone(FinalRadius, BEHDepth, ReqSPntZ, "Z", ReqSides, ReqSegs, FinalCenter)
  165. END
  166.  
  167. IF ReqRotH + ReqRotP + ReqRotB ~= 0 THEN DO       /* Empty Layer Needed */
  168.     CL = CurLayer()
  169.     Empty = EmptyLayers()
  170.     IF (WORDS(Empty) < 1) THEN DO
  171.         CALL Notify(1,"!Sorry!","@Need an empty layer","@for any rotations (H P B).")
  172.         CALL SaveSettings
  173.         CALL Exiting
  174.     END
  175.     EL = WORD(Empty, 1)
  176.  
  177.     CALL SetLayer(EL)
  178.  
  179.     CALL MakeCone(FinalRadius, BEHDepth, ReqSPntZ, "Z", ReqSides, ReqSegs, FinalCenter)
  180.  
  181.     CALL Rotate(ReqRotB, "Z", ReqSource)
  182.     CALL Rotate(ReqRotP, "X", ReqSource)
  183.     CALL Rotate(ReqRotH, "Y", ReqSource)
  184.  
  185.     CALL Cut()
  186.     CALL SetLayer(CL)
  187.     CALL Paste()
  188. END
  189.  
  190. CALL SaveSettings
  191. CALL Exiting
  192.  
  193. /* ******************************************************************** */
  194.                                             /* Recording Macro Settings */
  195. SaveSettings:
  196.  
  197.     IF (OPEN(PrefsFile, PrefsFileName, 'W')) THEN DO
  198.         CALL WRITELN(PrefsFile, MacrosName)
  199.  
  200.         CALL WRITELN(PrefsFile, ReqSource)
  201.         CALL WRITELN(PrefsFile, ReqAngle)
  202.         CALL WRITELN(PrefsFile, ReqDepth)
  203.         CALL WRITELN(PrefsFile, ReqSides)
  204.         CALL WRITELN(PrefsFile, ReqSegs)
  205.         CALL WRITELN(PrefsFile, ReqHPB)
  206.  
  207.         CALL CLOSE PrefsFile
  208.     END
  209.  
  210. RETURN
  211.  
  212. /* -------------------------------------------------------------------- */
  213.                                                               /* Ending */
  214. Exiting:
  215.  
  216.     IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
  217.     EXIT
  218.  
  219. RETURN
  220.  
  221. /* -------------------------------------------------------------------- */
  222.                                                  /* Information Windows */
  223. InformationWindows:
  224.  
  225.     OKorCancel = Notify(2, Info1A, Info1B, Info1C, Info1D, Info1E, Info1F, Info1G, Info1H, Info1I, Info1J, Info1K, Info1L, Info1M, Info1N)
  226.     IF OKorCancel = 1 THEN CALL Notify(1, Info2A, Info2B, Info2C, Info2D, Info2E, Info2F, Info2G, Info2H, Info2I, Info2J, Info2K, Info2L, Info2M, Info2N)
  227.  
  228. RETURN
  229.  
  230. /* -------------------------------------------------------------------- */
  231.                                                       /* Error Handling */
  232. SYNTAX:
  233. ERROR:
  234.  
  235.     ErrCode = RC
  236.     ErrLine = SIGL
  237.     ErrInfo = ERRORTEXT(ErrCode)
  238.  
  239.     Err1 = "!Sorry!"
  240.     Err2 = "An Error has been detected"
  241.     Err3 = "@þ Macro -            "
  242.     Err4 = "@þ Line Number -      "
  243.     Err5 = "@þ Error Code -       "
  244.     Err6 = "@þ Error Description -"
  245.     Err7 = "@¤ Please Inform -    "
  246.     Err8 = '  "Error Notice"     '
  247.     Err9 = "  13032 Copenhill Rd."
  248.     Err10 = "  Dallas, TX. 75240  "
  249.  
  250.     Call Notify(1,Err1,Err2,Err3,MacrosName,Err4,ErrLine,Err5,ErrCode,Err6,ErrInfo,Err7,Err8,Err9,Err10)
  251.  
  252. /* -------------------------------------------------------------------- */
  253.                                              /* Advanced Error Handling */
  254.     CALL SETCLIP("ErrorMacro",MacrosName)
  255.     CALL SETCLIP("ErrorLine",ErrLine)
  256.     CALL SETCLIP("ErrorCode",ErrCode)
  257.     CALL SETCLIP("ErrorDesc",ErrInfo)
  258.  
  259.     PARSE SOURCE TempA TempB ErrFile TempC TempD TempE
  260.  
  261.     CALL SETCLIP("ErrorFile",ErrFile)
  262.  
  263. /* -------------------------------------------------------------------- */
  264.  
  265.     IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
  266.     EXIT
  267.