From: Rudolf Polzer Date: Fri, 31 Dec 2010 17:54:33 +0000 (+0100) Subject: Author: rambetter X-Git-Tag: xonotic-v0.5.0~75 X-Git-Url: https://de.git.xonotic.org/?a=commitdiff_plain;h=7a04b6fdeaa81ce7f064184e91c5d3739a971e6a;p=xonotic%2Fnetradiant.git Author: rambetter Date: Thu Dec 30 21:03:13 2010 New Revision: 390 Modified: GtkRadiant/trunk/libs/mathlib.h GtkRadiant/trunk/libs/mathlib/mathlib.c GtkRadiant/trunk/tools/quake3/common/polylib.c Log: Undoing commits r363 and r371 as it pertains to polylib.c, mathlib.c, and mathlib.h (the regression tests have not been removed). Trunk is now restored to a state that it was in before I started trying to fix the math accuracy errors in q3map2. Commits r363 and r371 were "correct" and did improve math accuracy significantly, but unfortunately the underlying cause of math accuracy issues is something else, which is being addressed in branch Rambetter-math-fix-experiments currently. I'm taking the BSD approach here, which is "we not going to partially fix the problem. it's all or nothing". Otherwise it's just too risky in my opinion. I don't like playing Whack-A-Mole. Someday, we might merge Rambetter-math-fix-experiments branch to trunk. Sorry about all these needless commits to trunk. --- diff --git a/libs/mathlib.h b/libs/mathlib.h index 1a86094d..d206d330 100644 --- a/libs/mathlib.h +++ b/libs/mathlib.h @@ -89,7 +89,6 @@ 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); vec_t VectorNormalize (const vec3_t in, vec3_t out); -vec_t VectorSetLength (const vec3_t in, vec_t length, vec3_t out); vec_t ColorNormalize( const vec3_t in, vec3_t out ); void VectorInverse (vec3_t v); void VectorPolar(vec3_t v, float radius, float theta, float phi); diff --git a/libs/mathlib/mathlib.c b/libs/mathlib/mathlib.c index 0d134a51..c549cb10 100644 --- a/libs/mathlib/mathlib.c +++ b/libs/mathlib/mathlib.c @@ -119,7 +119,7 @@ void _VectorCopy (vec3_t in, vec3_t out) } vec_t VectorNormalize( const vec3_t in, vec3_t out ) { - vec_t length; + vec_t length, ilength; length = (vec_t)sqrt (in[0]*in[0] + in[1]*in[1] + in[2]*in[2]); if (length == 0) @@ -128,28 +128,14 @@ vec_t VectorNormalize( const vec3_t in, vec3_t out ) { return 0; } - out[0] = in[0]/length; - out[1] = in[1]/length; - out[2] = in[2]/length; + ilength = 1.0f/length; + out[0] = in[0]*ilength; + out[1] = in[1]*ilength; + out[2] = in[2]*ilength; return length; } -vec_t VectorSetLength(const vec3_t in, vec_t length, vec3_t out) { - vec_t origLength; - - origLength = (vec_t) sqrt((in[0] * in[0]) + (in[1] * in[1]) + (in[2] * in[2])); - if (origLength == 0) - { - VectorClear(out); - return 0; - } - - VectorScale(in, length / origLength, out); - - return origLength; -} - vec_t ColorNormalize( const vec3_t in, vec3_t out ) { float max, scale; diff --git a/tools/quake3/common/polylib.c b/tools/quake3/common/polylib.c index b62d12ff..fc8805e7 100644 --- a/tools/quake3/common/polylib.c +++ b/tools/quake3/common/polylib.c @@ -207,83 +207,6 @@ BaseWindingForPlane ================= */ winding_t *BaseWindingForPlane (vec3_t normal, vec_t dist) -{ - // The goal in this function is to replicate the exact behavior that was in the original - // BaseWindingForPlane() function (see below). The only thing we're going to change is the - // accuracy of the operation. The original code gave a preference for the vup vector to start - // out as (0, 0, 1), unless the normal had a dominant Z value, in which case vup started out - // as (1, 0, 0). After that, vup was "bent" [along the plane defined by normal and vup] to - // become perpendicular to normal. After that the vright vector was computed as the cross - // product of vup and normal. - - // Once these vectors are calculated, I'm constructing the winding points in exactly the same - // way as was done in the original function. Orientation is the same. - - // Note that the 4 points in the returned winding_t may actually not be necessary (3 might - // be enough). However, I want to minimize the chance of ANY bugs popping up due to any - // change in behavior of this function. Therefore, behavior stays exactly the same, except - // for precision of math. Performance might be better in the new function as well. - - int x, i; - vec_t max, v; - vec3_t vright, vup, org; - winding_t *w; - - max = -BOGUS_RANGE; - x = -1; - for (i = 0; i < 3; i++) { - v = fabs(normal[i]); - if (v > max) { - x = i; - max = v; - } - } - if (x == -1) Error("BaseWindingForPlane: no axis found"); - - switch (x) { - case 0: // Fall through to next case. - case 1: - vright[0] = -normal[1]; - vright[1] = normal[0]; - vright[2] = 0; - break; - case 2: - vright[0] = 0; - vright[1] = -normal[2]; - vright[2] = normal[1]; - break; - } - CrossProduct(normal, vright, vup); - - // IMPORTANT NOTE: vright and vup are NOT unit vectors at this point. - // However, normal, vup, and vright are pairwise perpendicular. - - VectorSetLength(vup, MAX_WORLD_COORD * 2, vup); - VectorSetLength(vright, MAX_WORLD_COORD * 2, vright); - VectorScale(normal, dist, org); - - w = AllocWinding(4); - - VectorSubtract(org, vright, w->p[0]); - VectorAdd(w->p[0], vup, w->p[0]); - - VectorAdd(org, vright, w->p[1]); - VectorAdd(w->p[1], vup, w->p[1]); - - VectorAdd(org, vright, w->p[2]); - VectorSubtract(w->p[2], vup, w->p[2]); - - VectorSubtract(org, vright, w->p[3]); - VectorSubtract(w->p[3], vup, w->p[3]); - - w->numpoints = 4; - - return w; -} - -// Old function, not used but here for reference. Please do not modify it. -// (You may remove it at some point.) -winding_t *_BaseWindingForPlane_orig_(vec3_t normal, vec_t dist) { int i, x; vec_t max, v;