DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
EnMath.c
См. документацию.
1
5
6class Math
7{
8 private void Math() {}
9 private void ~Math() {}
10
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;
15
16 static const float RAD2DEG = 57.2957795130823208768;
17 static const float DEG2RAD = 0.01745329251994329577;
18
20 proto static int GetNumberOfSetBits(int i);
21
23 proto static int GetNthBitSet(int value, int n);
24
38 proto static int RandomInt(int min, int max);
39
53
54 static int RandomIntInclusive(int min, int max)
55 {
56 return Math.RandomInt(min, max+1);
57 }
58
72
73 static bool RandomBool()
74 {
75 return RandomIntInclusive(0,1);
76 }
77
91 proto static float RandomFloat(float min, float max);
92
106 static float RandomFloatInclusive(float min, float max)
107 {
108 int max_range = Math.Pow(2, 30); //max range
109 int random_int = Math.RandomInt(0, max_range);
110 float rand_float = (float)random_int / (float)max_range;
111 float range = max - min;
112
113 return min + (rand_float * range); //rand float
114 }
115
126 static float RandomFloat01()
127 {
128 return RandomFloatInclusive(0, 1);
129 }
130
141 proto static int Randomize(int seed);
142
155 proto static float NormalizeAngle(float ang);
156
170 proto static float DiffAngle(float angle1, float angle2);
171
183 proto static float Pow(float v, float power);
184
198 proto static float ModFloat(float x, float y);
199
213 proto static float RemainderFloat(float x, float y);
214
225 proto static float AbsFloat(float f);
226
237 proto static int AbsInt(int i);
238
253 proto static float SignFloat(float f);
254
269 proto static int SignInt(int i);
270
281 proto static float SqrFloat(float f);
282
293 proto static int SqrInt(int i);
294
305 proto static float Sqrt(float val);
306
319 proto static float Log2(float x);
320
331 proto static float Sin(float angle);
332
343 proto static float Cos(float angle);
344
355 proto static float Tan(float angle);
356
367 proto static float Asin(float s);
368
379 proto static float Acos(float c);
380
386 proto static float Atan(float x);
387
399 proto static float Atan2(float y, float x);
400
413 proto static float Round(float f);
414
427 proto static float Floor(float f);
428
441 proto static float Ceil(float f);
442
455 proto static float WrapFloat(float f, float min, float max);
456
469 proto static float WrapFloatInclusive(float f, float min, float max);
470
482 proto static float WrapFloat0X(float f, float max);
483
495 proto static float WrapFloat0XInclusive(float f, float max);
496
509 proto static int WrapInt(int i, int min, int max);
510
522 proto static int WrapInt0X(int i, int max);
523
540 proto static float Clamp(float value, float min, float max);
541
553 proto static float Min(float x, float y);
554
566 proto static float Max(float x, float y);
567
580 proto static bool IsInRange(float v, float min, float max);
581
594 proto static bool IsInRangeInt(int v, int min, int max);
595
608 proto static float Lerp(float a, float b, float time);
609
622 proto static float InverseLerp(float a, float b, float value);
623
630 proto static float AreaOfRightTriangle(float s, float a);
631
638 proto static float HypotenuseOfRightTriangle(float s, float a);
639
647 proto static bool IsPointInCircle(vector c, float r, vector p);
648
656 proto static bool IsPointInRectangle(vector mi, vector ma, vector p);
657
658 //--------------------------------------------------------------------------
659 //-------------------------------- filters ---------------------------------
660 //--------------------------------------------------------------------------
661
677
678 proto static float SmoothCD(float val, float target, inout float velocity[], float smoothTime, float maxVelocity, float dt);
679
680 static float SmoothCDPI2PI(float val, float target, inout float velocity[], float smoothTime, float maxVelocity, float dt)
681 {
682 float diff = target - val;
683 if (diff < -Math.PI)
684 {
685 target += Math.PI2;
686 }
687 else if (diff > Math.PI)
688 {
689 target -= Math.PI2;
690 }
691
692 float retVal = SmoothCD(val, target, velocity, smoothTime, maxVelocity, dt);
693
694 while (retVal > Math.PI)
695 {
696 retVal -= Math.PI2;
697 }
698
699 while (retVal < -Math.PI)
700 {
701 retVal += Math.PI2;
702 }
703
704 return retVal;
705 }
706
708 static float Poisson(float mean, int occurences)
709 {
710 return Pow(mean, occurences) * Pow(EULER,-mean) / Factorial(occurences);
711 }
712
714 static int Factorial(int val)
715 {
716 if (val > 12)
717 {
718 ErrorEx("Values above '12' cause int overflow! Returning '1'",ErrorExSeverity.INFO);
719 return 1;
720 }
721
722 int res = 1;
723 while (val > 1)
724 {
725 res *= val--;
726 }
727 return res;
728 }
729
740 static float Remap(float inputMin, float inputMax, float outputMin, float outputMax, float inputValue, bool clampedOutput = true)
741 {
742 float tempValue = Math.InverseLerp(inputMin, inputMax, inputValue);
743 float remapped = Math.Lerp(outputMin, outputMax, tempValue);
744
745 if (clampedOutput)
746 return Math.Clamp(remapped, outputMin, outputMax);
747
748 return remapped;
749 }
750
752 {
753 float x = (min[0] + max[0]) * 0.5;
754 float z = (min[2] + max[2]) * 0.5;
755
756 return Vector(x, 0.0, z);
757 }
758}
759
Icon x
Icon y
Определения EnConvert.c:97
Определения EnConvert.c:106
ErrorExSeverity
Определения EnDebug.c:62
enum ShapeType ErrorEx
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static const float PI2
Определения EnMath.c:13
static float RandomFloat01()
Returns a random float number between and min [inclusive] and max [inclusive].
Определения EnMath.c:126
static proto float Max(float x, float y)
Returns bigger of two given values.
static float Poisson(float mean, int occurences)
occurences values above '12' will cause Factorial to overflow int.
Определения EnMath.c:708
static const float EULER
Определения EnMath.c:11
static proto bool IsInRange(float v, float min, float max)
Returns if value is between min and max (inclusive)
static proto float Floor(float f)
Returns floor of value.
static proto int Randomize(int seed)
Sets the seed for the random number generator.
static proto float Lerp(float a, float b, float time)
Linearly interpolates between 'a' and 'b' given 'time'.
static proto float SqrFloat(float f)
Returns squared value.
static proto float AreaOfRightTriangle(float s, float a)
Returns area of a right triangle.
static proto float HypotenuseOfRightTriangle(float s, float a)
Returns hypotenus of a right triangle.
static const float PI_HALF
Определения EnMath.c:14
static proto float Asin(float s)
Returns angle in radians from sinus.
static proto float ModFloat(float x, float y)
Returns the floating-point remainder of x/y rounded towards zero.
static proto float NormalizeAngle(float ang)
Normalizes the angle (0...360)
static proto bool IsInRangeInt(int v, int min, int max)
Returns if value is between min and max (inclusive)
static proto float SignFloat(float f)
Returns sign of given value.
static proto float Acos(float c)
Returns angle in radians from cosinus.
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
Определения EnMath.c:106
static proto float Sqrt(float val)
Returns square root.
static float SmoothCDPI2PI(float val, float target, inout float velocity[], float smoothTime, float maxVelocity, float dt)
Определения EnMath.c:680
static proto int GetNthBitSet(int value, int n)
returns the the index of n-th bit set in a bit mask counting from the right, for instance,...
static proto bool IsPointInCircle(vector c, float r, vector p)
Returns if point is inside circle.
static proto float Min(float x, float y)
Returns smaller of two given values.
static proto float Cos(float angle)
Returns cosinus of angle in radians.
static proto int AbsInt(int i)
Returns absolute value.
static proto float Tan(float angle)
Returns tangent of angle in radians.
static proto float Atan(float x)
Returns angle in radians from tangent.
static proto int SignInt(int i)
Returns sign of given value.
static proto bool IsPointInRectangle(vector mi, vector ma, vector p)
Returns if point is inside rectangle.
static proto int WrapInt0X(int i, int max)
Returns wrap number to specified interval [0, max[.
static proto int WrapInt(int i, int min, int max)
Returns wrap number to specified interval [min, max[.
static proto float Log2(float x)
Returns the binary (base-2) logarithm of x.
static proto float WrapFloat(float f, float min, float max)
Returns wrap number to specified interval [min, max[.
static proto float Round(float f)
Returns mathematical round of value.
static bool RandomBool()
Returns a random bool .
Определения EnMath.c:73
static proto float Atan2(float y, float x)
Returns angle in radians from tangent.
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto float Sin(float angle)
Returns sinus of angle in radians.
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
static proto float WrapFloatInclusive(float f, float min, float max)
Returns wrap number to specified interval, inclusive [min, max].
static proto int SqrInt(int i)
Returns squared value.
static proto float RemainderFloat(float x, float y)
Returns the floating-point remainder of x/y rounded to nearest.
static proto float Pow(float v, float power)
Return power of v ^ power.
static proto float WrapFloat0X(float f, float max)
Returns wrap number to specified interval [0, max[.
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
static float Remap(float inputMin, float inputMax, float outputMin, float outputMax, float inputValue, bool clampedOutput=true)
Returns given value remaped from input range into output range.
Определения EnMath.c:740
static vector CenterOfRectangle(vector min, vector max)
Определения EnMath.c:751
static proto float Ceil(float f)
Returns ceil of value.
static proto float DiffAngle(float angle1, float angle2)
Return relative difference between angles.
void ~Math()
Определения EnMath.c:9
void Math()
Определения EnMath.c:8
static const float RAD2DEG
Определения EnMath.c:16
static proto float WrapFloat0XInclusive(float f, float max)
Returns wrap number to specified interval, inclusive [0, max].
static const float DEG2RAD
Определения EnMath.c:17
static proto float AbsFloat(float f)
Returns absolute value.
static proto float SmoothCD(float val, float target, inout float velocity[], float smoothTime, float maxVelocity, float dt)
Does the CD smoothing function - easy in | easy out / S shaped smoothing.
static proto int GetNumberOfSetBits(int i)
returns the number of bits set in a bitmask i
static const float PI
Определения EnMath.c:12
static int Factorial(int val)
values above '12' will cause int overflow
Определения EnMath.c:714
static int RandomIntInclusive(int min, int max)
Returns a random int number between and min [inclusive] and max [inclusive].
Определения EnMath.c:54