diff --git a/tools/quake3/q3map2/map.c b/tools/quake3/q3map2/map.c index 23d7ca49..cc7963b0 100644 --- a/tools/quake3/q3map2/map.c +++ b/tools/quake3/q3map2/map.c @@ -293,7 +293,29 @@ void SnapPlane( vec3_t normal, vec_t *dist ) SnapPlaneImproved() snaps a plane to normal/distance epsilons, improved code */ -void SnapPlaneImproved(vec3_t normal, vec_t *dist, vec3_t center) +void SnapPlaneImproved(vec3_t normal, vec_t *dist) +{ + vec_t distNearestInt; + + SnapNormal(normal); + + if (VectorIsOnAxis(normal)) + { + // Only snap distance if the normal is an axis. Otherwise there + // is nothing "natural" about snapping the distance to an integer. + distNearestInt = Q_rint(*dist); + if (-distanceEpsilon < *dist - distNearestInt && *dist - distNearestInt < distanceEpsilon) + { + *dist = distNearestInt; + } + } +} + +/* +SnapPlaneImprovedWithCenter() +snaps a plane to normal/distance epsilons, improved code uses center +*/ +void SnapPlaneImprovedWithCenter(vec3_t normal, vec_t *dist, const vec3_t center) { vec_t distNearestInt; @@ -331,8 +353,27 @@ int FindFloatPlane( vec3_t normal, vec_t dist, int numPoints, vec3_t *points ) vec_t d; - /* hash the plane */ +#if EXPERIMENTAL_SNAP_PLANE_FIX + vec3_t center; + + if (numPoints > 0) + { + VectorClear(center); + for (i = 0; i < numPoints; i++) + { + VectorAdd(center, points[i], center); + } + for (j = 0; j < 3; j++) { center[j] = center[j] / numPoints; } + SnapPlaneImprovedWithCenter(normal, &dist, center); + } + else + { + SnapPlaneImproved(normal, &dist); + } +#else SnapPlane( normal, &dist ); +#endif + /* hash the plane */ hash = (PLANE_HASHES - 1) & (int) fabs( dist ); /* search the border bins as well */ diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index 27bc448a..c4881b82 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -125,6 +125,7 @@ constants /* temporary hacks and tests (please keep off in SVN to prevent anyone's legacy map from screwing up) */ #define EXPERIMENTAL_HIGH_PRECISION_MATH_Q3MAP2_FIXES 1 #define EXPERIMENTAL_SNAP_NORMAL_FIX 1 +#define EXPERIMENTAL_SNAP_PLANE_FIX 1 /* general */ #define MAX_QPATH 64