summaryrefslogtreecommitdiffstats
path: root/src/General.h
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2019-05-29 18:06:33 +0200
committeraap <aap@papnet.eu>2019-05-29 18:06:33 +0200
commit820fd66a94c20c4e1dab21f6abda4138eaefbe79 (patch)
tree445a810baf60f29c455dbaf4b3e82934806b49a8 /src/General.h
parentmore CVehicleModelInfo (diff)
downloadre3-820fd66a94c20c4e1dab21f6abda4138eaefbe79.tar
re3-820fd66a94c20c4e1dab21f6abda4138eaefbe79.tar.gz
re3-820fd66a94c20c4e1dab21f6abda4138eaefbe79.tar.bz2
re3-820fd66a94c20c4e1dab21f6abda4138eaefbe79.tar.lz
re3-820fd66a94c20c4e1dab21f6abda4138eaefbe79.tar.xz
re3-820fd66a94c20c4e1dab21f6abda4138eaefbe79.tar.zst
re3-820fd66a94c20c4e1dab21f6abda4138eaefbe79.zip
Diffstat (limited to '')
-rw-r--r--src/General.h36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/General.h b/src/General.h
index 7aacee39..8e1a2521 100644
--- a/src/General.h
+++ b/src/General.h
@@ -2,8 +2,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...