From: rambetter Date: Wed, 12 Jan 2011 03:35:57 +0000 (+0000) Subject: Adding MATHLIB_VECTOR_NORMALIZE_PRECISION_FIX in mathlib to control which X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=cfeead8ceb6b09a04f45dbd6c0ca694123449a3b;p=xonotic%2Fnetradiant.git Adding MATHLIB_VECTOR_NORMALIZE_PRECISION_FIX in mathlib to control which version of code in VectorNormalize() is used. Yes, I put the old code back in there, and it's active if MATHLIB_VECTOR_NORMALIZE_PRECISION_FIX is 0. Right now it's 1, so the fixed code is active. I need this quick way to test regression tests. git-svn-id: https://zerowing.idsoftware.com/svn/radiant/GtkRadiant/trunk@424 8a3a26a2-13c4-0310-b231-cf6edde360e5 --- diff --git a/libs/mathlib.h b/libs/mathlib.h index cac3597b..172d9eac 100644 --- a/libs/mathlib.h +++ b/libs/mathlib.h @@ -90,6 +90,9 @@ vec_t VectorLength(vec3_t v); void VectorMA( const vec3_t va, vec_t scale, const vec3_t vb, vec3_t vc ); void _CrossProduct (vec3_t v1, vec3_t v2, vec3_t cross); +// I need this define in order to test some of the regression tests from time to time. +// This define affect the precision of VectorNormalize() function only. +#define MATHLIB_VECTOR_NORMALIZE_PRECISION_FIX 1 vec_t VectorNormalize (const vec3_t in, vec3_t out); vec_t ColorNormalize( const vec3_t in, vec3_t out ); void VectorInverse (vec3_t v); diff --git a/libs/mathlib/mathlib.c b/libs/mathlib/mathlib.c index 0738c9c4..83555254 100644 --- a/libs/mathlib/mathlib.c +++ b/libs/mathlib/mathlib.c @@ -176,6 +176,8 @@ void _VectorCopy (vec3_t in, vec3_t out) vec_t VectorNormalize( const vec3_t in, vec3_t out ) { +#if MATHLIB_VECTOR_NORMALIZE_PRECISION_FIX + // The sqrt() function takes double as an input and returns double as an // output according the the man pages on Debian and on FreeBSD. Therefore, // I don't see a reason why using a double outright (instead of using the @@ -199,6 +201,27 @@ vec_t VectorNormalize( const vec3_t in, vec3_t out ) { out[2] = (vec_t) (z / length); return (vec_t) length; + +#else + + vec_t length, ilength; + + length = (vec_t)sqrt (in[0]*in[0] + in[1]*in[1] + in[2]*in[2]); + if (length == 0) + { + VectorClear (out); + return 0; + } + + ilength = 1.0f/length; + out[0] = in[0]*ilength; + out[1] = in[1]*ilength; + out[2] = in[2]*ilength; + + return length; + +#endif + } vec_t ColorNormalize( const vec3_t in, vec3_t out ) {