问题
Here are my axes. i dont know what to call it. (is it ZXY?) (this is what camera sees)

i want to know plane rotation around Y axis. Currently it is 0 degree around Y.
here is what i do,
Matrix33 orientmatrix = body->getGlobalOrientation();
return Degree(-asin(orientmatrix[2][0]));
this returns incorrect angles, in counterclockwise: 0..45..90..45..0..-45..-90..-45..0
it should be: 0...45..90..135..180..-45..-90..-135..0
what am i doing wrong?
thank you.
(this is OGRE, code is C++)
回答1:
What you are doing wrong is that you are using asin
. It returns a value between -pi/2 to +pi/2, or -90 degrees to +90 degrees.
If you want a value that spans 360 degrees you need to be using atan2
. Assuming your orientation truly is a rotation about y, you could use
Degree(atan2(orientmatrix[0][2], orientmatrix[0][0]))
来源:https://stackoverflow.com/questions/10971558/y-rotation-from-rotation-matrix