From a50ae736637960d427d4286e7e327b0041660dda Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Thu, 19 Jan 2017 20:29:40 +0100 Subject: [PATCH] Fix issue in GJK algorithm --- src/collision/narrowphase/GJK/GJKAlgorithm.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp index dec43865..e1649af0 100644 --- a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp +++ b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp @@ -173,8 +173,6 @@ bool GJKAlgorithm::testCollision(const NarrowPhaseInfo* narrowPhaseInfo, } while((isPolytopeShape && !simplex.isFull()) || (!isPolytopeShape && !simplex.isFull() && distSquare > MACHINE_EPSILON * simplex.getMaxLengthSquareOfAPoint())); - bool isEPAResultValid = false; - // If no contact has been found (penetration case) if (!contactFound) { @@ -182,10 +180,14 @@ bool GJKAlgorithm::testCollision(const NarrowPhaseInfo* narrowPhaseInfo, // again but on the enlarged objects to compute a simplex polytope that contains // the origin. Then, we give that simplex polytope to the EPA algorithm to compute // the correct penetration depth and contact points between the enlarged objects. - isEPAResultValid = computePenetrationDepthForEnlargedObjects(narrowPhaseInfo, contactPointInfo, v); + if(computePenetrationDepthForEnlargedObjects(narrowPhaseInfo, contactPointInfo, v)) { + + // A contact has been found with EPA algorithm, we return true + return true; + } } - if ((contactFound || !isEPAResultValid) && distSquare > MACHINE_EPSILON) { + if (contactFound && distSquare > MACHINE_EPSILON) { // Compute the closet points of both objects (without the margins) simplex.computeClosestPointsOfAandB(pA, pB);