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

  1. /* CMD: ½ModifyObject                                                   */
  2. /* By Brett Evan Hester      13032 Copenhill Rd. Dallas, Tx. 75240-5302 */
  3.     MacrosName = "ModifyObject"
  4. /* Macro Type:                                                          */
  5. /* MODIFIES    * OBJECTS   * BKG NEEDED   * SELECTED     * REMEMBERS    */
  6. /* Description:                                                         */
  7.  
  8. Info1A = "!Modify Object ©               Information 1 of 6"
  9. Info1B = ""
  10. Info1C = "@This macro will modify the currently selected,  "
  11. Info1D = "@given formulas for the position of each point.  "
  12. Info1E = ""
  13. Info1F = "@þ Variables based on each pnts coords.:         "
  14. Info1G = "          X              Y                Z     "
  15. Info1H = "@þ Variables based on current layer:             "
  16. Info1I = "LeftEdge  or X1  CenterX or CX  RightEdge or X2 "
  17. Info1J = "LowerEdge or Y1  CenterY or CY  UpperEdge or Y2 "
  18. Info1K = "FrontEdge or Z1  CenterZ or CZ  BackEdge  or Z2 "
  19. Info1L = "Width     or TX  Height  or TY  Depth     or TZ "
  20. Info1M = "DiffX     or DX  DiffY   or DY  DiffZ     or DZ "
  21. Info1N = "@More INFORMATION and VARIABLES on follow...     "
  22.  
  23. Info2A = "!Modify Object ©               Information 2 of 6"
  24. Info2B = ""
  25. Info2C = "@þ Variables based on current background layer:  "
  26. Info2D = "BKGLeft  / BX1  BKGCenterX / BCX  BKGRight / BX2"
  27. Info2E = "BKGLower / BY1  BKGCenterY / BCY  BKGUpper / BY2"
  28. Info2F = "BKGFront / BZ1  BKGCenterZ / BCZ  BKGBack  / BZ2"
  29. Info2G = "BKGWidth / BTX  BKGHeight  / BTY  BKGDepth / BTZ"
  30. Info2H = "BKGDiffX / BDX  BKGDiffY   / BDY  BKGDiffZ / BDZ"
  31. Info2I = '@Note:"Diff" stands for the difference between   '
  32. Info2J = "@      the coord. and the layer's center.        "
  33. Info2K = ""
  34. Info2L = "@½ Any variable can be used in any equation. ¼"
  35. Info2M = ""
  36. Info2N = "@More INFORMATION and VARIABLES on follow...     "
  37.  
  38. Info3A = "!Modify Object ©               Information 3 of 6"
  39. Info3B = ""
  40. Info3C = "@þ Constants:                                    "
  41. Info3D = '  Type "PI" to get 3.141592653589793238462643   '
  42. Info3E = '  Type "Eunit" for 2.718281828459045235360287   '
  43. Info3F = ""
  44. Info3G = "@¤ Constants for conversion purposes:            "
  45. Info3H = "þ 8 length constants are included, multiply by -"
  46. Info3I = "  MtToFt, MtToIn, KmToMl, KmToFt, & the reverse "
  47. Info3J = "þ 6 speed constants are included, multiply by - "
  48. Info3K = "  KPHToMPH, KPHToFPS, MPHToFPS, and the reverse "
  49. Info3L = "þ 2 angle constants are included, multiply by - "
  50. Info3M = "  DegToRad or RadToDeg                          "
  51. Info3N = "@Information on commands and usage to follow... "
  52.  
  53. Info4A = "!Modify Object ©               Information 4 of 6"
  54. Info4B = ""
  55. Info4C = "@þ Commands:                                     "
  56. Info4D = "  SQRT(x) = Square Root  ABS(x)  = Absolute     "
  57. Info4E = "  FACT(x) = Factorial    NINT(x) = Rounds off   "
  58. Info4F = ""
  59. Info4G = "@¤ Commands involving angle calculations:        "
  60. Info4H = "  SIN(x°)    ASIN(x°)    SINH(x°)    ASINH(x°)  "
  61. Info4I = "  COS(x°)    ACOS(x°)    COSH(x°)    ACOSH(x°)  "
  62. Info4J = "  TAN(x°)    ATAN(x°)    TANH(x°)    ATANH(x°)  "
  63. Info4K = ""
  64. Info4L = "@NOTE: The computer calculates angles in radians."
  65. Info4M = "@If you are suppling the angles in degrees, type "
  66. Info4N = "@ALT-W (°) after the angle. This equals DegToRad."
  67.  
  68. Info5A = "!Modify Object ©               Information 5 of 6"
  69. Info5B = ""
  70. Info5C = "@þ Arithmetic operations and their priority:     "
  71. Info5D = "@Operator           Priority  Example      Result"
  72. Info5E = "+  (prefix conversion) 8     '3.12'       3.12  "
  73. Info5F = '-  (prefix negation)   8     -"3.12"      -3.12 '
  74. Info5G = "** (exponentiation)    7     0.5 ** 3     0.125 "
  75. Info5H = "*  (multiplication)    6     1.5 * 1.50   2.250 "
  76. Info5I = "/  (division)          6     6 / 3        2     "
  77. Info5J = "%  (integer division)  6     -8 % 3       -2    "
  78. Info5K = "// (remainder)         6     5.1 // 0.2   0.1   "
  79. Info5L = "+  (addition)          5     3.1 + 4.05   7.15  "
  80. Info5M = "-  (subtraction)       5     5.55 - 1     4.55  "
  81. Info5N = "@((((( Use Parentheses When Ever Necessary. )))))"
  82.  
  83. Info6A = "!Modify Object ©               Information 6 of 6"
  84. Info6B = "@               Plug-Ins and Go! ©               "
  85. Info6C = "                           Hester and associates"
  86. Info6D = "                           13032 Copenhill Road "
  87. Info6E = "                           Dallas, Texas 75240  "
  88. Info6F = "@Special Thanks to:                              "
  89. Info6G = "Arnie Cachelin  Henry Ribron    Mark J. Holland "
  90. Info6H = "J. Phil Kelso   Terry Wester    Steven K. Simms "
  91. Info6I = "Kevin DeRita    Greg Glaser     William S. Hawes"
  92. Info6J = "NewTek ©        Commodore ©     INOVAtronics ©  "
  93. Info6K = ""
  94. Info6L = "@This macro represents a lot of time & hard work."
  95. Info6M = "@Encourage people to create new ones and not kill"
  96. Info6N = "@that possibility by stealing those that are out."
  97.  
  98. /* -------------------------------------------------------------------- */
  99.                                      /* Start Error Detection (See End) */
  100. SIGNAL ON ERROR
  101. SIGNAL ON SYNTAX
  102.                                                    /* Address LightWave */
  103. VT3DLib = ADDLIB("LWModelerARexx.port",0)
  104. ADDRESS "LWModelerARexx.port"
  105.                                                   /* Add Math Functions */
  106. MATHLIB= "rexxmathlib.library"
  107. IF POS(MATHLIB , SHOW('L')) = 0 THEN
  108.     IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
  109.         CALL Notify(1,"!Can't find "MATHLIB)
  110.         IF VT3DLib THEN CALL REMLIB("LWModelerARexx.port")
  111.         EXIT
  112.     END
  113.  
  114. /* -------------------------------------------------------------------- */
  115.                                                      /* Fixed Variables */
  116. PI = 3.141592653589793238462643
  117. EUnit = 2.718281828459045235360287
  118.                                                     /* Angle Conversion */
  119. RadToDeg = 180 / PI  ; DegToRad = PI / 180
  120.                                                  /* Distance Conversion */
  121. MtToFt = 3.280833    ; FtToMt = 0.3048006
  122. MtToIn = 39.370079   ; InToMt = 0.02540005
  123. KmToMl = 0.621371    ; MlToKm = 1.60935
  124. KmToFt = 3280.839895 ; FtToKm = 0.000305
  125.                                                     /* Speed Conversion */
  126. KPHToMPH = 0.621371  ; MPHToKPH = 1.609344
  127. KPHToFPS = 0.911344  ; FPSToKPH = 1.09728
  128. MPHToFPS = 1.466667  ; FPSToMPH = 0.681818
  129.  
  130. /* -------------------------------------------------------------------- */
  131.                                                /* Info On Current Layer */
  132. CL = CurLayer()
  133. Box = BoundingBox(CL)
  134. PARSE var Box N X1 X2 Y1 Y2 Z1 Z2
  135.  
  136. CX = (X1 / 2) + (X2 / 2)
  137. CY = (Y1 / 2) + (Y2 / 2)
  138. CZ = (Z1 / 2) + (Z2 / 2)
  139.  
  140. LeftEdge = X1  ; CenterX = CX ; RightEdge = X2
  141. LowerEdge = Y1 ; CenterY = CY ; UpperEdge = Y2
  142. FrontEdge = Z1 ; CenterZ = CZ ; BackEdge = Z2
  143.  
  144. TX = X2 - X1   ; Width = TX
  145. TY = Y2 - Y1   ; Height = TY
  146. TZ = Z2 - Z1   ; Depth = TZ
  147.                                                    /* Info On BKG Layer */
  148. BL = CurBLayer()
  149. Box = BoundingBox(BL)
  150. PARSE var Box N BX1 BX2 BY1 BY2 BZ1 BZ2
  151.  
  152. BCX = (BX1 / 2) + (BX2 / 2)
  153. BCY = (BY1 / 2) + (BY2 / 2)
  154. BCZ = (BZ1 / 2) + (BZ2 / 2)
  155.  
  156. BKGLeft = BX1   ; BKGCenterX = BCX ; BKGRight = BX2
  157. BKGLower = BY1  ; BKGCenterY = BCY ; BKGUpper = BY2
  158. BKGFront = BZ1  ; BKGCenterZ = BCZ ; BKGBack = BZ2
  159.  
  160. BTX = BX2 - BX1 ; BKGWidth = BTX
  161. BTY = BY2 - BY1 ; BKGHeight = BTY
  162. BTZ = BZ2 - BZ1 ; BKGDepth = BTZ
  163.  
  164. /* -------------------------------------------------------------------- */
  165.                                     /* Reading Global Macro Preferences */
  166. BEHDefaultFilePath = "Sys:"
  167. BEHSettingsSavedTo = "T:"
  168. BEHSpeechAndSound = "1"
  169.  
  170. IF (EXISTS("S:PlugInPrefs")) THEN DO
  171.     IF (~OPEN(PlugInPrefs, "S:PlugInPrefs", 'R')) THEN BREAK
  172.     IF (READLN(PlugInPrefs) ~= "PlugInPrefs") THEN BREAK
  173.     BEHDefaultFilePath = READLN(PlugInPrefs)
  174.     BEHSettingsSavedTo = READLN(PlugInPrefs)
  175.     BEHSpeechAndSound = READLN(PlugInPrefs)
  176.     CALL CLOSE PlugInPrefs
  177. END
  178.  
  179. /* -------------------------------------------------------------------- */
  180.                                             /* Recalling Macro Settings */
  181. ReqX = "X"
  182. ReqY = "Y"
  183. ReqZ = "Z"
  184.  
  185. PrefsFileName = BEHSettingsSavedTo||MacrosName||".PLUG"
  186.  
  187. IF (EXISTS(PrefsFileName)) THEN DO
  188.     IF (~OPEN(PrefsFile, PrefsFileName, 'R')) THEN BREAK
  189.     IF (READLN(PrefsFile) ~= MacrosName) THEN BREAK
  190.  
  191.     ReqX = READLN(PrefsFile)
  192.     ReqY = READLN(PrefsFile)
  193.     ReqZ = READLN(PrefsFile)
  194.  
  195.     CALL CLOSE PrefsFile
  196. END
  197.  
  198. /* ******************************************************************** */
  199.                                                    /* Main Body Of Code */
  200. MainBodyOfCode:
  201.  
  202.     CALL MenuRequester
  203.     CALL SaveSettings
  204.     CALL TransformObject
  205.     CALL Exiting
  206.  
  207. RETURN
  208.  
  209. /* ******************************************************************** */
  210.                                                       /* User Interface */
  211. MenuRequester:
  212.  
  213.     CALL Req_Begin"Modify Object ©                   by Brett Hester"
  214.  
  215.     ReqA = Req_AddControl("Position X (X)",'S',33)
  216.     ReqB = Req_AddControl("Position X (Y)",'S',33)
  217.     ReqC = Req_AddControl("Position X (Z)",'S',33)
  218.     ReqD = Req_AddControl("",'CH',"Information")
  219.  
  220.     CALL Req_SetVal(ReqA, ReqX)
  221.     CALL Req_SetVal(ReqB, ReqY)
  222.     CALL Req_SetVal(ReqC, ReqZ)
  223.     CALL Req_SetVal(ReqD, 0)
  224.  
  225.     OKorCancel = Req_Post() ; IF OKorCancel = 0 THEN CALL Exiting
  226.  
  227.     ReqX = Req_GetVal(ReqA)
  228.     ReqY = Req_GetVal(ReqB)
  229.     ReqZ = Req_GetVal(ReqC)
  230.     BEHInfo = Req_GetVal(ReqD)
  231.  
  232.     CALL Req_End()
  233.  
  234.     IF BEHInfo = 1 THEN CALL InformationWindows
  235.  
  236. RETURN
  237.  
  238. /* -------------------------------------------------------------------- */
  239.                                                  /* Transforming Object */
  240. TransformObject:
  241.  
  242.     N = XFrm_Begin()
  243.     CALL Meter_Begin N, "Transforming Object..."
  244.     DO i = 1 to N
  245.         PARSE value XFrm_GetPos(i) with X Y Z .
  246.  
  247.         DX = X - CX    ; DY = Y - CY    ; DZ = Z - CZ
  248.         BDX = X - BCX  ; BDY = Y - BCY  ; BDZ = Z - BCZ
  249.         DiffX = DX     ; DiffY = DY     ; DiffZ = DZ
  250.         BKGDiffX = BDX ; BKGDiffY = BDY ; BKGDiffZ = BDZ
  251.         CNT = i
  252.  
  253.         CALL UsingDegrees(ReqX) ; INTERPRET "X = "||Formula
  254.         CALL UsingDegrees(ReqY) ; INTERPRET "Y = "||Formula
  255.         CALL UsingDegrees(ReqZ) ; INTERPRET "Z = "||Formula
  256.  
  257.         CALL XFrm_SetPos i, X Y Z
  258.         CALL Meter_Step
  259.     END
  260.     CALL Meter_End
  261.     CALL XFrm_End
  262.  
  263. RETURN
  264.  
  265. /* -------------------------------------------------------------------- */
  266.                            /* Structuring Formulas with Degree symbols  */
  267. UsingDegrees:
  268.  
  269.     PARSE arg Formula
  270.  
  271.     QAAngle = 1
  272.     DO UNTIL QAAngle = 0
  273.         QAAngle = POS("°", Formula)
  274.         IF QAAngle ~= 0 THEN DO
  275.             FormulaLength = LENGTH(Formula)
  276.             PartA = LEFT(Formula, QAAngle - 1)
  277.             PartB = RIGHT(Formula, FormulaLength - QAAngle)
  278.             Formula = PartA||" * "||DegToRad||PartB
  279.         END
  280.     END
  281.  
  282. RETURN
  283.  
  284. /* -------------------------------------------------------------------- */
  285.                                                        /* Save Settings */
  286. SaveSettings:
  287.  
  288.     IF (OPEN(PrefsFile, PrefsFileName, 'W')) THEN DO
  289.         CALL WRITELN(PrefsFile, MacrosName)
  290.  
  291.         CALL WRITELN(PrefsFile, ReqX)
  292.         CALL WRITELN(PrefsFile, ReqY)
  293.         CALL WRITELN(PrefsFile, ReqZ)
  294.  
  295.         CALL CLOSE PrefsFile
  296.     END
  297.  
  298. RETURN
  299.  
  300. /* -------------------------------------------------------------------- */
  301.                                                               /* Ending */
  302. Exiting:
  303.  
  304.     IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
  305.     EXIT
  306.  
  307. RETURN
  308.  
  309. /* -------------------------------------------------------------------- */
  310.                                                  /* Information Windows */
  311. InformationWindows:
  312.  
  313.     OKorCancel = Notify(2, Info1A, Info1B, Info1C, Info1D, Info1E, Info1F, Info1G, Info1H, Info1I, Info1J, Info1K, Info1L, Info1M, Info1N)
  314.     IF OKorCancel = 1 THEN OKorCancel = Notify(2, Info2A, Info2B, Info2C, Info2D, Info2E, Info2F, Info2G, Info2H, Info2I, Info2J, Info2K, Info2L, Info2M, Info2N)
  315.     IF OKorCancel = 1 THEN OKorCancel = Notify(2, Info3A, Info3B, Info3C, Info3D, Info3E, Info3F, Info3G, Info3H, Info3I, Info3J, Info3K, Info3L, Info3M, Info3N)
  316.     IF OKorCancel = 1 THEN OKorCancel = Notify(2, Info4A, Info4B, Info4C, Info4D, Info4E, Info4F, Info4G, Info4H, Info4I, Info4J, Info4K, Info4L, Info4M, Info4N)
  317.     IF OKorCancel = 1 THEN OKorCancel = Notify(2, Info5A, Info5B, Info5C, Info5D, Info5E, Info5F, Info5G, Info5H, Info5I, Info5J, Info5K, Info5L, Info5M, Info5N)
  318.     IF OKorCancel = 1 THEN CALL Notify(1, Info6A, Info6B, Info6C, Info6D, Info6E, Info6F, Info6G, Info6H, Info6I, Info6J, Info6K, Info6L, Info6M, Info6N)
  319.     CALL MenuRequester
  320.  
  321. RETURN
  322.  
  323. /* -------------------------------------------------------------------- */
  324.                                                       /* Error Handling */
  325. SYNTAX:
  326. ERROR:
  327.  
  328.     ErrCode = RC
  329.     ErrLine = SIGL
  330.     ErrInfo = ERRORTEXT(ErrCode)
  331.  
  332.     Err1 = "!Sorry!"
  333.     Err2 = "An Error has been detected"
  334.     Err3 = "@þ Macro -            "
  335.     Err4 = "@þ Line Number -      "
  336.     Err5 = "@þ Error Code -       "
  337.     Err6 = "@þ Error Description -"
  338.     Err7 = "@¤ Please Inform -    "
  339.     Err8 = '  "Error Notice"     '
  340.     Err9 = "  13032 Copenhill Rd."
  341.     Err10 = "  Dallas, TX. 75240  "
  342.  
  343.     Call Notify(1,Err1,Err2,Err3,MacrosName,Err4,ErrLine,Err5,ErrCode,Err6,ErrInfo,Err7,Err8,Err9,Err10)
  344.  
  345. /* -------------------------------------------------------------------- */
  346.                                              /* Advanced Error Handling */
  347.     CALL SETCLIP("ErrorMacro",MacrosName)
  348.     CALL SETCLIP("ErrorLine",ErrLine)
  349.     CALL SETCLIP("ErrorCode",ErrCode)
  350.     CALL SETCLIP("ErrorDesc",ErrInfo)
  351.  
  352.     PARSE SOURCE TempA TempB ErrFile TempC TempD TempE
  353.  
  354.     CALL SETCLIP("ErrorFile",ErrFile)
  355.  
  356. /* -------------------------------------------------------------------- */
  357.  
  358.     SIGNAL ON ERROR
  359.     SIGNAL ON SYNTAX
  360.     SIGNAL MainBodyOfCode
  361.