From 3ea562d40465fba1fb9ed9fb3ee4db94e3e3aea7 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 29 Mar 2019 13:28:53 +0100 Subject: [PATCH] collide: handle degenerate case for into-sphere test more robustly This case happens, for example, when colliding a capsule with identical begin and end points into a sphere. --- panda/src/collide/collisionSphere.cxx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/panda/src/collide/collisionSphere.cxx b/panda/src/collide/collisionSphere.cxx index aacc43fcb2..0d3275ec36 100644 --- a/panda/src/collide/collisionSphere.cxx +++ b/panda/src/collide/collisionSphere.cxx @@ -620,14 +620,20 @@ intersects_line(double &t1, double &t2, double A = dot(delta, delta); - nassertr(A != 0.0, false); - LVector3 fc = from - get_center(); - double B = 2.0f* dot(delta, fc); double fc_d2 = dot(fc, fc); double radius = get_radius() + inflate_radius; double C = fc_d2 - radius * radius; + if (A == 0.0) { + // Degenerate case where delta is zero. This is effectively a test + // against a point (or sphere, for nonzero inflate_radius). + t1 = 0.0; + t2 = 0.0; + return C < 0.0; + } + + double B = 2.0f * dot(delta, fc); double radical = B*B - 4.0*A*C; if (IS_NEARLY_ZERO(radical)) {