33#define MATH_PI 3.1415926
34noref
const vector g_vec_null = [0.0f, 0.0f, 0.0f];
36#define MAX_DISTANCE 99999
40vector vectoangles2(vector fwd, optional vector up) = #11;
41void rotatevectorsbyangle(vector angle) = #0;
43#define vectoangles vectoangles2
48void makevectors( vector angles )
51 float sr, sp, sy, cr, cp, cy;
53 angle = angles[1] * (M_PI*2 / 360);
56 angle = angles[0] * (M_PI*2 / 360);
59 angle = angles[2] * (M_PI*2 / 360);
67 v_right[0] = (-1*sr*sp*cy+-1*cr*-sy);
68 v_right[1] = (-1*sr*sp*sy+-1*cr*cy);
69 v_right[2] = -1*sr*cp;
71 v_up[0] = (cr*sp*cy+-sr*-sy);
72 v_up[1] = (cr*sp*sy+-sr*cy);
85lerpAngle(
float startAngle,
float endAngle,
float lerpAmount)
87 float shortest_angle = ((((endAngle - startAngle) % 360.0f) + 540.0f) % 360.0f) - 180.0f;
88 return shortest_angle * lerpAmount;
98lerp(
float startValue,
float endValue,
float lerpAmount)
100 return (startValue * (1 - lerpAmount)) + (endValue * lerpAmount);
108fixAngleDelta(
float angleValue)
110 if (angleValue > 180) {
112 }
else if (angleValue < -180) {
118 return fixAngleDelta(angleValue);
127fixAngle(vector inputAngle)
129 inputAngle[0] = fixAngleDelta(inputAngle[0]);
130 inputAngle[1] = fixAngleDelta(inputAngle[1]);
131 inputAngle[2] = fixAngleDelta(inputAngle[2]);
141reflect(vector hitDirection, vector planeNormal)
143 return hitDirection - 2 * dotproduct(hitDirection, planeNormal) * planeNormal;
151randomVector(
bool flyUp)
154 tmp[0] = random() - 0.5f;
155 tmp[1] = random() - 0.5f;
157 if ( flyUp ==
true ) {
160 tmp[2] = random() - 0.5f;
173rotateAroundPoint(vector pos, vector pivot,
float degr)
176 new[0] = pivot[0] + (pos[0] - pivot[0]) * cos(degr) - (pos[1] - pivot[1]) * sin(degr);
177 new[1] = pivot[1] + (pos[0] - pivot[0]) * sin(degr) + (pos[1] - pivot[1]) * cos(degr);
187angleDifference(vector angle1, vector angle2)
189 static float Math_AngleDiff_S(
float from,
float to) {
190 float angleDelta = from - to;
192 if (angleDelta > 180) {
194 }
else if (angleDelta < -180) {
204 angle1 = fixAngle(angle1);
205 angle2 = fixAngle(angle2);
207 newAngle[0] = Math_AngleDiff_S(angle1[0], angle2[0]);
208 newAngle[1] = Math_AngleDiff_S(angle1[1], angle2[1]);
209 newAngle[2] = Math_AngleDiff_S(angle1[2], angle2[2]);
220hsvToRGB(
float h,
float s,
float v)
223 vector col = [0,0,0];
225 h = max(0.0, min(360.0, h));
226 s = max(0.0, min(100.0, s));
227 v = max(0.0, min(100.0, v));
233 col[0] = col[1] = col[2] = rint(v*255);
242 t = v * (1 - s * (1 - f));
246 col[0] = rint(255*v);
247 col[1] = rint(255*t);
248 col[2] = rint(255*p);
251 col[0] = rint(255*q);
252 col[1] = rint(255*v);
253 col[2] = rint(255*p);
256 col[0] = rint(255*p);
257 col[1] = rint(255*v);
258 col[2] = rint(255*t);
261 col[0] = rint(255*p);
262 col[1] = rint(255*q);
263 col[2] = rint(255*v);
266 col[0] = rint(255*t);
267 col[1] = rint(255*p);
268 col[2] = rint(255*v);
271 col[0] = rint(255*v);
272 col[1] = rint(255*p);
273 col[2] = rint(255*q);