OOH I know this one! let me dig up the code...
[edit]
arrgghhh can't find it... Basically, first you have your object in its own space, that is at position <x,y,z>, with angle <a,b,c>. So using x/y/z and a/b/c, construct the 4 by 4 matrix defining the objects position. Call this matrix A.
Now, construct a matrix that transforms the object's space into world space. Call this matrix B.
Now have a matrix C, C=B*A
wait, no, scratch that explanation, I found the post!!!
http://www.youtube.com/watch?v=A-UTPKL-UGY&feature=grec_index
type vect2
x as float
y as float
z as float
endtype
global ret as vect2
global retAngle as vect2
autocam off
make object box 1,10,.1,10
position object 1,0,0,0
make object box 2,1,2,.5
ChildPos as vect2
ChildAng as vect2
ChildPos.x=rnd(10)-5
ChildPos.y=1
ChildPos.z=rnd(10)-5
ChildAng.x=rnd(10)-5
position object 2,ChildPos.x,ChildPos.y,ChildPos.z
sync on
sync rate 30
do
rotate object 1,object angle x(1)+keystate(16)-keystate(30),object angle y(1)+keystate(17)-keystate(31),object angle z(1)+keystate(18)-keystate(32)
if upkey()
inc ChildPos.x,cos(ChildAng.y)*.1
inc ChildPos.z,sin(ChildAng.y)*.1
endif
if downkey()
inc ChildPos.x,-cos(ChildAng.y)*.1
inc ChildPos.z,-sin(ChildAng.y)*.1
endif
inc ChildAng.x,mousemovey()
inc ChildAng.y,mousemovex()
rotate object 2,ChildAng.x,ChildAng.y,ChildAng.z
ParentToChild(1,2,ChildPos)
position object 2,ret.x,ret.y,ret.z
rotate object 2,retAngle.x,retAngle.y,retAngle.z
position camera ret.x,ret.y,ret.z
rotate camera retAngle.x,retAngle.y,retAngle.z
if spacekey()
position camera 10,10,10
point camera 0,0,0
endif
sync
loop
function ParentToChild(Parent as integer, Child as integer, offset as vect2)
null = make matrix4(1)
null = make matrix4(2)
null = make matrix4(3)
null = make vector4(4)
null = make vector4(5)
ObjectRotationMatrix(Parent,1)
ObjectRotationMatrix(Child,2)
set vector4 4,offset.x,offset.y,offset.z,1
transform vector4 5,4,1
ret.x=x vector4(5) : ret.y=y vector4(5) : ret.z=z vector4(5)
multiply matrix4 3,2,1
rotMatrixToEulerAng(3)
null = delete matrix4(1)
null = delete matrix4(2)
null = delete matrix4(3)
null = delete vector4(4)
null = delete vector4(5)
endfunction
function rotMatrixToEulerAng(C as integer)
C31#=M4Element(C,3,1)
C32#=M4Element(C,3,2)
C33#=M4Element(C,3,3)
C21#=M4Element(C,2,1)
C11#=M4Element(C,1,1)
if absolut(C31#)<>1
retAngle.y=-asin(C31#)
retAngle.x=atanfull(C32#/cos(retAngle.y),C33#/cos(retAngle.y))
retAngle.z=atanfull(C21#/cos(retAngle.y),C11#/cos(retAngle.y))
else
retAngle.z=0
retAngle.y=posneg(C31#,90)
retAngle.x=atanfull(posneg(C31#,C13#),posneg(C31#,C13#))
endif
endfunction
function ObjectRotationMatrix(object as integer, mtrx as integer)
null = make matrix4(1000)
null = make matrix4(1001)
null = make matrix4(1002)
rotate x matrix4 1000,object angle x(object)*0.0174532925
rotate y matrix4 1001,object angle y(object)*0.0174532925
multiply matrix4 1002,1000,1001
rotate z matrix4 1000,object angle z(object)*0.0174532925
multiply matrix4 mtrx,1002,1000
null = delete matrix4(1000)
null = delete matrix4(1001)
null = delete matrix4(1002)
endfunction
function posneg(a#,num#)
if a#<0 then exitfunction -num#
if a#>0 then exitfunction num#
endfunction 0.0
function absolut(a#)
if a#>0 then exitfunction a#
a#=-a#
endfunction a#
function M4Element(m4,row,column)
n#=get matrix4 element(m4,(column-1)*4+row-1)
endfunction n#
Quote: "press qwe/asd to change the angle of the plane, mouse to look around, and the up and down arrowkeys to move. You'll notice absolutely nothing special, but press the spacekey to view yourself standing on a plane, rotating around."
uhh I'm not sure if this will actually help you with your problem... but its what you were asking for
the rotMatrixToEulerAng function originates from this matrix:

which is the combination of (rotation around z axis)*(rotation around y axis)*(rotation around x axis) in a left handed coordinate system.
So, that matrix, given three euler angles, equals the rotation matrix passed into the function. So you can pick and choose which ones are easiest to solve for! First you solve for the y angle in the bottom left of the matrix, and then you continue on - with a couple if statements to avoid division by zero screwups and stuff.
[edit]
oh yeah, if your world transformation scales anything, you'll want to normalize the first three columns (it might be a good idea anyways), since the idea of a plain ol' rotation matrix is to have orthogonal unit vectors.