]> de.git.xonotic.org Git - xonotic/netradiant.git/commitdiff
Adding MATHLIB_VECTOR_NORMALIZE_PRECISION_FIX in mathlib to control which
authorrambetter <rambetter>
Wed, 12 Jan 2011 03:35:57 +0000 (03:35 +0000)
committerrambetter <rambetter>
Wed, 12 Jan 2011 03:35:57 +0000 (03:35 +0000)
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: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@424 8a3a26a2-13c4-0310-b231-cf6edde360e5

libs/mathlib.h
libs/mathlib/mathlib.c

index cac3597b0a2a46afc8fce60fb8489288db2fe83d..172d9eac2d75da09195ae4cb70a06eff17774319 100644 (file)
@@ -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);
 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);
 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);
index 0738c9c44dd2fa1706c601e679c1bc2565104e18..835552549f7f22ff2682308dc0494900e3de9b8f 100644 (file)
@@ -176,6 +176,8 @@ void _VectorCopy (vec3_t in, vec3_t out)
 
 vec_t VectorNormalize( const 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
        // 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;
        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 ) {
 }
 
 vec_t ColorNormalize( const vec3_t in, vec3_t out ) {