{-0.587785, -0.425325, -0.688191}, {-0.688191, -0.587785, -0.425325},
};
-qbyte NormalToByte(vec3_t n)
+qbyte NormalToByte(const vec3_t n)
{
int i, best;
float bestdistance, distance;
return y * (1.5f - (number * 0.5f * y * y));
}
-void _VectorNormalizeFast(vec3_t v)
-{
- float y, number;
-
- number = DotProduct(v, v);
-
- if (number != 0.0)
- {
- *((int *)&y) = 0x5f3759df - ((* (int *) &number) >> 1);
- y = y * (1.5f - (number * 0.5f * y * y));
-
- VectorScale(v, y, v);
- }
-}
-
#if 0
// LordHavoc: no longer used at all
void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal )
BoxOnPlaneSideClassify(p);
}
-void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
+void AngleVectors (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up)
{
double angle, sr, sp, sy, cr, cp, cy;
}
}
-void AngleVectorsFLU (vec3_t angles, vec3_t forward, vec3_t left, vec3_t up)
+void AngleVectorsFLU (const vec3_t angles, vec3_t forward, vec3_t left, vec3_t up)
{
double angle, sr, sp, sy, cr, cp, cy;
}
}
-void AngleMatrix (vec3_t angles, vec3_t translate, vec_t matrix[][4])
+void AngleMatrix (const vec3_t angles, const vec3_t translate, vec_t matrix[][4])
{
double angle, sr, sp, sy, cr, cp, cy;
matrix[2][3] = translate[2];
}
-void VectorMASlow (vec3_t veca, float scale, vec3_t vecb, vec3_t vecc)
-{
- vecc[0] = veca[0] + scale*vecb[0];
- vecc[1] = veca[1] + scale*vecb[1];
- vecc[2] = veca[2] + scale*vecb[2];
-}
-
-
-vec_t _DotProduct (vec3_t v1, vec3_t v2)
-{
- return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
-}
-
-void _VectorSubtract (vec3_t veca, vec3_t vecb, vec3_t out)
-{
- out[0] = veca[0]-vecb[0];
- out[1] = veca[1]-vecb[1];
- out[2] = veca[2]-vecb[2];
-}
-
-void _VectorAdd (vec3_t veca, vec3_t vecb, vec3_t out)
-{
- out[0] = veca[0]+vecb[0];
- out[1] = veca[1]+vecb[1];
- out[2] = veca[2]+vecb[2];
-}
-
-void _VectorCopy (vec3_t in, vec3_t out)
-{
- out[0] = in[0];
- out[1] = in[1];
- out[2] = in[2];
-}
-
// LordHavoc: changed CrossProduct to a #define
/*
void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross)
}
*/
-double sqrt(double x);
-
-vec_t Length(vec3_t v)
-{
- int i;
- float length;
-
- length = 0;
- for (i=0 ; i< 3 ; i++)
- length += v[i]*v[i];
- length = sqrt (length); // FIXME
-
- return length;
-}
-
/*
// LordHavoc: fixme: do more research on gcc assembly so that qftol_minushalf and result will not be considered unused
static double qftol_minushalf = -0.5;
}
+/*
float VectorNormalizeLength2 (vec3_t v, vec3_t dest) // LordHavoc: added to allow copying while doing the calculation...
{
float length, ilength;
dest[0] = dest[1] = dest[2] = 0;
return length;
-
-}
-
-void _VectorInverse (vec3_t v)
-{
- v[0] = -v[0];
- v[1] = -v[1];
- v[2] = -v[2];
-}
-
-void _VectorScale (vec3_t in, vec_t scale, vec3_t out)
-{
- out[0] = in[0]*scale;
- out[1] = in[1]*scale;
- out[2] = in[2]*scale;
-}
-
-
-int Q_log2(int val)
-{
- int answer=0;
- while (val>>=1)
- answer++;
- return answer;
}
-
+*/
/*
================
R_ConcatRotations
================
*/
-void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3])
+void R_ConcatRotations (const float in1[3][3], const float in2[3][3], float out[3][3])
{
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + in1[0][2] * in2[2][0];
out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + in1[0][2] * in2[2][1];
R_ConcatTransforms
================
*/
-void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4])
+void R_ConcatTransforms (const float in1[3][4], const float in2[3][4], float out[3][4])
{
out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] + in1[0][2] * in2[2][0];
out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] + in1[0][2] * in2[2][1];
}
-/*
-===================
-FloorDivMod
-
-Returns mathematically correct (floor-based) quotient and remainder for
-numer and denom, both of which should contain no fractional part. The
-quotient must fit in 32 bits.
-====================
-*/
-
-void FloorDivMod (double numer, double denom, int *quotient,
- int *rem)
-{
- int q, r;
- double x;
-
-#ifndef PARANOID
- if (denom <= 0.0)
- Sys_Error ("FloorDivMod: bad denominator %d\n", denom);
-
-// if ((floor(numer) != numer) || (floor(denom) != denom))
-// Sys_Error ("FloorDivMod: non-integer numer or denom %f %f\n",
-// numer, denom);
-#endif
-
- if (numer >= 0.0)
- {
-
- x = floor(numer / denom);
- q = (int)x;
- r = (int)floor(numer - (x * denom));
- }
- else
- {
- //
- // perform operations with positive values, and fix mod to make floor-based
- //
- x = floor(-numer / denom);
- q = -(int)x;
- r = (int)floor(-numer - (x * denom));
- if (r != 0)
- {
- q--;
- r = (int)denom - r;
- }
- }
-
- *quotient = q;
- *rem = r;
-}
-
-
-/*
-===================
-GreatestCommonDivisor
-====================
-*/
-int GreatestCommonDivisor (int i1, int i2)
-{
- if (i1 > i2)
- {
- if (i2 == 0)
- return (i1);
- return GreatestCommonDivisor (i2, i1 % i2);
- }
- else
- {
- if (i1 == 0)
- return (i2);
- return GreatestCommonDivisor (i1, i2 % i1);
- }
-}
-
-
void Mathlib_Init(void)
{
int a;
#define VectorCopy4(a,b) {(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];(b)[3]=(a)[3];}
-void VectorMASlow (vec3_t veca, float scale, vec3_t vecb, vec3_t vecc);
-
-vec_t _DotProduct (vec3_t v1, vec3_t v2);
-void _VectorSubtract (vec3_t veca, vec3_t vecb, vec3_t out);
-void _VectorAdd (vec3_t veca, vec3_t vecb, vec3_t out);
-void _VectorCopy (vec3_t in, vec3_t out);
-
vec_t Length (vec3_t v);
float VectorNormalizeLength (vec3_t v); // returns vector length
float VectorNormalizeLength2 (vec3_t v, vec3_t dest); // returns vector length
-void _VectorInverse (vec3_t v);
-void _VectorScale (vec3_t in, vec_t scale, vec3_t out);
-int Q_log2(int val);
-void _VectorNormalizeFast (vec3_t v);
-
-float Q_RSqrt(float number);
#define NUMVERTEXNORMALS 162
extern float m_bytenormals[NUMVERTEXNORMALS][3];
-qbyte NormalToByte(vec3_t n);
+qbyte NormalToByte(const vec3_t n);
void ByteToNormal(qbyte num, vec3_t n);
-void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]);
-void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]);
-
-void FloorDivMod (double numer, double denom, int *quotient, int *rem);
-int GreatestCommonDivisor (int i1, int i2);
+void R_ConcatRotations (const float in1[3][3], const float in2[3][3], float out[3][3]);
+void R_ConcatTransforms (const float in1[3][4], const float in2[3][4], float out[3][4]);
-void AngleVectors (vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
+void AngleVectors (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
// LordHavoc: proper matrix version of AngleVectors
-void AngleVectorsFLU (vec3_t angles, vec3_t forward, vec3_t left, vec3_t up);
+void AngleVectorsFLU (const vec3_t angles, vec3_t forward, vec3_t left, vec3_t up);
// LordHavoc: builds a [3][4] matrix
-void AngleMatrix (vec3_t angles, vec3_t translate, vec_t matrix[][4]);
+void AngleMatrix (const vec3_t angles, const vec3_t translate, vec_t matrix[][4]);
// LordHavoc: like AngleVectors, but taking a forward vector instead of angles, useful!
void VectorVectors(const vec3_t forward, vec3_t right, vec3_t up);