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: svn://svn.icculus.org/gtkradiant/GtkRadiant/trunk@424 8a3a26a2-13c4-0310-b231-cf6edde360e5
This commit is contained in:
rambetter 2011-01-12 03:35:57 +00:00
parent 3b0589dd8b
commit 3326472fee
2 changed files with 26 additions and 0 deletions

View 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);
// 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);

View File

@ -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 ) {