Commit a78dda33 authored by hybrid's avatar hybrid

Fix getRotation to handle matrices with scale

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2842 dfc29bdd-3216-0410-991c-e03cc46cb475
parent d905e243
......@@ -848,34 +848,36 @@ namespace core
inline core::vector3d<T> CMatrix4<T>::getRotationDegrees() const
{
const CMatrix4<T> &mat = *this;
const core::vector3d<T> scale = getScale();
const core::vector3d<f64> invScale(core::reciprocal(scale.X),core::reciprocal(scale.Y),core::reciprocal(scale.Z));
f64 Y = -asin(mat(0,2));
f64 Y = -asin(mat[2]*invScale.X);
const f64 C = cos(Y);
Y *= RADTODEG64;
f64 rotx, roty, X, Z;
if (fabs(C)>ROUNDING_ERROR_f64)
if (!core::iszero(C))
{
const T invC = (T)(1.0/C);
rotx = mat(2,2) * invC;
roty = mat(1,2) * invC;
const f64 invC = core::reciprocal(C);
rotx = mat[10] * invC * invScale.Z;
roty = mat[6] * invC * invScale.Y;
X = atan2( roty, rotx ) * RADTODEG64;
rotx = mat(0,0) * invC;
roty = mat(0,1) * invC;
rotx = mat[0] * invC * invScale.X;
roty = mat[1] * invC * invScale.X;
Z = atan2( roty, rotx ) * RADTODEG64;
}
else
{
X = 0.0;
rotx = mat(1,1);
roty = -mat(1,0);
rotx = mat[5] * invScale.Y;
roty = -mat[4] * invScale.Y;
Z = atan2( roty, rotx ) * RADTODEG64;
}
// fix values that get below zero
// before it would set (!) values to 360
// that where above 360:
// that were above 360:
if (X < 0.0) X += 360.0;
if (Y < 0.0) Y += 360.0;
if (Z < 0.0) Z += 360.0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment