I told you my brain wasn't working correctly!
Here, try this:
`EZroate Enhanced
`Features Demo 3: Orbiting
`---------------------------------------------
`by: Ron Erickson 1-Jul-04
`**********************
`Setup
`**********************
SYNC ON
SYNC RATE 60
SET DISPLAY MODE 800,600,16
AUTOCAM OFF
RANDOMIZE TIMER()
COLOR BACKDROP rgb(0,0,0)
`**********************
`Load Objects:
`**********************
`Create Door
MAKE OBJECT BOX 1,5,10,.5
POSITION OBJECT 1,0,5,0
LOAD IMAGE "media/oak_door.jpg",1
TEXTURE OBJECT 1,1
`Create Path
MAKE OBJECT PLAIN 2,5,50
XROTATE OBJECT 2,90
LOAD IMAGE "media/grass_T.jpg",2
TEXTURE OBJECT 2,2
SCALE OBJECT TEXTURE 2,1,10
make object sphere 100,1
color object 100,rgb(255,0,0)
make object sphere 101,1
make object sphere 102,1
ObjX# = 2.5
ObjY# = 0
ObjZ# = 0
`Camera
POSITION CAMERA -5,10,-20
POINT CAMERA 0,5,0
mode = 0
direction = 0
`**********************
`Main Loop:
`**********************
DO
`Advance Demo with SpaceBar
`---------------------------
IF SPACEKEY() = 1
changemode = 1
ENDIF
IF changemode = 1 AND SPACEKEY() = 0
changemode = 0
mode = mode + 1
ROTATE OBJECT 1,0,0,0
POSITION OBJECT 1,5,5,0
direction = 0
DoorAngle = 0
ENDIF
If UPKEY() = 1
ObjZ# = ObjZ# + 1
position object 1,object position x(1), object position y(1), object position z(1)+1
endif
If DOWNKEY() = 1
ObjZ# = ObjZ# - 1
position object 1,object position x(1), object position y(1), object position z(1)-1
endif
If RIGHTKEY() = 1
ObjX# = ObjX# + 1
position object 1,object position x(1)+1, object position y(1), object position z(1)
endif
If LEFTKEY() = 1
ObjX# = ObjX# - 1
position object 1,object position x(1)-1, object position y(1), object position z(1)
endif
`Check Limits of the Door's Rotation
`-------------------------------------------------------
IF direction = 0 AND DoorAngle > 90 THEN direction = 1
IF direction = 1 AND DoorAngle < 0 THEN direction = 0
`Mode 0 - Not using orbiting
`-------------------------------------------------------
IF mode = 0
IF direction = 0
DoorAngle = DoorAngle + 1
ENDIF
IF direction = 1
DoorAngle = DoorAngle - 1
ENDIF
YROTATE OBJECT 1,DoorAngle
ENDIF
`Mode 1 - Orbiting Door from Left Side
`-------------------------------------------------------
IF mode = 1
`Setup EZrotate with object's current rotation
EZro_SetEuler OBJECT ANGLE X(1),OBJECT ANGLE Y(1),OBJECT ANGLE Z(1)
`Setup EZrotate with object's current position
EZro_SetPos OBJECT POSITION X(1),OBJECT POSITION Y(1),OBJECT POSITION Z(1)
EZro_Orbit 1,ObjX#,ObjY#,ObjZ#,ObjX#,ObjY#+1,ObjZ#,1
`CALCULATE new Euler angles for object
EZro_FindEuler
`Apply new Rotation to Object
ROTATE OBJECT 1,EZro_GetEulerX(),EZro_GetEulerY(),EZro_GetEulerZ()
`Apply new Position to Object
POSITION OBJECT 1,EZro_GetPosX(),EZro_GetPosY(),EZro_GetPosZ()
ENDIF
`Mode 2 - Orbiting Door from Right Side
`-------------------------------------------------------
IF mode = 2
`Setup EZrotate with object's current rotation
EZro_SetEuler OBJECT ANGLE X(1),OBJECT ANGLE Y(1),OBJECT ANGLE Z(1)
`Setup EZrotate with object's current position
EZro_SetPos OBJECT POSITION X(1),OBJECT POSITION Y(1),OBJECT POSITION Z(1)
`Orbit Object on Left Side of Door
IF direction = 0
EZro_Orbit 1,2.5,0,0,2.5,10,0,1
DoorAngle = DoorAngle + 1
ENDIF
IF direction = 1
EZro_Orbit 1,2.5,0,0,2.5,10,0,-1
DoorAngle = DoorAngle - 1
ENDIF
`CALCULATE new Euler angles for object
EZro_FindEuler
`Apply new Rotation to Object
ROTATE OBJECT 1,EZro_GetEulerX(),EZro_GetEulerY(),EZro_GetEulerZ()
`Apply new Position to Object
POSITION OBJECT 1,EZro_GetPosX(),EZro_GetPosY(),EZro_GetPosZ()
ENDIF
`Mode 3 - Orbiting Door from Bottom
`-------------------------------------------------------
IF mode = 3
`Setup EZrotate with object's current rotation
EZro_SetEuler OBJECT ANGLE X(1),OBJECT ANGLE Y(1),OBJECT ANGLE Z(1)
`Setup EZrotate with object's current position
EZro_SetPos OBJECT POSITION X(1),OBJECT POSITION Y(1),OBJECT POSITION Z(1)
`Orbit Object on Left Side of Door
IF direction = 0
EZro_Orbit 1,-2.5,0,0,2.5,0,0,1
DoorAngle = DoorAngle + 1
ENDIF
IF direction = 1
EZro_Orbit 1,-2.5,0,0,2.5,0,0,-1
DoorAngle = DoorAngle - 1
ENDIF
`CALCULATE new Euler angles for object
EZro_FindEuler
`Apply new Rotation to Object
ROTATE OBJECT 1,EZro_GetEulerX(),EZro_GetEulerY(),EZro_GetEulerZ()
`Apply new Position to Object
POSITION OBJECT 1,EZro_GetPosX(),EZro_GetPosY(),EZro_GetPosZ()
ENDIF
position object 100, OBJECT POSITION X(1),OBJECT POSITION Y(1),OBJECT POSITION Z(1)
position object 101, ObjX#,ObjY#,ObjZ#
position object 102, ObjX#,ObjY#+1,ObjZ#
`Orbit Command Reference:
`EZro_Orbit RotateFlag,P1x#,P1y#,P1z#,P2x#,P2y#,P2z#,angle#
`--------------------------------------------------------------------------------------
`RotateFlag: If set to 0 then Object will not rotate as it moves around the orbit axis
` If set to 1 then Object will rotate as it moves around the orbit axis
`P1x#,P1y#,P1z#: The XYZ coordinates of the first point in the orbit axis
`P2x#,P2y#,P2z#: The XYZ coordinates of the second point in the orbit axis
`angle#: The amount (in degrees) that you want your object to orbit
SET CURSOR 0,0
PRINT "EZ-Rotate Enhanced"
PRINT "Features Demo 3: Orbiting"
PRINT "By: Ron Erickson"
PRINT "visit: www.ericksonline.com"
PRINT "-------------------------------------------------------------------"
PRINT "This Demo illustrates how you can use the ORBITING feature of"
PRINT "EZrotate to rotate an object around any base. You are no longer"
PRINT "limited to only rotating objects around it's origin."
PRINT "-------------------------------------------------------------------"
IF mode = 0
PRINT "By default, the origin of this door object is at it's center."
PRINT "When the door is rotated, it will rotate around that point."
ENDIF
IF mode <> 0
PRINT "Using the ORBIT feature of EZrotate allows you to easily rotate"
PRINT "your object around any point!"
ENDIF
IF mode < 3
PRINT "Press SPACEBAR to continue ->"
ENDIF
IF mode = 3
PRINT "Press ESCAPE to Quit"
ENDIF
SYNC
LOOP
Now, this is only really in effect while you are in Mode 1. Anyway, to help visualize the problem, I have added 3 spheres. Sphere 100 (colored red) is being positioned at the door's origin. The two other spheres are used to describe the rotation axis. As you press the arrow keys, the entire arrangement will now move around.
I hope this helps!
-Ron