]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
added some tolerances in Mod_Q1BSP_RecursiveHullCheck so that it is
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 13 Jul 2007 08:09:48 +0000 (08:09 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 13 Jul 2007 08:09:48 +0000 (08:09 +0000)
likely to give sane results if an endpoint is exactly on a plane
(possibly negating the need for the nudge off the impact plane, but that
remains in the code)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7484 d7cf8633-e32d-0410-b094-e92efae38249

model_brush.c

index b6b2500630613a5d90d57a9df4421fe73f352bb0..91a7cf913249e094c9ca04e63d4d9e122725e206 100644 (file)
@@ -613,6 +613,7 @@ RecursiveHullCheckTraceInfo_t;
 
 // 1/32 epsilon to keep floating point happy
 #define DIST_EPSILON (0.03125)
+#define DIST_EPSILON2 (0)
 
 #define HULLCHECKSTATE_EMPTY 0
 #define HULLCHECKSTATE_SOLID 1
@@ -695,9 +696,21 @@ loc0:
                t2 = DotProduct (plane->normal, p2) - plane->dist;
        }
 
-       if (t1 < 0)
+       // this has some tolerances so that it never intersects with a plane if
+       // one of the endpoints lies exactly on it
+       // the objective of this code is to allow points that are exactly on a
+       // plane to still give sane results (improving physics stability)
+       if (t2 < t1)
        {
-               if (t2 < 0)
+               if (t2 >= -DIST_EPSILON2)
+               {
+#if COLLISIONPARANOID >= 3
+                       Con_Print(">");
+#endif
+                       num = node->children[0];
+                       goto loc0;
+               }
+               if (t1 <= DIST_EPSILON2)
                {
 #if COLLISIONPARANOID >= 3
                        Con_Print("<");
@@ -705,11 +718,11 @@ loc0:
                        num = node->children[1];
                        goto loc0;
                }
-               side = 1;
+               side = 0;
        }
        else
        {
-               if (t2 >= 0)
+               if (t1 >= -DIST_EPSILON2)
                {
 #if COLLISIONPARANOID >= 3
                        Con_Print(">");
@@ -717,7 +730,15 @@ loc0:
                        num = node->children[0];
                        goto loc0;
                }
-               side = 0;
+               if (t2 <= DIST_EPSILON2)
+               {
+#if COLLISIONPARANOID >= 3
+                       Con_Print("<");
+#endif
+                       num = node->children[1];
+                       goto loc0;
+               }
+               side = 1;
        }
 
        // the line intersects, find intersection point