home *** CD-ROM | disk | FTP | other *** search
- /* CMD: ½CalcPosition */
- /* By Brett Evan Hester 13032 Copenhill Rd. Dallas, Tx. 75240-5302 */
- MacrosName = "CalcPosition"
- /* Macro Type: */
- /* CALCULATES * OBJECTS * SELECTED * REMEMBERS */
- /* Description: */
-
- Info1A = "!Calculate Position © Information 1 of 2"
- Info1B = ""
- Info1C = "@This macro will provide a position given an old "
- Info1D = "@position OR a direction and distance to head. "
- Info1E = ""
- Info1F = "þ When calculating or using the HEADING & PITCH:"
- Info1G = "¤ Clockwise rotation is positive (+). "
- Info1H = "¤ POINT A is considered the source. "
- Info1I = "¤ POINT B is considered the target. "
- Info1J = "¤ DISTANCE is direct from POINT A to POINT B. "
- Info1K = ""
- Info1L = "@þ On the main menu: "
- Info1M = "OK will Update the Menu Requester and Continue. "
- Info1N = "CANCEL will Leave or Quit this macro. "
-
- Info2A = "!Calculate Position © Information 2 of 2"
- Info2B = "@ Plug-Ins and Go! © "
- Info2C = " Hester and associates"
- Info2D = " 13032 Copenhill Road "
- Info2E = " Dallas, Texas 75240 "
- Info2F = "@Special Thanks to: "
- Info2G = "Arnie Cachelin Henry Ribron Mark J. Holland "
- Info2H = "J. Phil Kelso Terry Wester Steven K. Simms "
- Info2I = "Kevin DeRita Greg Glaser William S. Hawes"
- Info2J = "NewTek © Commodore © INOVAtronics © "
- Info2K = ""
- Info2L = "@This macro represents a lot of time & hard work."
- Info2M = "@Encourage people to create new ones and not kill"
- Info2N = "@that possibility by stealing those that are out."
-
- /* -------------------------------------------------------------------- */
- /* Start Error Detection (See End) */
- SIGNAL ON ERROR
- SIGNAL ON SYNTAX
- /* Address LightWave */
- VT3DLib = ADDLIB("LWModelerARexx.port",0)
- ADDRESS "LWModelerARexx.port"
- /* Add Math Functions */
- MATHLIB= "rexxmathlib.library"
- IF POS(MATHLIB , SHOW('L')) = 0 THEN
- IF ~ADDLIB(MATHLIB , 0 , -30 , 0) THEN DO
- CALL Notify(1,"!Can't find "MATHLIB)
- IF VT3DLib THEN CALL REMLIB("LWModelerARexx.port")
- EXIT
- END
-
- /* -------------------------------------------------------------------- */
- /* Reading Global Macro Preferences */
- BEHDefaultFilePath = "Sys:"
- BEHSettingsSavedTo = "T:"
- BEHSpeechAndSound = "1"
-
- IF (EXISTS("S:PlugInPrefs")) THEN DO
- IF (~OPEN(PlugInPrefs, "S:PlugInPrefs", 'R')) THEN BREAK
- IF (READLN(PlugInPrefs) ~= "PlugInPrefs") THEN BREAK
- BEHDefaultFilePath = READLN(PlugInPrefs)
- BEHSettingsSavedTo = READLN(PlugInPrefs)
- BEHSpeechAndSound = READLN(PlugInPrefs)
- CALL CLOSE PlugInPrefs
- END
-
- /* -------------------------------------------------------------------- */
- /* Recalling Macro Settings */
- XA = 0 ; YA = 0 ; ZA = 0
- XB = 0 ; YB = 0 ; ZB = 0
- ReqHeading = 0 ; ReqPitch = 0 ; ReqDistance = 0
- ReqCalc = 3
- ReqCreate = 1
-
- PrefsFileName = BEHSettingsSavedTo||MacrosName||".PLUG"
-
- IF (EXISTS(PrefsFileName)) THEN DO
- IF (~OPEN(PrefsFile, PrefsFileName, 'R')) THEN BREAK
- IF (READLN(PrefsFile) ~= MacrosName) THEN BREAK
-
- PARSE VALUE READLN(PrefsFile) WITH XA YA ZA
- PARSE VALUE READLN(PrefsFile) WITH XB YB ZB
- PARSE VALUE READLN(PrefsFile) WITH ReqHeading ReqPitch ReqDistance
- ReqCalc = READLN(PrefsFile)
- BEHInfoReqCreate = READLN(PrefsFile)
-
- CALL CLOSE PrefsFile
- END
-
- /* -------------------------------------------------------------------- */
- /* Setting fixed variables */
- PI = 3.141592653589793238462643
- RadToDeg = 180 / PI ; DegToRad = PI / 180
- QuarterTurn = PI / 2 /* 90° 1.570 Rad */
- HalfTurn = PI /* 180° 3.142 Rad */
- FullTurn = PI * 2 /* 360° 6.283 Rad */
-
- /* -------------------------------------------------------------------- */
- /* Settings if 2 Points Selected */
- CALL Sel_Mode(USER)
-
- NumberOfPnts = XFrm_Begin()
-
- IF NumberOfPnts = 2 THEN DO
- PARSE VALUE XFrm_GetPos(1) WITH XA YA ZA
- PARSE VALUE XFrm_GetPos(2) WITH XB YB ZB
- CALL XFrm_End
- CALL CalcHPD
- ReqCreate = 2
- END
-
- /* ******************************************************************** */
- /* Main Body Of Code */
- DO FOREVER
- CALL MenuRequester
- IF ReqCalc ~= 3 THEN CALL CalcXYZ
- IF ReqCalc = 3 THEN CALL CalcHPD
- IF ReqCreate = 1 THEN CALL CreatePoints
- END
-
- /* ******************************************************************** */
- /* User Interface */
- MenuRequester:
-
- CALL Req_Begin("Calculate Position © ")
-
- CALL Req_AddControl(" ",'T'," by Brett Hester ","")
- CALL Req_AddControl("þ",'T',"Coords. X Y Z")
- ReqA = Req_AddControl("A",'V',1)
- ReqB = Req_AddControl("B",'V',1)
- CALL Req_AddControl(" ",'T',"")
- CALL Req_AddControl("þ",'T',"Heading Pitch Distance")
- ReqC = Req_AddControl("¤",'V',0)
- CALL Req_AddControl(" ",'T',"")
- CALL Req_AddControl("þ",'T',"Calculate")
- ReqD = Req_AddControl("¤",'CH', " Point A Point B HP & D ")
- CALL Req_AddControl(" ",'T',"")
- ReqE = Req_AddControl(" ",'CH', "Create Points X")
- ReqF = Req_AddControl("¤",'CH', "Information")
-
- CALL Req_SetVal(ReqA, XA YA ZA)
- CALL Req_SetVal(ReqB, XB YB ZB)
- CALL Req_SetVal(ReqC, ReqHeading ReqPitch ReqDistance)
- CALL Req_SetVal(ReqD, ReqCalc)
- CALL Req_SetVal(ReqE, ReqCreate)
- CALL Req_SetVal(ReqF, 0)
-
- IF Req_Post() = 0 THEN DO
- CALL SaveSettings
- CALL Exiting
- END
-
- PARSE VALUE Req_GetVal(ReqA) WITH XA YA ZA
- PARSE VALUE Req_GetVal(ReqB) WITH XB YB ZB
- PARSE VALUE Req_GetVal(ReqC) WITH ReqHeading ReqPitch ReqDistance
- ReqCalc = Req_GetVal(ReqD)
- ReqCreate = Req_GetVal(ReqE)
- BEHInfo = Req_GetVal(ReqF)
-
- CALL Req_End()
-
- ReqDistance = ABS(ReqDistance)
-
- IF BEHInfo = 0 THEN CALL CheckInput
- IF BEHInfo = 1 THEN CALL InformationWindows
-
- RETURN
-
- /* -------------------------------------------------------------------- */
- /* Verify Input */
- CheckInput:
-
- IF ReqCalc ~= 3 THEN DO
- IF ReqDistance = 0 THEN DO
- CALL Notify(1,"!No Distance was provided.")
- CALL MenuRequester
- END
- END
-
- OKtoContinue = 0
- DO UNTIL OKtoContinue = 1
- IF ReqPitch < -90 THEN DO
- ReqPitch = -90 - (ReqPitch + 90)
- IF ReqPitch > -270 THEN ReqHeading = ReqHeading - 180
- END
- IF ReqPitch > 90 THEN DO
- ReqPitch = 90 - (ReqPitch - 90)
- IF ReqPitch < 270 THEN ReqHeading = ReqHeading + 180
- END
- IF ReqPitch < 90 THEN DO
- IF ReqPitch > -90 THEN OKtoContinue = 1
- END
- END
-
- OKtoContinue = 0
- DO UNTIL OKtoContinue = 1
- IF ReqHeading < -180 THEN ReqHeading = 180 + (ReqHeading +180)
- IF ReqHeading > 180 THEN ReqHeading = -180 + (ReqHeading -180)
- IF ReqHeading < 180 THEN DO
- IF ReqHeading > -180 THEN OKtoContinue = 1
- END
- END
-
- RETURN
-
- /* -------------------------------------------------------------------- */
- /* Calculating Quadrant of 2nd Point */
- CalcXYZ:
- /******************************************************/
- /*Quadrants: */
- /* _______+Z_______ */
- /* / +IV | +I \ */
- /* / -++ | +++ \ */
- /* -X /----------+---------\ +X Quad. XYZ P Heading */
- /* / +III | +II \ ======================*/
- /* / -+- | ++- \ +I +++ - + 0-90 */
- /* /-------------+------------\ +II ++- - + 90-180 */
- /* | | -Z | | +III -+- - - 90-180 */
- /* | | | | +IV -++ - - 0-90 */
- /* | |_______+Z_______| | -I +-+ + + 0-90 */
- /* | / -IV | -I \ | -II +-- + + 90-180 */
- /* / --+ | +-+ \ -III --- + - 90-180 */
- /* -X /----------+---------\ +X -IV --+ + - 0-90 */
- /* / -III | -II \ */
- /* |/ --- | +-- \| */
- /* /-------------+------------\ */
- /* -Z */
- /******************************************************/
-
- IF ReqPitch > 0 THEN YDiff = "-" /* + Quadrant */
- IF ReqPitch <= 0 THEN YDiff = "+" /* - Quadrant */
-
- IF ReqHeading >= 0 THEN DO
- IF ReqHeading <= 90 THEN DO /* Quadrant I */
- XDiff = "+" ; ZDiff = "+"
- END
- IF ReqHeading > 90 THEN DO /* Quadrant II */
- XDiff = "+" ; ZDiff = "-"
- END
- END
-
- IF ReqHeading < 0 THEN DO
- IF ReqHeading < -90 THEN DO /* Quadrant III */
- XDiff = "-" ; ZDiff = "-"
- END
- IF ReqHeading >= -90 THEN DO /* Quadrant IV */
- XDiff = "-" ; ZDiff = "+"
- END
- END
- /* Calculating distance between points */
- Skew = ABS(ReqDistance * COS((ReqPitch * DegToRad)))
- Height = ABS(ReqDistance * SIN((ReqPitch * DegToRad)))
- Width = ABS(Skew * SIN((ReqHeading * DegToRad)))
- Depth = ABS(Skew * COS((ReqHeading * DegToRad)))
-
- IF ReqCalc = 1 THEN DO /* Calculate Position of Point A */
- INTERPRET "XA = "||XB||XDiff||Width
- INTERPRET "YA = "||YB||YDiff||Height
- INTERPRET "ZA = "||ZB||ZDiff||Depth
- END
-
- IF ReqCalc = 2 THEN DO /* Calculate Position of Point B */
- INTERPRET "XB = "||XA||XDiff||Width
- INTERPRET "YB = "||YA||YDiff||Height
- INTERPRET "ZB = "||ZA||ZDiff||Depth
- END
-
- RETURN
-
- /* -------------------------------------------------------------------- */
- /* Calculating HPD */
- CalcHPD:
-
- Width = ABS((XB-XA)) ; Height = ABS((YB-YA)) ; Depth = ABS((ZB-ZA))
- Skew = SQRT((Width * Width) + (Depth * Depth))
- ReqDistance = SQRT((Skew * Skew) + (Height * Height))
-
- IF Width ~= 0 THEN ReqHeading = ATAN(Depth / Width) * RadToDeg
- IF Width = 0 THEN ReqHeading = 0
- IF Skew ~= 0 THEN ReqPitch = ATAN(Height / Skew) * RadToDeg
- IF Skew = 0 THEN ReqPitch = 0
-
- IF XB > XA THEN DO
- IF ZB > ZA THEN ReqHeading = 90 - ReqHeading
- IF ZB < ZA THEN ReqHeading = ReqHeading + 90
- END
- IF XB < XA THEN DO
- IF ZB > ZA THEN ReqHeading = ReqHeading - 90
- IF ZB < ZA THEN ReqHeading = (90 - ReqHeading) - 180
- END
-
- IF YB > YA THEN ReqPitch = ReqPitch - ReqPitch - ReqPitch
-
- RETURN
-
- /* -------------------------------------------------------------------- */
- /* Creating Points */
- CreatePoints:
-
- CALL Add_Begin()
- CALL Add_Point(XA YA ZA)
- CALL Add_Point(XB YB ZB)
- CALL Add_Polygon(1 2)
- CALL Add_End()
-
- RETURN
-
- /* -------------------------------------------------------------------- */
- /* Ending */
- Exiting:
-
- IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
- EXIT
-
- RETURN
-
- /* -------------------------------------------------------------------- */
- /* Information Windows */
- InformationWindows:
-
- OKorCancel = Notify(2, Info1A, Info1B, Info1C, Info1D, Info1E, Info1F, Info1G, Info1H, Info1I, Info1J, Info1K, Info1L, Info1M, Info1N)
- IF OKorCancel = 1 THEN CALL Notify(1, Info2A, Info2B, Info2C, Info2D, Info2E, Info2F, Info2G, Info2H, Info2I, Info2J, Info2K, Info2L, Info2M, Info2N)
- CALL MenuRequester
-
- RETURN /* Not actually needed */
-
- /* -------------------------------------------------------------------- */
- /* Recording Macro Settings */
- SaveSettings:
-
- IF (OPEN(PrefsFile, PrefsFileName, 'W')) THEN DO
- CALL WRITELN(PrefsFile, MacrosName)
-
- CALL WRITELN(PrefsFile, XA YA ZA)
- CALL WRITELN(PrefsFile, XB YB ZB)
- CALL WRITELN(PrefsFile, ReqHeading ReqPitch ReqDistance)
- CALL WRITELN(PrefsFile, ReqCalc)
- CALL WRITELN(PrefsFile, BEHInfoReqCreate)
-
- CALL CLOSE PrefsFile
- END
-
- RETURN
-
- /* -------------------------------------------------------------------- */
- /* Error Handling */
- SYNTAX:
- ERROR:
-
- ErrCode = RC
- ErrLine = SIGL
- ErrInfo = ERRORTEXT(ErrCode)
-
- Err1 = "!Sorry!"
- Err2 = "An Error has been detected"
- Err3 = "@þ Macro - "
- Err4 = "@þ Line Number - "
- Err5 = "@þ Error Code - "
- Err6 = "@þ Error Description -"
- Err7 = "@¤ Please Inform - "
- Err8 = ' "Error Notice" '
- Err9 = " 13032 Copenhill Rd."
- Err10 = " Dallas, TX. 75240 "
-
- Call Notify(1,Err1,Err2,Err3,MacrosName,Err4,ErrLine,Err5,ErrCode,Err6,ErrInfo,Err7,Err8,Err9,Err10)
-
- /* -------------------------------------------------------------------- */
- /* Advanced Error Handling */
- CALL SETCLIP("ErrorMacro",MacrosName)
- CALL SETCLIP("ErrorLine",ErrLine)
- CALL SETCLIP("ErrorCode",ErrCode)
- CALL SETCLIP("ErrorDesc",ErrInfo)
-
- PARSE SOURCE TempA TempB ErrFile TempC TempD TempE
-
- CALL SETCLIP("ErrorFile",ErrFile)
-
- /* -------------------------------------------------------------------- */
-
- IF (VT3DLib) THEN CALL REMLIB("LWModelerARexx.port")
- EXIT
-