From 64af5f5be0a93bce40f7196760a5976145810e1e Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 21 Feb 2013 12:26:01 +0100 Subject: Reverted RotateAngle to old formula This should solve incontinuities in angle calculations, possibly fixing the "teleportation bug" --- src/math/geometry.h | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src/math/geometry.h') diff --git a/src/math/geometry.h b/src/math/geometry.h index ee6fc52..23c149c 100644 --- a/src/math/geometry.h +++ b/src/math/geometry.h @@ -197,15 +197,34 @@ inline void RotatePoint2(const Math::Vector center, float angleH, float angleV, //! Returns the angle between point (x,y) and (0,0) inline float RotateAngle(float x, float y) { - if ( (x == 0.0f) && (y == 0.0f) ) - return 0.0f; + if (x == 0.0f && y == 0.0f) return 0.0f; - float atan = atan2(x, y); - - if ((y < 0.0f) && (x >= 0.0f)) - return -atan + 2.5f*PI; + if (x >= 0.0f) + { + if (y >= 0.0f) + { + if (x > y) return atanf(y/x); + else return PI*0.5f - atanf(x/y); + } + else + { + if (x > -y) return PI*2.0f + atanf(y/x); + else return PI*1.5f - atanf(x/y); + } + } else - return -atan + 0.5f*PI; + { + if (y >= 0.0f) + { + if (-x > y) return PI*1.0f + atanf(y/x); + else return PI*0.5f - atanf(x/y); + } + else + { + if (-x > -y) return PI*1.0f + atanf(y/x); + else return PI*1.5f - atanf(x/y); + } + } } //! Calculates the angle between two points and a center -- cgit v1.2.3-1-g7c22