mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2024-11-28 15:21:57 +00:00
Cleanup vector math
This work was submitted by Dmitry Antipov. We stick to macros instead of inline functions since they're in line with the rest of the code base. This patch removes several unused functions and tranfers most of the rest into macros.
This commit is contained in:
parent
432fdc271b
commit
123e409a2e
6 changed files with 12 additions and 192 deletions
|
@ -1,3 +1,6 @@
|
|||
Quake II 5.31 to 5.32:
|
||||
- Cleanup vector math. (by Dmitry Antipov)
|
||||
|
||||
Quake II 5.30 to 5.31:
|
||||
- Enabled hud scaling by default and added an option to the video
|
||||
menu to switch scaling off.
|
||||
|
|
|
@ -129,11 +129,6 @@ typedef enum
|
|||
|
||||
typedef float vec_t;
|
||||
typedef vec_t vec3_t[3];
|
||||
typedef vec_t vec5_t[5];
|
||||
|
||||
typedef int fixed4_t;
|
||||
typedef int fixed8_t;
|
||||
typedef int fixed16_t;
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846 /* matches value in gcc v2 math.h */
|
||||
|
@ -160,28 +155,21 @@ extern vec3_t vec3_origin;
|
|||
#define VectorClear(a) (a[0] = a[1] = a[2] = 0)
|
||||
#define VectorNegate(a, b) (b[0] = -a[0], b[1] = -a[1], b[2] = -a[2])
|
||||
#define VectorSet(v, x, y, z) (v[0] = (x), v[1] = (y), v[2] = (z))
|
||||
|
||||
void VectorMA(vec3_t veca, float scale, vec3_t vecb, vec3_t vecc);
|
||||
|
||||
/* just in case you do't want to use the macros */
|
||||
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);
|
||||
#define VectorLength(x) sqrtf(x[0] * x[0] + x[1] * x[1] + x[2] * x[2])
|
||||
#define VectorScale(x, scale, y) (y[0] = scale * x[0], \
|
||||
y[1] = scale * x[1], \
|
||||
y[2] = scale * x[2])
|
||||
#define VectorMA(x, scale, y, z) (z[0] = x[0] + scale * y[0], \
|
||||
z[1] = x[1] + scale * y[1], \
|
||||
z[2] = x[2] + scale * y[2])
|
||||
|
||||
void ClearBounds(vec3_t mins, vec3_t maxs);
|
||||
void AddPointToBounds(vec3_t v, vec3_t mins, vec3_t maxs);
|
||||
int VectorCompare(vec3_t v1, vec3_t v2);
|
||||
vec_t VectorLength(vec3_t v);
|
||||
void CrossProduct(vec3_t v1, vec3_t v2, vec3_t cross);
|
||||
vec_t VectorNormalize(vec3_t v); /* returns vector length */
|
||||
vec_t VectorNormalize2(vec3_t v, vec3_t out);
|
||||
void VectorInverse(vec3_t v);
|
||||
void VectorScale(vec3_t in, vec_t scale, vec3_t out);
|
||||
int Q_log2(int val);
|
||||
|
||||
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 AngleVectors(vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
|
||||
void AngleVectors2(vec3_t value1, vec3_t angles);
|
||||
|
|
|
@ -258,46 +258,8 @@ R_ConcatRotations(float in1[3][3], float in2[3][3], float out[3][3])
|
|||
in1[2][2] * in2[2][2];
|
||||
}
|
||||
|
||||
void
|
||||
R_ConcatTransforms(float in1[3][4], 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];
|
||||
out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] +
|
||||
in1[0][2] * in2[2][2];
|
||||
out[0][3] = in1[0][0] * in2[0][3] + in1[0][1] * in2[1][3] +
|
||||
in1[0][2] * in2[2][3] + in1[0][3];
|
||||
out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] +
|
||||
in1[1][2] * in2[2][0];
|
||||
out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] +
|
||||
in1[1][2] * in2[2][1];
|
||||
out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] +
|
||||
in1[1][2] * in2[2][2];
|
||||
out[1][3] = in1[1][0] * in2[0][3] + in1[1][1] * in2[1][3] +
|
||||
in1[1][2] * in2[2][3] + in1[1][3];
|
||||
out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] +
|
||||
in1[2][2] * in2[2][0];
|
||||
out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] +
|
||||
in1[2][2] * in2[2][1];
|
||||
out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] +
|
||||
in1[2][2] * in2[2][2];
|
||||
out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] +
|
||||
in1[2][2] * in2[2][3] + in1[2][3];
|
||||
}
|
||||
|
||||
/* ============================================================================ */
|
||||
|
||||
float
|
||||
Q_fabs(float f)
|
||||
{
|
||||
int tmp = *(int *)&f;
|
||||
|
||||
tmp &= 0x7FFFFFFF;
|
||||
return *(float *)&tmp;
|
||||
}
|
||||
|
||||
float
|
||||
LerpAngle(float a2, float a1, float frac)
|
||||
{
|
||||
|
@ -502,10 +464,7 @@ VectorCompare(vec3_t v1, vec3_t v2)
|
|||
vec_t
|
||||
VectorNormalize(vec3_t v)
|
||||
{
|
||||
float length, ilength;
|
||||
|
||||
length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
|
||||
length = (float)sqrt(length);
|
||||
float ilength, length = VectorLength(v);
|
||||
|
||||
if (length)
|
||||
{
|
||||
|
@ -518,63 +477,6 @@ VectorNormalize(vec3_t v)
|
|||
return length;
|
||||
}
|
||||
|
||||
vec_t
|
||||
VectorNormalize2(vec3_t v, vec3_t out)
|
||||
{
|
||||
float length, ilength;
|
||||
|
||||
length = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
|
||||
length = (float)sqrt(length);
|
||||
|
||||
if (length)
|
||||
{
|
||||
ilength = 1 / length;
|
||||
out[0] = v[0] * ilength;
|
||||
out[1] = v[1] * ilength;
|
||||
out[2] = v[2] * ilength;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
void
|
||||
VectorMA(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];
|
||||
}
|
||||
|
||||
void
|
||||
CrossProduct(vec3_t v1, vec3_t v2, vec3_t cross)
|
||||
{
|
||||
|
@ -583,55 +485,6 @@ CrossProduct(vec3_t v1, vec3_t v2, vec3_t cross)
|
|||
cross[2] = v1[0] * v2[1] - v1[1] * v2[0];
|
||||
}
|
||||
|
||||
double sqrt(double x);
|
||||
|
||||
vec_t
|
||||
VectorLength(vec3_t v)
|
||||
{
|
||||
int i;
|
||||
float length;
|
||||
|
||||
length = 0;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
{
|
||||
length += v[i] * v[i];
|
||||
}
|
||||
|
||||
length = (float)sqrt(length);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/* ==================================================================================== */
|
||||
|
||||
char *
|
||||
|
|
|
@ -149,7 +149,7 @@ Touch_Multi(edict_t *self, edict_t *other, cplane_t *plane /* unused */,
|
|||
|
||||
AngleVectors(other->s.angles, forward, NULL, NULL);
|
||||
|
||||
if (_DotProduct(forward, self->movedir) < 0)
|
||||
if (DotProduct(forward, self->movedir) < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -76,17 +76,7 @@ extern void COM_FileBase ( char * in , char * out ) ;
|
|||
extern const char * COM_FileExtension ( const char * in ) ;
|
||||
extern void COM_StripExtension ( char * in , char * out ) ;
|
||||
extern char * COM_SkipPath ( char * pathname ) ;
|
||||
extern int Q_log2 ( int val ) ;
|
||||
extern void VectorScale ( vec3_t in , vec_t scale , vec3_t out ) ;
|
||||
extern void VectorInverse ( vec3_t v ) ;
|
||||
extern vec_t VectorLength ( vec3_t v ) ;
|
||||
extern void CrossProduct ( vec3_t v1 , vec3_t v2 , vec3_t cross ) ;
|
||||
extern void _VectorCopy ( vec3_t in , vec3_t out ) ;
|
||||
extern void _VectorAdd ( vec3_t veca , vec3_t vecb , vec3_t out ) ;
|
||||
extern void _VectorSubtract ( vec3_t veca , vec3_t vecb , vec3_t out ) ;
|
||||
extern vec_t _DotProduct ( vec3_t v1 , vec3_t v2 ) ;
|
||||
extern void VectorMA ( vec3_t veca , float scale , vec3_t vecb , vec3_t vecc ) ;
|
||||
extern vec_t VectorNormalize2 ( vec3_t v , vec3_t out ) ;
|
||||
extern vec_t VectorNormalize ( vec3_t v ) ;
|
||||
extern int VectorCompare ( vec3_t v1 , vec3_t v2 ) ;
|
||||
extern void AddPointToBounds ( vec3_t v , vec3_t mins , vec3_t maxs ) ;
|
||||
|
@ -94,8 +84,6 @@ extern void ClearBounds ( vec3_t mins , vec3_t maxs ) ;
|
|||
extern int BoxOnPlaneSide2 ( vec3_t emins , vec3_t emaxs , struct cplane_s * p ) ;
|
||||
extern float anglemod ( float a ) ;
|
||||
extern float LerpAngle ( float a2 , float a1 , float frac ) ;
|
||||
extern float Q_fabs ( float f ) ;
|
||||
extern void R_ConcatTransforms ( float in1 [ 3 ] [ 4 ] , float in2 [ 3 ] [ 4 ] , float out [ 3 ] [ 4 ] ) ;
|
||||
extern void R_ConcatRotations ( float in1 [ 3 ] [ 3 ] , float in2 [ 3 ] [ 3 ] , float out [ 3 ] [ 3 ] ) ;
|
||||
extern void PerpendicularVector ( vec3_t dst , const vec3_t src ) ;
|
||||
extern void ProjectPointOnPlane ( vec3_t dst , const vec3_t p , const vec3_t normal ) ;
|
||||
|
|
|
@ -76,17 +76,7 @@
|
|||
{"COM_FileExtension", (byte *)COM_FileExtension},
|
||||
{"COM_StripExtension", (byte *)COM_StripExtension},
|
||||
{"COM_SkipPath", (byte *)COM_SkipPath},
|
||||
{"Q_log2", (byte *)Q_log2},
|
||||
{"VectorScale", (byte *)VectorScale},
|
||||
{"VectorInverse", (byte *)VectorInverse},
|
||||
{"VectorLength", (byte *)VectorLength},
|
||||
{"CrossProduct", (byte *)CrossProduct},
|
||||
{"_VectorCopy", (byte *)_VectorCopy},
|
||||
{"_VectorAdd", (byte *)_VectorAdd},
|
||||
{"_VectorSubtract", (byte *)_VectorSubtract},
|
||||
{"_DotProduct", (byte *)_DotProduct},
|
||||
{"VectorMA", (byte *)VectorMA},
|
||||
{"VectorNormalize2", (byte *)VectorNormalize2},
|
||||
{"VectorNormalize", (byte *)VectorNormalize},
|
||||
{"VectorCompare", (byte *)VectorCompare},
|
||||
{"AddPointToBounds", (byte *)AddPointToBounds},
|
||||
|
@ -94,8 +84,6 @@
|
|||
{"BoxOnPlaneSide2", (byte *)BoxOnPlaneSide2},
|
||||
{"anglemod", (byte *)anglemod},
|
||||
{"LerpAngle", (byte *)LerpAngle},
|
||||
{"Q_fabs", (byte *)Q_fabs},
|
||||
{"R_ConcatTransforms", (byte *)R_ConcatTransforms},
|
||||
{"R_ConcatRotations", (byte *)R_ConcatRotations},
|
||||
{"PerpendicularVector", (byte *)PerpendicularVector},
|
||||
{"ProjectPointOnPlane", (byte *)ProjectPointOnPlane},
|
||||
|
|
Loading…
Reference in a new issue