Commit 73414257 authored by hybrid's avatar hybrid

Fix NAN error in getAngle of vector2d, patch by Rocko Bonaparte

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@3743 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 5a7032e4
...@@ -213,24 +213,23 @@ public: ...@@ -213,24 +213,23 @@ public:
return Y < 0 ? 90 : 270; return Y < 0 ? 90 : 270;
// don't use getLength here to avoid precision loss with s32 vectors // don't use getLength here to avoid precision loss with s32 vectors
f64 tmp = Y / sqrt((f64)(X*X + Y*Y)); // avoid floating-point trouble as sqrt(y*y) is occasionally larger than y, so clamp
if ( tmp > 1.0 ) // avoid floating-point trouble as sqrt(y*y) is occasionally larger y const f64 tmp = core::clamp(Y / sqrt((f64)(X*X + Y*Y)), -1.0, 1.0);
tmp = 1.0; const f64 angle = atan( core::squareroot(1 - tmp*tmp) / tmp) * RADTODEG64;
tmp = atan( core::squareroot(1 - tmp*tmp) / tmp) * RADTODEG64;
if (X>0 && Y>0) if (X>0 && Y>0)
return tmp + 270; return angle + 270;
else else
if (X>0 && Y<0) if (X>0 && Y<0)
return tmp + 90; return angle + 90;
else else
if (X<0 && Y<0) if (X<0 && Y<0)
return 90 - tmp; return 90 - angle;
else else
if (X<0 && Y>0) if (X<0 && Y>0)
return 270 - tmp; return 270 - angle;
return tmp; return angle;
} }
//! Calculates the angle between this vector and another one in degree. //! Calculates the angle between this vector and another one in degree.
......
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