Need bulletproof angle extraction from matrix!

Blitz3D Forums/Blitz3D Programming/Need bulletproof angle extraction from matrix!

Hi,

In my effort to write a 3ds importer I've really hit the head on the wall! I can't seem to find any method of extracting Euler angles from the transformation matrix that is 100% bulletproof. The one I'm currently using, is the closest I've come, it looks like this:
xrot# = ASin(-m(1,2))
If xrot<90.0
	If xrot>-90.0
		zrot# = ATan2(m(0,2),m(2,2))
		yrot# = -ATan2(m(1,0),m(1,1))
	Else
		zrot# = -ATan2(-m(0,1),m(0,0))
		yrot# = 0.0
	End If
Else
	zrot# = ATan2(-m(0,1),m(0,0))
	yrot# = 0.0				
End If

It produces the exact same angles as Blitz' LoadAnimMesh command, but at 90 and -90 degrees Pitch (xrot), it utterly fails, if one of the other axes have been rotated. It's a real pain, so if anyone has got a solution ( Mark ? :) ), I would really appreciate it! Perhaps it's possible to do some sneaky align to vector stuff???

PS: it's a 3x3 rotation+scale matrix, that has been unified.

Fredborg