2019-05-29 20:02:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-15 16:52:37 +02:00
|
|
|
class CGeneral
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static float GetATanOfXY(float x, float y){
|
2019-05-29 18:06:33 +02:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
2019-05-15 16:52:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// not too sure about all these...
|
|
|
|
static uint16 GetRandomNumber(void)
|
|
|
|
{ return myrand() & 0xFFFF; }
|
|
|
|
// Probably don't want to ever reach high
|
|
|
|
static float GetRandomNumberInRange(float low, float high)
|
2019-05-29 20:05:50 +02:00
|
|
|
{ return low + (high - low)*(GetRandomNumber()/float(MY_RAND_MAX + 1)); }
|
2019-05-29 20:02:58 +02:00
|
|
|
|
|
|
|
static Int32 GetRandomNumberInRange(Int32 low, Int32 high)
|
2019-05-29 20:05:50 +02:00
|
|
|
{ return low + (high - low)*(GetRandomNumber()/float(MY_RAND_MAX + 1)); }
|
2019-05-15 16:52:37 +02:00
|
|
|
};
|