summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2013-02-21 12:26:01 +0100
committerPiotr Dziwinski <piotrdz@gmail.com>2013-02-21 12:26:01 +0100
commit64af5f5be0a93bce40f7196760a5976145810e1e (patch)
tree6d6ea112a69a213b1dd137ce396729dd5c8068c8
parentc42515927e7e249574daeab680b73248a0a5c2e2 (diff)
downloadcolobot-64af5f5be0a93bce40f7196760a5976145810e1e.tar.gz
colobot-64af5f5be0a93bce40f7196760a5976145810e1e.tar.bz2
colobot-64af5f5be0a93bce40f7196760a5976145810e1e.zip
Reverted RotateAngle to old formula
This should solve incontinuities in angle calculations, possibly fixing the "teleportation bug"
-rw-r--r--src/math/geometry.h33
1 files changed, 26 insertions, 7 deletions
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