summaryrefslogtreecommitdiffstats
path: root/src/General.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/General.h')
-rw-r--r--src/General.h36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/General.h b/src/General.h
index 1dec2d54..d67b1ff0 100644
--- a/src/General.h
+++ b/src/General.h
@@ -5,8 +5,40 @@ class CGeneral
{
public:
static float GetATanOfXY(float x, float y){
- if(y >= 0.0f) return atan2(x, y);
- return atan2(x, y) + 2*M_PI;
+// why exactly doesn't this work?
+// if(y >= 0.0f) return atan2(x, y);
+// return atan2(x, y) + 2*M_PI;
+
+ if(x == 0.0f && y == 0.0f)
+ return 0.0f;
+ float xabs = fabs(x);
+ float yabs = fabs(y);
+
+ if(xabs < yabs){
+ if(y > 0.0f){
+ if(x > 0.0f)
+ return 0.5f*PI - atan2(x / y, 1.0f);
+ else
+ return 0.5f*PI + atan2(-x / y, 1.0f);
+ }else{
+ if(x > 0.0f)
+ return 1.5f*PI + atan2(x / -y, 1.0f);
+ else
+ return 1.5f*PI - atan2(-x / -y, 1.0f);
+ }
+ }else{
+ if(y > 0.0f){
+ if(x > 0.0f)
+ return atan2(y / x, 1.0f);
+ else
+ return PI - atan2(y / -x, 1.0f);
+ }else{
+ if(x > 0.0f)
+ return 2.0f*PI - atan2(-y / x, 1.0f);
+ else
+ return PI + atan2(-y / -x, 1.0f);
+ }
+ }
}
// not too sure about all these...