summaryrefslogtreecommitdiffstats
path: root/src/core/General.h
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2019-07-07 13:09:11 +0200
committeraap <aap@papnet.eu>2019-07-07 13:09:11 +0200
commit53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb (patch)
treefc65a6c40fa719f9d43be9e0e15be79c490135e0 /src/core/General.h
parentfinished CPhysical (diff)
downloadre3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.gz
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.bz2
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.lz
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.xz
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.tar.zst
re3-53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb.zip
Diffstat (limited to 'src/core/General.h')
-rw-r--r--src/core/General.h91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/core/General.h b/src/core/General.h
new file mode 100644
index 00000000..cae1caa0
--- /dev/null
+++ b/src/core/General.h
@@ -0,0 +1,91 @@
+#pragma once
+
+class CGeneral
+{
+public:
+ static float GetATanOfXY(float x, float y){
+ 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);
+ }
+ }
+ }
+
+ static float LimitRadianAngle(float angle)
+ {
+ float result;
+
+ if (angle < -25.0f)
+ result = -25.0f;
+ else if (angle > 25.0f)
+ result = 25.0f;
+ else
+ result = angle;
+
+ while (result >= PI) {
+ result -= 2 * PI;
+ }
+
+ while (result < -PI) {
+ result += 2 * PI;
+ }
+
+ return result;
+ }
+
+ static float GetRadianAngleBetweenPoints(float x1, float y1, float x2, float y2)
+ {
+ float x = x2 - x1;
+ float y = y2 - y1;
+
+ if (y == 0.0f)
+ y = 0.0001f;
+
+ if (x > 0.0f) {
+ if (y > 0.0f)
+ return PI - atan2(x / y, 1.0f);
+ else
+ return -atan2(x / y, 1.0f);
+ } else {
+ if (y > 0.0f)
+ return -(PI + atan2(x / y, 1.0f));
+ else
+ return -atan2(x / y, 1.0f);
+ }
+ }
+
+ // not too sure about all these...
+ static uint16 GetRandomNumber(void)
+ { return myrand() & MYRAND_MAX; }
+ // Probably don't want to ever reach high
+ static float GetRandomNumberInRange(float low, float high)
+ { return low + (high - low)*(GetRandomNumber()/float(MYRAND_MAX + 1)); }
+
+ static int32 GetRandomNumberInRange(int32 low, int32 high)
+ { return low + (high - low)*(GetRandomNumber()/float(MYRAND_MAX + 1)); }
+};