DarkGuy,
I have here for you a relic of most ancient glory, dug up from the black ashes of Apollo's past. In side the code box below you will find a power to wield all the forces of Euler and Cartesian with the might of a thousand horses, and the wit of a thousand scholars. Simply copy-paste-run, and you will see the power lies in the order and the system.
Here, in all its ASCII glory, The Rosetta Stone of DBC Rotation:
Rem * Title : Rotation Tutorial
Rem * Original Author : Simon Harrison ( Si) Date : 18th July 2000
Rem *
rem David Lawrence ( muddleglum) November 2002
rem Added matrix, mouse click functioning, new rotation, 'plane' object to give sense of direction,
rem Also, more explanation.
rem Feel free anyone, to add to this information ( and tell me)> [email protected]
set display mode 640,480,16
set text size 17:rem this is for Db pro only
sync on
sync rate 30
cls RGB(20,128,164)
ink RGB(35,118,140),0
box 0,0,8,8
box 8,8,16,16
GET IMAGE 1,0,0,16,16
cls 0
make matrix 1,16,16,10,10
position matrix 1,-7,-1.5,-1
PREPARE MATRIX TEXTURE 1, 1,1,1
backdrop off
gosub makeplane
autocam off
position camera 0,.5,-3
fog on
fog distance 12
do
`cls 0
set cursor 0,0
ink rgb(255,255,255),0
print " DEMO OF ROTATIONS. Should work with DB versions 1.08 to 1.13"
print " - But NOT DB PRO, until some rotations are corrected -- perhaps patch 4 ++ !"
print " < Left click on desired rotation system "
print "1. X Y Z order of Rotation calculation"
print "2. Z Y X order of Rotation calculation"
print "3. Fix Object Pivot"
print "4. Free Flight Rotation"
print "5. Modified Free Flight (= Y X Z)"
print "6. Simon's Original Notes"
print " "
ink RGB(255,128,128),0
Text 0, 350, " NOTE. Though I have suggested the simplest"
text 0, 365, "use of these rotations, skilled people should"
text 0, 380, " be able to do more through mathematical"
text 0, 395, "manipulation or sheer cunning .. aligning with "
text 0, 410, "dummy (zeroed or rotated) hidden objects, etc."
`mouse select
mx=mousex()
my=mousey()
if mouseclick()=1
if mx < 240
if my>48 and my<64 then gosub xyz:cls 0
if my>64 and my<81 then gosub zyx:cls 0
if my>81 and my<95 then gosub fixpivot:cls 0
if my>95 and my<111 then gosub freeflight:cls 0
if my>111 and my<128 then gosub modfreeflight:cls 0
if my>128 and my<144 then gosub info:cls 0
endif
endif
sync
loop
rem SUB-ROUTINE**************************************************************
rem XYZ ROTATION
xyz:
backdrop on
color backdrop 0
make object cylinder 2,1 : color object 2,rgb(255,0,0)
zrotate object 2,90
fix object pivot 2
scale object 2,200,10,10
make object cylinder 3,1
scale object 3,10,200,10
color object 3,rgb(0,255,0)
make object cylinder 4,1 : color object 4,rgb(255,255,0)
xrotate object 4,90
fix object pivot 4
scale object 4,10,10,200
xang=0
yang=0
zang=0
repeat
set cursor 0,400
ink rgb(255,0,0),0 : print "X-Axis: Up/Down Cursor Keys"
ink rgb(0,255,0),0 : print "Y-Axis: Left/Right Cursor Keys"
ink rgb(255,255,0),0 : print "Z-Axis: Shift/Ctrl Keys"
ink rgb(255,255,255),0 : text 0,120,"RIGHT Click to Return to Main Screen"
text 0,370," Return Key to reset to zero rotation"
set cursor 0,0
if upkey()=1 then inc xang : ink rgb(255,0,0),0 : print "X ROTATE OBJECT 1,";wrapvalue(xang)
if downkey()=1 then dec xang : ink rgb(255,0,0),0 : print "X ROTATE OBJECT 1,";wrapvalue(xang)
if rightkey()=1 then inc yang : ink rgb(0,255,0),0 : print "Y ROTATE OBJECT 1,";wrapvalue(yang)
if leftkey()=1 then dec yang : ink rgb(0,255,0),0 : print "Y ROTATE OBJECT 1,";wrapvalue(yang)
if shiftkey()=1 then inc zang : ink rgb(255,255,0),0 : print "Z ROTATE OBJECT 1,";wrapvalue(zang)
if controlkey()=1 then dec zang : ink rgb(255,255,0),0 : print "Z ROTATE OBJECT 1,";wrapvalue(zang)
ink rgb(255,255,255),0
text 255,0, " XYZ ROTATION"
set cursor 0,20
print "The x rotation axis, red, the first, is permanently fixed in relation to the world coord system."
print "The y rotation axis, green, is built on, and only affected by changes in the previous x rotation axis."
print "The z rotation axis, yellow, is affected by both others, giving therefore, object related rotation."
print "Simplest use of this order, would be in changing object direction and then rolling - but note"
print "how the DB tank demo uses this rotation with a glued object as a limb to match the ground slope."
ink RGB(255,128,128),0
Text 350, 380, "From the objects point of view, Z rotation"
text 350, 395, "affects only the object. Y rotation affects"
text 350, 410, "the object and the Z axis. Rotating X affects"
text 350, 425, "object and Y, Z axes. For use, it is perhaps "
text 350, 440, "more practical to see it as at top."
if returnkey()=1
xang=0:yang=0: zang=0
endif
rem Rotate cube
xrotate object 1,wrapvalue(xang)
yrotate object 1,wrapvalue(yang)
zrotate object 1,wrapvalue(zang)
xrotate object 3,wrapvalue(xang)
yrotate object 3,wrapvalue(yang)
xrotate object 4,wrapvalue(xang)
yrotate object 4,wrapvalue(yang)
zrotate object 4,wrapvalue(zang)
sync
until mouseclick()=2
rotate object 1,0,0,0
delete object 2
delete object 3
delete object 4
backdrop off
return
rem SUB-ROUTINE**************************************************************
rem ZYX ROTATION
zyx:
backdrop on
color backdrop 0
make object cylinder 2,1 : color object 2,rgb(255,0,0)
zrotate object 2,90
fix object pivot 2
scale object 2,200,10,10
make object cylinder 3,1
scale object 3,10,200,10
color object 3,rgb(0,255,0)
make object cylinder 4,1 : color object 4,rgb(255,255,0)
xrotate object 4,90
fix object pivot 4
scale object 4,10,10,200
set object rotation zyx 1
set object rotation zyx 2
set object rotation zyx 3
set object rotation zyx 4
xang=0
yang=0
zang=0
repeat
set cursor 0,400
ink rgb(255,0,0),0 : print "X-Axis: Up/Down Cursor Keys"
ink rgb(0,255,0),0 : print "Y-Axis: Left/Right Cursor Keys"
ink rgb(255,255,0),0 : print "Z-Axis: Shift/Ctrl Keys"
ink rgb(255,255,255),0 : text 0,100,"RIGHT Click to Return to Main Screen"
text 0,370," Return Key to reset to zero rotation"
set cursor 0,0
if upkey()=1 then inc xang : ink rgb(255,0,0),0 : print "X ROTATE OBJECT 1,";wrapvalue(xang)
if downkey()=1 then dec xang : ink rgb(255,0,0),0 : print "X ROTATE OBJECT 1,";wrapvalue(xang)
if rightkey()=1 then inc yang : ink rgb(0,255,0),0 : print "Y ROTATE OBJECT 1,";wrapvalue(yang)
if leftkey()=1 then dec yang : ink rgb(0,255,0),0 : print "Y ROTATE OBJECT 1,";wrapvalue(yang)
if shiftkey()=1 then inc zang : ink rgb(255,255,0),0 : print "Z ROTATE OBJECT 1,";wrapvalue(zang)
if controlkey()=1 then dec zang : ink rgb(255,255,0),0 : print "Z ROTATE OBJECT 1,";wrapvalue(zang)
ink rgb(255,255,255),0
text 255,0, " ZYX ROTATION"
set cursor 0,20
print "The z rotation axis, yellow, the first, is permanently fixed in relation to the world coord system."
print "The y rotation axis, green, is built on, and only affected by changes in the previous z rotation axis."
print "The x rotation axis, red, is affected by both others, giving therefore, object related rotation."
print "Simplest use of this order would be changing object direction and then pitching up or down."
ink RGB(255,128,128),0
Text 350, 380, "From the objects point of view, X rotation"
text 350, 395, "affects only the object. Y rotation affects"
text 350, 410, "the object and the X axis. Rotating Z affects"
text 350, 425, "object and Y, X axes. For use, it is perhaps "
text 350, 440, "more practical to see it as at top."
if returnkey()=1
xang=0:yang=0: zang=0
endif
rem Rotate cube
xrotate object 1,wrapvalue(xang)
yrotate object 1,wrapvalue(yang)
zrotate object 1,wrapvalue(zang)
rem Rotate x-axis cylinder
xrotate object 2,wrapvalue(xang)
yrotate object 2,wrapvalue(yang)
zrotate object 2,wrapvalue(zang)
rem Rotate y-axis cylinder
yrotate object 3,wrapvalue(yang)
zrotate object 3,wrapvalue(zang)
sync
until mouseclick()=2
rotate object 1,0,0,0
set object rotation xyz 1
delete object 2
delete object 3
delete object 4
backdrop off
return
rem SUB-ROUTINE**************************************************************
rem FIX OBJECT PIVOT ROTATION
fixpivot:
backdrop on
color backdrop 0
make object cylinder 2,1 : color object 2,rgb(255,0,0)
zrotate object 2,90
fix object pivot 2
scale object 2,200,10,10
make object cylinder 3,1
scale object 3,10,200,10
color object 3,rgb(0,255,0)
make object cylinder 4,1 : color object 4,rgb(255,255,0)
xrotate object 4,90
fix object pivot 4
scale object 4,10,10,200
repeat
set cursor 0,400
ink rgb(255,0,0),0 : print "X-Axis: Up/Down Cursor Keys"
ink rgb(0,255,0),0 : print "Y-Axis: Left/Right Cursor Keys"
ink rgb(255,255,0),0 : print "Z-Axis: Shift/Ctrl Keys"
ink rgb(255,255,255),0 : text 0,80,"RIGHT Click to Return to Main Screen"
set cursor 0,0
if upkey()=1 then xrotate object 1,1 : ink rgb(255,0,0),0 : print "X ROTATE OBJECT 1,1"
if downkey()=1 then xrotate object 1,359 : ink rgb(255,0,0),0 : print "X ROTATE OBJECT 1,359"
if rightkey()=1 then yrotate object 1,1 : ink rgb(0,255,0),0 : print "Y ROTATE OBJECT 1,1"
if leftkey()=1 then yrotate object 1,359 : ink rgb(0,255,0),0 : print "Y ROTATE OBJECT 1,359"
if shiftkey()=1 then zrotate object 1,1 : ink rgb(255,255,0),0 : print "Z ROTATE OBJECT 1,1"
if controlkey()=1 then zrotate object 1,359 : ink rgb(255,255,0),0 : print "Z ROTATE OBJECT 1,359"
fix object pivot 1 : ink rgb(255,255,255),0 : text 220,0, "FIX OBJECT PIVOT, ROTATION"
ink rgb(255,255,255),0
set cursor 0,40
print "All axes remain in the original alignment with the world coord system."
print " I can't see very much use for this myself! For effects perhaps."
sync
until mouseclick()=2
delete object 2
delete object 3
delete object 4
delete object 1
gosub makeplane
backdrop off
return
rem SUB-ROUTINE**************************************************************
rem FREE FLIGHT ROTATION
freeflight:
backdrop on
color backdrop 0
`make object box 12,.3,.2,1.2
`position object 12, -1,0,0
`set object rotation zyx 12
make object cylinder 2,1 : color object 2,rgb(255,0,0)
zrotate object 2,90
fix object pivot 2
scale object 2,200,10,10
make object cylinder 3,1
scale object 3,10,200,10
color object 3,rgb(0,255,0)
make object cylinder 4,1 : color object 4,rgb(255,255,0)
xrotate object 4,90
fix object pivot 4
scale object 4,10,10,200
repeat
set cursor 0,400
ink rgb(255,0,0),0 : print "X-Axis: Up/Down Cursor Keys"
ink rgb(0,255,0),0 : print "Y-Axis: Left/Right Cursor Keys"
ink rgb(255,255,0),0 : print "Z-Axis: Shift/Ctrl Keys"
ink rgb(255,255,255),0 : text 0,80,"RIGHT Click to Return to Main Screen"
text 0,370," Return Key to reset to zero rotation"
set cursor 0,0
if leftkey()=1
turn object left 1,1
turn object left 2,1
turn object left 3,1
turn object left 4,1
ink rgb(0,255,0),0 : print "TURN OBJECT LEFT 1,1"
endif
if rightkey()=1
turn object right 1,1
turn object right 2,1
turn object right 3,1
turn object right 4,1
ink rgb(0,255,0),0 : print "TURN OBJECT RIGHT 1,1"
endif
if downkey()=1
pitch object up 1,1.0
pitch object up 2,1.0
pitch object up 3,1.0
pitch object up 4,1.0
ink rgb(255,0,0),0 : print "PITCH OBJECT UP 1,1"
endif
if upkey()=1
pitch object down 1,1.0
pitch object down 2,1.0
pitch object down 3,1.0
pitch object down 4,1.0
ink rgb(255,0,0),0 : print "PITCH OBJECT DOWN 1,1"
endif
if shiftkey()=1
roll object left 1,1.0
roll object left 2,1.0
roll object left 3,1.0
roll object left 4,1.0
ink rgb(255,255,0),0 : print "ROLL OBJECT LEFT 1,1"
endif
if controlkey()=1
roll object right 1,1.0
roll object right 2,1.0
roll object right 3,1.0
roll object right 4,1.0
ink rgb(255,255,0),0 : print "ROLL OBJECT RIGHT 1,1"
endif
ink rgb(245,245,245),0
set cursor 470,200: print "W direction= " ;limb direction y(1,0)
set cursor 470,230: print "sinepitch= " ;sin(limb direction x(1,0))
rem Cheat method can be used for pitch as well - see below
`alt#=object position y(1)
` move object 1,1
`set cursor 470,230: print "sinepitch= " ; alt#-object position y(1)
` move object 1,1*-1
turn object right 1,90
move object 1,1
set cursor 470,260: print "sineroll= " ; object position y(1)- alt#
move object 1,1*-1
turn object left 1,90:rem back to original position and direction
rem End cheat method
text 236,0, "FREE FLIGHT ROTATION"
set cursor 0,20
print "All axes rotate with the object. Any new change is always relative to the objects current rotation."
print " Ideal for representing reaction of aircraft to controls."
print " It can also represent the transfer of flight forces as angular change in forward movement."
ink RGB(255,128,128),0
text 348,150, "What is this weird 'sinpitch' if you roll at zero"
text 350,170, "pitch? Never noticed it in my working sims. "
Text 340, 350, "To use free flight one may need a return of the "
text 340, 365, "curent x,y,z angles.Versions vary. The latest"
text 340, 380, "1.13, returns x y and z values which will set"
text 340, 395, "another object the same, when it uses zyx"
text 340, 410, "rotation. I have included here a 'cheat'"
text 340, 425, "method which gives angles RELATED TO "
text 340, 440, " WORLD VERTICAL, as needed for a flight sim."
text 340, 455, "(I use them mostly as a sine of the angle)."
`rotate object 12, object angle x(1), object angle y(1), object angle z(1)
if returnkey()=1
rotate object 1,0,0,0
rotate object 2,0,0,0
rotate object 3,0,0,0
rotate object 4,0,0,0
endif
sync
until mouseclick()=2
rotate object 1,0,0,0
delete object 2
delete object 3
delete object 4
`delete object 12
backdrop off
return
rem SUB-ROUTINE**************************************************************
info:
backdrop on
color backdrop 0
set cursor 0,0
ink rgb(255,255,255),0
repeat
text 200,0, " SIMON'S ORIGINAL NOTES"
text 0, 40, "XYZ ROTATION"
text 0,55, "X Rotation is always global"
text 0,70, "Y Rotation is local if you rotate x, global if you rotate z"
text 0,85, "Z Rotation is always local"
text 0,110, "ZYX ROTATION"
text 0,125, "X Rotation is always local"
text 0,140, "Y Rotation is global if you rotate x, local if you rotate z"
text 0,155, "Z Rotation is always global"
text 0,180, "FIX OBJECT PIVOT"
text 0, 195, "All rotations are global"
text 0, 210, " "
text 0, 230, "FREE FLIGHT ROTATION"
text 0, 245, "All rotations are local"
text 0,300,"RIGHT Click to Return to Main Screen"
sync
until mouseclick()=2
backdrop off
return
` -----------------------------------------------------------------------
modfreeflight:
backdrop on
color backdrop 0
turn=0
pitch=0
roll=0
make object cylinder 2,1 : color object 2,rgb(255,0,0)
zrotate object 2,90
fix object pivot 2
scale object 2,200,10,10
make object cylinder 3,1
scale object 3,10,200,10
color object 3,rgb(0,255,0)
make object cylinder 4,1 : color object 4,rgb(255,255,0)
xrotate object 4,90
fix object pivot 4
scale object 4,10,10,200
repeat
set cursor 0,400
ink rgb(255,0,0),0 : print "X-Axis: Up/Down Cursor Keys"
ink rgb(0,255,0),0 : print "Y-Axis: Left/Right Cursor Keys"
ink rgb(255,255,0),0 : print "Z-Axis: Shift/Ctrl Keys"
ink rgb(255,255,255),0 : text 0,130,"RIGHT Click to Return to Main Screen"
text 0,370," Return Key to reset to zero rotation"
set cursor 0,0
if leftkey()=1 then turn=wrapvalue(turn-1): ink rgb(0,255,0),0 : print "DIRECTION ANGLE = "; turn
if rightkey()=1 then turn=wrapvalue(turn+1):ink rgb(0,255,0),0 : print "DIRECTION ANGLE = "; turn
if downkey()=1 then pitch=wrapvalue( pitch -1):ink rgb(255,0,0),0 : print "PITCH ANGLE = ";pitch
if upkey()=1 then pitch=wrapvalue(pitch+1):ink rgb(255,0,0),0 : print "PITCH ANGLE = ";pitch
if shiftkey()=1 then roll = wrapvalue(roll+1):ink rgb(255,255,0),0 : print "ROLL ANGLE = ";roll
if controlkey()=1 then roll = wrapvalue(roll-1):ink rgb(255,255,0),0 : print "ROLL ANGLE = ";roll
rotate object 1,0,0,0: rem In some versions, this may need to be replaced with :-
rem set object to object orientation 1, 2 .... where '2' is a dummy object
rem left at a rotation of 0,0,0'
rem Others have done versions that use a rotating dummy object I think.
turn object right 1,turn
pitch object down 1, pitch
roll object left 1,roll
yrotate object 2, turn
set object to object orientation 4,1
ink rgb(255,255,255),0
text 210,0, "MODIFIED FREE FLIGHT ROTATION"
set cursor 0,20
print "An 'artificial equivalent' to a new standard rotation order of Y X Z."
print "The object may be pointed in any world direction, then pitched up or down, then rolled"
print "freely. Note that the pitch as well as turn, always relates to the world co-ords."
print " This can be a very useful and easily followed rotation system."
print "It can be used to angle a ground travelling object to the ground matrix slope,"
print " or make a simplified flight or helicopter simulation."
if returnkey()=1
turn=0
pitch=0
roll=0
endif
sync
until mouseclick()=2
rotate object 1,0,0,0
delete object 2
delete object 3
delete object 4
backdrop off
return
return
rem *************************************************************************
makeplane:
make object box 2,1.6,.05,.40: rem wing
make mesh from object 1,2
delete object 2
make object box 3,.05,.5,.4: rem tail
make mesh from object 2,3
delete object 3
make object box 1,.3,.2,1.2:rem body
add limb 1,1,1
add limb 1,2,2
OFFSET LIMB 1, 2,0,.2,-.5
position object 1,0,0,0
return
Pass this around to nubs, keeping intact the credits to almighty muddleglum, for he hath done humanity a most noble service.

I'm going to eat you!