27var vector g_vectorCacheLast;
28var vector g_vectorCacheForward;
29var vector g_vectorCacheRight;
30var vector g_vectorCacheUp;
33anglesMake(vector angle)
36 g_vectorCacheLast = angle;
37 g_vectorCacheForward = v_forward;
38 g_vectorCacheRight = v_right;
39 g_vectorCacheUp = v_up;
48anglesToForward(vector angle)
50 if (angle == g_vectorCacheLast) {
51 return g_vectorCacheForward;
55 return g_vectorCacheForward;
64anglesToRight(vector angle)
66 if (angle == g_vectorCacheLast) {
67 return g_vectorCacheRight;
71 return g_vectorCacheRight;
80anglesToUp(vector angle)
82 if (angle == g_vectorCacheLast) {
83 return g_vectorCacheUp;
87 return g_vectorCacheUp;
96distanceSquared(vector pointA, vector pointB)
98 float diffX = pointA[0] - pointB[0];
99 float diffY = pointA[1] - pointB[1];
100 float diffZ = pointA[2] - pointB[2];
101 return (diffX * diffX) + (diffY * diffY) + (diffZ * diffZ);
110distance(vector pointA, vector pointB)
112 return sqrt(distanceSquared(pointA, pointB));
121distance2D(vector pointA, vector pointB)
123 float diffX = pointA[0] - pointB[0];
124 float diffY = pointA[1] - pointB[1];
125 return sqrt((diffX * diffX) + (diffY * diffY));
135closer(vector referencePoint, vector pointA, vector pointB)
137 float distanceA = distanceSquared(referencePoint, pointA);
138 float distanceB = distanceSquared(referencePoint, pointA);
139 return (distanceA < distanceB) ? true :
false;
147combineAngles(vector angleA, vector angleB)
150 rotatevectorsbyangle(angleB);
151 return vectoangles(v_forward, v_up);
159length(vector toCalculate)
161 static vector lastInput = g_vec_null;
162 static float lastOutput = 0.0f;
164 if (toCalculate == lastInput) {
168 lastInput = toCalculate;
169 lastOutput = vlen(toCalculate);
178lengthSquared(vector target)
180 return (target[0] * target[0]) + (target[1] * target[1]) + (target[2] * target[2]);
189vectorDot(vector vectorA, vector vectorB)
191 return dotproduct(vectorA, vectorB);
201vectorLerp(vector fromVector, vector toVector,
float lerpFraction)
203 static float vectorLerp_Lerp(
float fA,
float fB,
float fPercent) {
204 return (fA * (1 - fPercent)) + (fB * fPercent);
207 vector outputVector = g_vec_null;
208 outputVector[0] = vectorLerp_Lerp(fromVector[0], toVector[0], lerpFraction);
209 outputVector[1] = vectorLerp_Lerp(fromVector[1], toVector[1], lerpFraction);
210 outputVector[2] = vectorLerp_Lerp(fromVector[2], toVector[2], lerpFraction);
219vectorNormalize(vector toNormalize)
221 static vector lastInput = g_vec_null;
222 static vector lastOutput = g_vec_null;
224 if (toNormalize == lastInput) {
228 lastInput = toNormalize;
229 lastOutput = normalize(toNormalize);
238vectorToAngles(vector toAngles)
240 static vector lastInput = g_vec_null;
241 static vector lastOutput = g_vec_null;
243 if (toAngles == lastInput) {
247 lastInput = toAngles;
248 lastOutput = fixAngle(vectoangles(toAngles));
258vectorToAnglesRoll(vector forwardDir, vector rollDir)
260 static vector lastInput = g_vec_null;
261 static vector lastInput2 = g_vec_null;
262 static vector lastOutput = g_vec_null;
264 if (forwardDir == lastInput && rollDir == lastInput2) {
268 lastInput = forwardDir;
269 lastInput2 = rollDir;
270 lastOutput = fixAngle(vectoangles(forwardDir, rollDir));
281lerpAngleVector(vector inputAngle, vector endAngle,
float lerpAmount)
283 vector currentDir = anglesToForward(inputAngle);
284 vector desiredDir = anglesToForward(endAngle);
285 return vectorToAngles(vectorLerp(currentDir, desiredDir, lerpAmount));
294dirFromTarget(vector lookingEnt, vector targetEnt)
296 return anglesToForward(vectorToAngles(targetEnt - lookingEnt));