9 private void ~Math() {}
11 static const float EULER = 2.7182818284590452353;
12 static const float PI = 3.14159265358979;
13 static const float PI2 = 6.28318530717958;
14 static const float PI_HALF = 1.570796326794;
16 static const float RAD2DEG = 57.2957795130823208768;
17 static const float DEG2RAD = 0.01745329251994329577;
20 proto
static int GetNumberOfSetBits(
int i);
23 proto
static int GetNthBitSet(
int value,
int n);
38 proto
static int RandomInt(
int min,
int max);
54 static int RandomIntInclusive(
int min,
int max)
56 return Math.RandomInt(min, max+1);
73 static bool RandomBool()
75 return RandomIntInclusive(0,1);
91 proto
static float RandomFloat(
float min,
float max);
106 static float RandomFloatInclusive(
float min,
float max)
108 int max_range =
Math.Pow(2, 30);
109 int random_int =
Math.RandomInt(0, max_range);
110 float rand_float = (
float)random_int / (
float)max_range;
111 float range = max - min;
113 return min + (rand_float * range);
126 static float RandomFloat01()
128 return RandomFloatInclusive(0, 1);
141 proto
static int Randomize(
int seed);
155 proto
static float NormalizeAngle(
float ang);
170 proto
static float DiffAngle(
float angle1,
float angle2);
183 proto
static float Pow(
float v,
float power);
198 proto
static float ModFloat(
float x,
float y);
213 proto
static float RemainderFloat(
float x,
float y);
225 proto
static float AbsFloat(
float f);
237 proto
static int AbsInt(
int i);
253 proto
static float SignFloat(
float f);
269 proto
static int SignInt(
int i);
281 proto
static float SqrFloat(
float f);
293 proto
static int SqrInt(
int i);
305 proto
static float Sqrt(
float val);
319 proto
static float Log2(
float x);
331 proto
static float Sin(
float angle);
343 proto
static float Cos(
float angle);
355 proto
static float Tan(
float angle);
367 proto
static float Asin(
float s);
379 proto
static float Acos(
float c);
386 proto
static float Atan(
float x);
399 proto
static float Atan2(
float y,
float x);
413 proto
static float Round(
float f);
427 proto
static float Floor(
float f);
441 proto
static float Ceil(
float f);
455 proto
static float WrapFloat(
float f,
float min,
float max);
469 proto
static float WrapFloatInclusive(
float f,
float min,
float max);
482 proto
static float WrapFloat0X(
float f,
float max);
495 proto
static float WrapFloat0XInclusive(
float f,
float max);
509 proto
static int WrapInt(
int i,
int min,
int max);
522 proto
static int WrapInt0X(
int i,
int max);
540 proto
static float Clamp(
float value,
float min,
float max);
553 proto
static float Min(
float x,
float y);
566 proto
static float Max(
float x,
float y);
580 proto
static bool IsInRange(
float v,
float min,
float max);
594 proto
static bool IsInRangeInt(
int v,
int min,
int max);
608 proto
static float Lerp(
float a,
float b,
float time);
622 proto
static float InverseLerp(
float a,
float b,
float value);
630 proto
static float AreaOfRightTriangle(
float s,
float a);
638 proto
static float HypotenuseOfRightTriangle(
float s,
float a);
647 proto
static bool IsPointInCircle(
vector c,
float r,
vector p);
678 proto
static float SmoothCD(
float val,
float target, inout
float velocity[],
float smoothTime,
float maxVelocity,
float dt);
680 static float SmoothCDPI2PI(
float val,
float target, inout
float velocity[],
float smoothTime,
float maxVelocity,
float dt)
682 float diff = target - val;
687 else if (diff >
Math.PI)
692 float retVal = SmoothCD(val, target, velocity, smoothTime, maxVelocity, dt);
694 while (retVal >
Math.PI)
699 while (retVal < -
Math.PI)
708 static float Poisson(
float mean,
int occurences)
710 return Pow(mean, occurences) * Pow(EULER,-mean) / Factorial(occurences);
714 static int Factorial(
int val)
740 static float Remap(
float inputMin,
float inputMax,
float outputMin,
float outputMax,
float inputValue,
bool clampedOutput =
true)
742 float tempValue =
Math.InverseLerp(inputMin, inputMax, inputValue);
743 float remapped =
Math.Lerp(outputMin, outputMax, tempValue);
746 return Math.Clamp(remapped, outputMin, outputMax);
753 float x = (min[0] + max[0]) * 0.5;
754 float z = (min[2] + max[2]) * 0.5;
766 static bool VectorIsEqual(
vector v1,
vector v2,
float tolerance)
768 return (
Math.AbsFloat(v1[0] - v2[0]) <= tolerance &&
Math.AbsFloat(v1[1] - v2[1]) <= tolerance &&
Math.AbsFloat(v1[2] - v2[2]) <= tolerance);
proto native vector Vector(float x, float y, float z)
Vector constructor from components.