Well... to get euler angles from a rotation matrix:
//uses the algorithm described on this website:
//http://www.gregslabaugh.name/publications/euler.pdf
//I've mirrored it on my site at
//http://www.neurofuzzydev.com/downloads/Papers/rotMatrixToEulerAngles.pdf
function rotMatrixToEulerAng(C as integer)
C31#=M4Element(C,1,3) //transposed
C32#=M4Element(C,2,3)
C33#=M4Element(C,3,3)
C21#=M4Element(C,1,2)
C11#=M4Element(C,1,1)
C12#=M4Element(C,2,1)
C13#=M4Element(C,3,1)
if absolut(C31#)<>1
ret_y=-asin(C31#)
ret_x=atanfull(C32#/cos(ret_y),C33#/cos(ret_y))
ret_z=atanfull(C21#/cos(ret_y),C11#/cos(ret_y))
else
ret_z=0
if C31#=-1
ret_y=90
ret_x=atanfull(C12#,C13#)
else
ret_y=270
ret_x=atanfull(-C12#,-C13#)
endif
endif
endfunction
function absolut(n as float)
if n>0 then exitfunction n
n=-n
endfunction n
//gets an element of a 4x4 matrix.
function M4Element(m4,row,column)
n#=get matrix4 element(m4,column-1+(row-1)*4)
endfunction n#
So this is similar to a part of the problem in your other question. Where A is the up vector of your camera and B is the forward vector of your camera, you have the square rotation matrix:
using the cross product and guess and check thing I described in the other thread, we can see that the matrix you want to insert into the function is:
[A.y*B.z-A.z*B.y A.x B.x ]
[A.z*B.x-A.x*B.z A.y B.y ]
[A.x*B.y-A.y*B.x A.z B.z ]
To use that matrix in my above code, ianM's utils has a function called setmatrix. Either use that, or edit the function so that all the variables are set correctly. The variable setting part of the first function transposes the matrix and sets needed values in one fell swoop. So:
C31#=B.x (row 1 column 3 of the above matrix, indexed from 0 unlike in my notation)
C32#=B.y
C33#=B.z
C21#=A.x
C11#=A.y*B.z-A.z*B.y
C12#=A.z*B.x-A.x*B.z
C13#=A.x*B.y-A.y*B.x
I might be wrong, but those values should work.
In the two solutions i posted for you... I think they're correct, but there might be a typo in there somewhere. Typos are hard to avoid when editing plaintext to do math...
Why does blue text appear every time you are near?