summaryrefslogtreecommitdiffstats
path: root/src/math/geometry.h
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2013-03-30 15:01:00 +0100
committerPiotr Dziwinski <piotrdz@gmail.com>2013-03-30 15:23:05 +0100
commite218dcfdf2c58f8841e7ebd220527d08e870a6d5 (patch)
treea567db04a8a51e2db87f80e259faf222a7d4becd /src/math/geometry.h
parentbfc701e286259d9a7aa2ff8240704eab2ba3a237 (diff)
parente607fed265070be8c518d4302d8b76f738421fb3 (diff)
downloadcolobot-e218dcfdf2c58f8841e7ebd220527d08e870a6d5.tar.gz
colobot-e218dcfdf2c58f8841e7ebd220527d08e870a6d5.tar.bz2
colobot-e218dcfdf2c58f8841e7ebd220527d08e870a6d5.zip
Merge branch 'dev'
Merging content from dev
Diffstat (limited to 'src/math/geometry.h')
-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