diff options
author | Piotr Dziwinski <piotrdz@gmail.com> | 2013-03-30 15:01:00 +0100 |
---|---|---|
committer | Piotr Dziwinski <piotrdz@gmail.com> | 2013-03-30 15:23:05 +0100 |
commit | e218dcfdf2c58f8841e7ebd220527d08e870a6d5 (patch) | |
tree | a567db04a8a51e2db87f80e259faf222a7d4becd /src/math/geometry.h | |
parent | bfc701e286259d9a7aa2ff8240704eab2ba3a237 (diff) | |
parent | e607fed265070be8c518d4302d8b76f738421fb3 (diff) | |
download | colobot-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.h | 33 |
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 |