From 3da906441cc03acf05084b4ce25b9ec700cd3c34 Mon Sep 17 00:00:00 2001 From: rambetter Date: Tue, 4 Jan 2011 06:48:32 +0000 Subject: [PATCH] Fixing SnapWeldVectorAccu(). By the way, the original SnapWeldVector() appears to be significantly broken, but I don't think it should be fixed at this point. I'm beginning to think that FixWinding() should not be called during the chop winding procedure. git-svn-id: svn://svn.icculus.org/gtkradiant/GtkRadiant/branches/Rambetter-math-fix-experiments@407 8a3a26a2-13c4-0310-b231-cf6edde360e5 --- tools/quake3/q3map2/brush.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/tools/quake3/q3map2/brush.c b/tools/quake3/q3map2/brush.c index bb38f83..596da29 100644 --- a/tools/quake3/q3map2/brush.c +++ b/tools/quake3/q3map2/brush.c @@ -277,15 +277,18 @@ void SnapWeldVector( vec3_t a, vec3_t b, vec3_t out ) } } +/* +SnapWeldVectorAccu() +welds two vec3_accu_t's into a third, taking into account nearest-to-integer +instead of averaging +*/ void SnapWeldVectorAccu(vec3_accu_t a, vec3_accu_t b, vec3_accu_t out) { - // I have very serious concerns about this function. - // This is a first pass where I just copy the original SnapWeldVector() - // and make sure it works with the higher resolution data types. - // TODO: Examine this function with a fine-toothed comb. - + // I'm just preserving what I think was the intended logic of the original + // SnapWeldVector(). I'm not actually sure where this function should even + // be used. int i; - vec_accu_t ai, bi, outi; + vec_accu_t ai, bi, ad, bd; if (a == NULL || b == NULL || out == NULL) Error("SnapWeldVectorAccu: NULL argument"); @@ -293,16 +296,20 @@ void SnapWeldVectorAccu(vec3_accu_t a, vec3_accu_t b, vec3_accu_t out) for (i = 0; i < 3; i++) { ai = Q_rintAccu(a[i]); - bi = Q_rintAccu(a[i]); // Note, it's using a[i]. This is from legacy code. + bi = Q_rintAccu(b[i]); + ad = fabs(ai - a[i]); + bd = fabs(bi - b[i]); - if (ai == a[i]) out[i] = a[i]; - else if (bi == b[i]) out[i] = b[i]; - - else if (fabs(ai - a[i]) < fabs(bi < b[i])) out[i] = a[i]; - else out[i] = b[i]; - - outi = Q_rintAccu(out[i]); - if (fabs(outi - out[i]) <= SNAP_EPSILON) out[i] = outi; + if (ad < bd) + { + if (ad < SNAP_EPSILON) out[i] = ai; + else out[i] = a[i]; + } + else + { + if (bd < SNAP_EPSILON) out[i] = bi; + else out[i] = b[i]; + } } }