2019-05-29 22:47:33 +00:00
|
|
|
#pragma once
|
2019-05-29 18:02:58 +00:00
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
class CGeneral
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static float GetATanOfXY(float x, float y){
|
2019-05-29 16:06:33 +00:00
|
|
|
if(x == 0.0f && y == 0.0f)
|
|
|
|
return 0.0f;
|
2019-07-10 15:18:26 +00:00
|
|
|
float xabs = Abs(x);
|
|
|
|
float yabs = Abs(y);
|
2019-05-29 16:06:33 +00:00
|
|
|
|
|
|
|
if(xabs < yabs){
|
|
|
|
if(y > 0.0f){
|
|
|
|
if(x > 0.0f)
|
2019-07-10 15:18:26 +00:00
|
|
|
return 0.5f*PI - Atan2(x / y, 1.0f);
|
2019-05-29 16:06:33 +00:00
|
|
|
else
|
2019-07-10 15:18:26 +00:00
|
|
|
return 0.5f*PI + Atan2(-x / y, 1.0f);
|
2019-05-29 16:06:33 +00:00
|
|
|
}else{
|
|
|
|
if(x > 0.0f)
|
2019-07-10 15:18:26 +00:00
|
|
|
return 1.5f*PI + Atan2(x / -y, 1.0f);
|
2019-05-29 16:06:33 +00:00
|
|
|
else
|
2019-07-10 15:18:26 +00:00
|
|
|
return 1.5f*PI - Atan2(-x / -y, 1.0f);
|
2019-05-29 16:06:33 +00:00
|
|
|
}
|
|
|
|
}else{
|
|
|
|
if(y > 0.0f){
|
|
|
|
if(x > 0.0f)
|
2019-07-10 15:18:26 +00:00
|
|
|
return Atan2(y / x, 1.0f);
|
2019-05-29 16:06:33 +00:00
|
|
|
else
|
2019-07-10 15:18:26 +00:00
|
|
|
return PI - Atan2(y / -x, 1.0f);
|
2019-05-29 16:06:33 +00:00
|
|
|
}else{
|
|
|
|
if(x > 0.0f)
|
2019-07-10 15:18:26 +00:00
|
|
|
return 2.0f*PI - Atan2(-y / x, 1.0f);
|
2019-05-29 16:06:33 +00:00
|
|
|
else
|
2019-07-10 15:18:26 +00:00
|
|
|
return PI + Atan2(-y / -x, 1.0f);
|
2019-05-29 16:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-15 14:52:37 +00:00
|
|
|
}
|
|
|
|
|
2019-06-20 11:22:44 +00:00
|
|
|
static float LimitRadianAngle(float angle)
|
|
|
|
{
|
2019-07-03 16:34:42 +00:00
|
|
|
float result;
|
2019-06-20 11:22:44 +00:00
|
|
|
|
2019-07-03 16:34:42 +00:00
|
|
|
if (angle < -25.0f)
|
|
|
|
result = -25.0f;
|
|
|
|
else if (angle > 25.0f)
|
|
|
|
result = 25.0f;
|
|
|
|
else
|
|
|
|
result = angle;
|
2019-06-20 11:22:44 +00:00
|
|
|
|
|
|
|
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)
|
2019-07-10 15:18:26 +00:00
|
|
|
return PI - Atan2(x / y, 1.0f);
|
2019-06-20 11:22:44 +00:00
|
|
|
else
|
|
|
|
return -atan2(x / y, 1.0f);
|
|
|
|
} else {
|
|
|
|
if (y > 0.0f)
|
2019-07-10 15:18:26 +00:00
|
|
|
return -(PI + Atan2(x / y, 1.0f));
|
2019-06-20 11:22:44 +00:00
|
|
|
else
|
|
|
|
return -atan2(x / y, 1.0f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
// not too sure about all these...
|
|
|
|
static uint16 GetRandomNumber(void)
|
2019-07-04 21:10:04 +00:00
|
|
|
{ return myrand() & MYRAND_MAX; }
|
2019-05-15 14:52:37 +00:00
|
|
|
// Probably don't want to ever reach high
|
|
|
|
static float GetRandomNumberInRange(float low, float high)
|
2019-05-30 21:49:06 +00:00
|
|
|
{ return low + (high - low)*(GetRandomNumber()/float(MYRAND_MAX + 1)); }
|
2019-05-29 18:02:58 +00:00
|
|
|
|
2019-06-16 22:16:38 +00:00
|
|
|
static int32 GetRandomNumberInRange(int32 low, int32 high)
|
2019-05-30 21:49:06 +00:00
|
|
|
{ return low + (high - low)*(GetRandomNumber()/float(MYRAND_MAX + 1)); }
|
2019-05-15 14:52:37 +00:00
|
|
|
};
|