diff --git a/Quake/chase.c b/Quake/chase.c index ff1a2c74..de5570b5 100644 --- a/Quake/chase.c +++ b/Quake/chase.c @@ -98,7 +98,7 @@ void Chase_UpdateForDrawing (void) // make sure camera is not in or behind a wall TraceLine(r_refdef.vieworg, ideal, temp); - if (Length(temp) != 0) + if (VectorLength(temp) != 0) VectorCopy(temp, ideal); // place camera diff --git a/Quake/cl_main.c b/Quake/cl_main.c index 0e131e96..bee4d5ea 100644 --- a/Quake/cl_main.c +++ b/Quake/cl_main.c @@ -724,7 +724,7 @@ void CL_Tracepos_f (void) VectorScale(vpn, 8192.0, v); TraceLine(r_refdef.vieworg, v, w); - if (Length(w) == 0) + if (VectorLength(w) == 0) Con_Printf ("Tracepos: trace didn't hit anything\n"); else Con_Printf ("Tracepos: (%i %i %i)\n", (int)w[0], (int)w[1], (int)w[2]); diff --git a/Quake/gl_model.c b/Quake/gl_model.c index 44879ef8..9bb0cfd3 100644 --- a/Quake/gl_model.c +++ b/Quake/gl_model.c @@ -789,8 +789,8 @@ void Mod_LoadTexinfo (lump_t *l) { for (j=0 ; j<8 ; j++) out->vecs[0][j] = LittleFloat (in->vecs[0][j]); - len1 = Length (out->vecs[0]); - len2 = Length (out->vecs[1]); + len1 = VectorLength (out->vecs[0]); + len2 = VectorLength (out->vecs[1]); len1 = (len1 + len2)/2; if (len1 < 0.32) out->mipadjust = 4; @@ -1409,7 +1409,7 @@ float RadiusFromBounds (vec3_t mins, vec3_t maxs) corner[i] = fabs(mins[i]) > fabs(maxs[i]) ? fabs(mins[i]) : fabs(maxs[i]); } - return Length (corner); + return VectorLength (corner); } /* diff --git a/Quake/gl_rlight.c b/Quake/gl_rlight.c index 09183888..26617f96 100644 --- a/Quake/gl_rlight.c +++ b/Quake/gl_rlight.c @@ -92,7 +92,7 @@ void R_RenderDlight (dlight_t *light) rad = light->radius * 0.35; VectorSubtract (light->origin, r_origin, v); - if (Length (v) < rad) + if (VectorLength (v) < rad) { // view is inside the dlight AddLightBlend (1, 0.5, 0, light->radius * 0.0003); return; diff --git a/Quake/mathlib.c b/Quake/mathlib.c index 94deace6..5590bebc 100644 --- a/Quake/mathlib.c +++ b/Quake/mathlib.c @@ -234,7 +234,7 @@ void VectorAngles (const vec3_t forward, vec3_t angles) temp[0] = forward[0]; temp[1] = forward[1]; temp[2] = 0; - angles[PITCH] = -atan2(forward[2], Length(temp)) / M_PI_DIV_180; + angles[PITCH] = -atan2(forward[2], VectorLength(temp)) / M_PI_DIV_180; angles[YAW] = atan2(forward[1], forward[0]) / M_PI_DIV_180; angles[ROLL] = 0; } @@ -317,27 +317,16 @@ void 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 Length(vec3_t v) +vec_t VectorLength(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; + return sqrt(DotProduct(v,v)); } float VectorNormalize (vec3_t v) { float length, ilength; - length = v[0]*v[0] + v[1]*v[1] + v[2]*v[2]; - length = sqrt (length); // FIXME + length = sqrt(DotProduct(v,v)); if (length) { diff --git a/Quake/mathlib.h b/Quake/mathlib.h index 95398997..276ab1d7 100644 --- a/Quake/mathlib.h +++ b/Quake/mathlib.h @@ -46,7 +46,7 @@ extern int nanmask; #define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask) -#define CLAMP(min, x, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) //johnfitz +#define CLAMP(_minval, x, _maxval) ((x) < (_minval) ? (_minval) : (x) > (_maxval) ? (_maxval) : (x)) #define Q_rint(x) ((x) > 0 ? (int)((x) + 0.5) : (int)((x) - 0.5)) //johnfitz -- from joequake @@ -101,7 +101,7 @@ void _VectorAdd (vec3_t veca, vec3_t vecb, vec3_t out); void _VectorCopy (vec3_t in, vec3_t out); int VectorCompare (vec3_t v1, vec3_t v2); -vec_t Length (vec3_t v); +vec_t VectorLength (vec3_t v); void CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross); float VectorNormalize (vec3_t v); // returns vector length void VectorInverse (vec3_t v); @@ -121,7 +121,6 @@ int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct mplane_s *plane); float anglemod(float a); - #define BOX_ON_PLANE_SIDE(emins, emaxs, p) \ (((p)->type < 3)? \ ( \ diff --git a/Quake/pr_cmds.c b/Quake/pr_cmds.c index 2be29891..6f99b224 100644 --- a/Quake/pr_cmds.c +++ b/Quake/pr_cmds.c @@ -908,7 +908,7 @@ void PF_findradius (void) continue; for (j=0 ; j<3 ; j++) eorg[j] = org[j] - (ent->v.origin[j] + (ent->v.mins[j] + ent->v.maxs[j])*0.5); - if (Length(eorg) > rad) + if (VectorLength(eorg) > rad) continue; ent->v.chain = EDICT_TO_PROG(chain); diff --git a/Quake/r_alias.c b/Quake/r_alias.c index bdc49e29..d3ba4694 100644 --- a/Quake/r_alias.c +++ b/Quake/r_alias.c @@ -326,7 +326,7 @@ void R_SetupAliasLighting (entity_t *e) if (cl_dlights[i].die >= cl.time) { VectorSubtract (currententity->origin, cl_dlights[i].origin, dist); - add = cl_dlights[i].radius - Length(dist); + add = cl_dlights[i].radius - VectorLength(dist); if (add > 0) VectorMA (lightcolor, add, cl_dlights[i].color, lightcolor); } diff --git a/Quake/sv_user.c b/Quake/sv_user.c index ec5e7948..c1468bff 100644 --- a/Quake/sv_user.c +++ b/Quake/sv_user.c @@ -244,7 +244,7 @@ void SV_WaterMove (void) else wishvel[2] += cmd.upmove; - wishspeed = Length(wishvel); + wishspeed = VectorLength(wishvel); if (wishspeed > sv_maxspeed.value) { VectorScale (wishvel, sv_maxspeed.value/wishspeed, wishvel); @@ -255,7 +255,7 @@ void SV_WaterMove (void) // // water friction // - speed = Length (velocity); + speed = VectorLength (velocity); if (speed) { newspeed = speed - host_frametime * speed * sv_friction.value; @@ -313,7 +313,7 @@ void SV_NoclipMove (void) velocity[2] = forward[2]*cmd.forwardmove + right[2]*cmd.sidemove; velocity[2] += cmd.upmove*2; //doubled to match running speed - if (Length (velocity) > sv_maxspeed.value) + if (VectorLength (velocity) > sv_maxspeed.value) { VectorNormalize (velocity); VectorScale (velocity, sv_maxspeed.value, velocity); diff --git a/Quake/view.c b/Quake/view.c index bf7fcfc7..85154933 100644 --- a/Quake/view.c +++ b/Quake/view.c @@ -121,7 +121,7 @@ float V_CalcBob (void) // (don't count Z, or jumping messes it up) bob = sqrt(cl.velocity[0]*cl.velocity[0] + cl.velocity[1]*cl.velocity[1]) * cl_bob.value; -//Con_Printf ("speed: %5.1f\n", Length(cl.velocity)); +//Con_Printf ("speed: %5.1f\n", VectorLength(cl.velocity)); bob = bob*0.3 + bob*0.7*sin(cycle); if (bob > 4) bob = 4;