//! Get the euler angles from an OpenGL matrix
// \param m[] - the matrix
// \param rx - [out] the rotation around the x axis
// \param ry - [out] the rotation around the y axis
// \param rz - [out] the rotation around the z axis
FUNCTION EntityGetEulers: mat[], BYREF X, BYREF Y, BYREF Z
// roll = rx
// yaw = ry
// pitch = rz
LOCAL rotx, roty, C
Y = -ASIN(mat[2])
C = COS(Y)
IF ABS(C)>1e-7
LOCAL invC = 1.0/C
rotx = mat[10] * invC
roty = mat[6] * invC
X = ATAN( roty, rotx )
rotx = mat[0] * invC
roty = mat[1] * invC
Z = ATAN( roty, rotx )
ELSE
X = 0.0
rotx = mat[5]
roty = -mat[4]
Z = ATAN( roty, rotx )
ENDIF
ENDFUNCTION