Commit c11c87f2 authored by hybrid's avatar hybrid

Fix getRotationDegrees in matrix class as noted by drewbacca

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3400 dfc29bdd-3216-0410-991c-e03cc46cb475
parent e08e256f
...@@ -778,11 +778,11 @@ namespace core ...@@ -778,11 +778,11 @@ namespace core
} }
//! Returns the absolute values of the scales of the matrix. //! Returns the absolute values of the scales of the matrix.
/** /**
Note that this always returns the absolute (positive) values. Unfortunately it Note that this returns the absolute (positive) values unless only scale is set.
does not appear to be possible to extract any original negative values. The best Unfortunately it does not appear to be possible to extract any original negative
that we could do would be to arbitrarily make one scale negative if one or three values. The best that we could do would be to arbitrarily make one scale
of them were negative. negative if one or three of them were negative.
FIXME - return the original values. FIXME - return the original values.
*/ */
template <class T> template <class T>
...@@ -854,7 +854,23 @@ namespace core ...@@ -854,7 +854,23 @@ namespace core
inline core::vector3d<T> CMatrix4<T>::getRotationDegrees() const inline core::vector3d<T> CMatrix4<T>::getRotationDegrees() const
{ {
const CMatrix4<T> &mat = *this; const CMatrix4<T> &mat = *this;
const core::vector3d<T> scale = getScale(); core::vector3d<T> scale = getScale();
// we need to check for negative scale on to axes, which would bring up wrong results
if (scale.Y<0 && scale.Z<0)
{
scale.Y =-scale.Y;
scale.Z =-scale.Z;
}
else if (scale.X<0 && scale.Z<0)
{
scale.X =-scale.X;
scale.Z =-scale.Z;
}
else if (scale.X<0 && scale.Y<0)
{
scale.X =-scale.X;
scale.Y =-scale.Y;
}
const core::vector3d<f64> invScale(core::reciprocal(scale.X),core::reciprocal(scale.Y),core::reciprocal(scale.Z)); const core::vector3d<f64> invScale(core::reciprocal(scale.X),core::reciprocal(scale.Y),core::reciprocal(scale.Z));
f64 Y = -asin(core::clamp(mat[2]*invScale.X, -1.0, 1.0)); f64 Y = -asin(core::clamp(mat[2]*invScale.X, -1.0, 1.0));
...@@ -882,8 +898,6 @@ namespace core ...@@ -882,8 +898,6 @@ namespace core
} }
// fix values that get below zero // fix values that get below zero
// before it would set (!) values to 360
// that were above 360:
if (X < 0.0) X += 360.0; if (X < 0.0) X += 360.0;
if (Y < 0.0) Y += 360.0; if (Y < 0.0) Y += 360.0;
if (Z < 0.0) Z += 360.0; if (Z < 0.0) Z += 360.0;
......
...@@ -175,6 +175,20 @@ bool rotations(void) ...@@ -175,6 +175,20 @@ bool rotations(void)
result &= (vec1.equals(core::vector3df(27.5400505f, 34.4302292f, 42.6845398f), 0.000002f)); result &= (vec1.equals(core::vector3df(27.5400505f, 34.4302292f, 42.6845398f), 0.000002f));
assert(result); assert(result);
// corner cases
rot1.setRotationDegrees(irr::core::vector3df(180.0f, 0.f, 0.f));
vec1=rot1.getRotationDegrees();
result &= (vec1.equals(core::vector3df(180.0f, 0.f, 0.f), 0.000002f));
assert(result);
rot1.setRotationDegrees(irr::core::vector3df(0.f, 180.0f, 0.f));
vec1=rot1.getRotationDegrees();
result &= (vec1.equals(core::vector3df(180.0f, 360, 180.0f), 0.000002f));
assert(result);
rot1.setRotationDegrees(irr::core::vector3df(0.f, 0.f, 180.0f));
vec1=rot1.getRotationDegrees();
result &= (vec1.equals(core::vector3df(0.f, 0.f, 180.0f), 0.000002f));
assert(result);
return result; return result;
} }
......
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