Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_Math.c
Go to the documentation of this file.
1 class SCR_Math
2 {
3  //~ Random generator used in scripted Math functions
4  protected const static ref RandomGenerator RANDOM_GENERATOR = new RandomGenerator();
5 
6  //------------------------------------------------------------------------------------------------
8  // TODO: [Obsolete("Use Math.Mod instead")]
9  static float fmod(float dividend, float divisor)
10  {
11  if (divisor == 0)
12  return 0;
13 
14  return dividend - Math.Floor(dividend / divisor) * divisor;
15  }
16 
17  //------------------------------------------------------------------------------------------------
25  static float LerpAngle(float a, float b, float t)
26  {
27  float dt = fmod(b - a, 360);
28  if (dt > 180)
29  dt -= 360;
30 
31  return fmod(Math.Lerp(a, a + dt, t), 360);
32  }
33 
34  //------------------------------------------------------------------------------------------------
41  static float DeltaAngle(float a, float b)
42  {
43  return 180 - Math.AbsFloat(fmod(Math.AbsFloat(b - a), 360) - 180);
44  }
45 
46  //------------------------------------------------------------------------------------------------
52  static int IntegerMask(int x)
53  {
54  x |= (x >> 1);
55  x |= (x >> 2);
56  x |= (x >> 4);
57  x |= (x >> 8);
58  x |= (x >> 16);
59  return x;
60  }
61 
62  //------------------------------------------------------------------------------------------------
64  static float GetDistanceToStop(float speed, float deceleration)
65  {
66  float distance = 0;
67  if (deceleration > 0)
68  distance = 0.5 * speed * speed / deceleration;
69  else if (speed > 0)
70  distance = 1e10;
71 
72  return distance;
73  }
74 
75  //------------------------------------------------------------------------------------------------
77  static float GetSpeedToReachDistance(float distance, float deceleration)
78  {
79  float speed = 0;
80  if (distance > 0 && deceleration > 0)
81  speed = Math.Sqrt(2 * distance * deceleration);
82 
83  return speed;
84  }
85 
86  //------------------------------------------------------------------------------------------------
88  static float GetSpeedToReachDistanceInTime(float distance, float deceleration, float time)
89  {
90  if (time <= 0)
91  return 1e10;
92 
93  // Get the decelerated part
94  float speed = GetSpeedToReachDistance(distance, deceleration);
95  float averageSpeed = distance / time;
96  float additionalSpeed = averageSpeed - speed*0.5;
97  speed += additionalSpeed;
98 
99  return speed;
100  }
101 
102  //------------------------------------------------------------------------------------------------
107  static RandomGenerator GetMathRandomGenerator()
108  {
109  return RANDOM_GENERATOR;
110  }
111 };
SCR_Math
Definition: SCR_Math.c:1
distance
float distance
Definition: SCR_DestructibleTreeV2.c:29