From de95e15147e8edf8d72a2f1177e7f8de06ebb0c5 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Wed, 8 Nov 2017 21:28:00 +0100 Subject: [PATCH] Fix issue with the shape order in concave vs convex middle-phase collision detection --- src/collision/MiddlePhaseTriangleCallback.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/collision/MiddlePhaseTriangleCallback.cpp b/src/collision/MiddlePhaseTriangleCallback.cpp index de6c22ea..9d163799 100644 --- a/src/collision/MiddlePhaseTriangleCallback.cpp +++ b/src/collision/MiddlePhaseTriangleCallback.cpp @@ -38,12 +38,19 @@ void MiddlePhaseTriangleCallback::testTriangle(uint meshSubPart, uint triangleIn TriangleShape(trianglePoints[0], trianglePoints[1], trianglePoints[2], verticesNormals, meshSubPart, triangleIndex); + bool isShape1Convex = mOverlappingPair->getShape1()->getCollisionShape()->isConvex(); + ProxyShape* shape1 = isShape1Convex ? mConvexProxyShape : mConcaveProxyShape; + ProxyShape* shape2 = isShape1Convex ? mConcaveProxyShape : mConvexProxyShape; + // Create a narrow phase info for the narrow-phase collision detection NarrowPhaseInfo* firstNarrowPhaseInfo = narrowPhaseInfoList; narrowPhaseInfoList = new (mAllocator.allocate(sizeof(NarrowPhaseInfo))) - NarrowPhaseInfo(mOverlappingPair, mConvexProxyShape->getCollisionShape(), - triangleShape, mConvexProxyShape->getLocalToWorldTransform(), - mConcaveProxyShape->getLocalToWorldTransform(), mConvexProxyShape->getCachedCollisionData(), - mConcaveProxyShape->getCachedCollisionData(), mAllocator); + NarrowPhaseInfo(mOverlappingPair, + isShape1Convex ? mConvexProxyShape->getCollisionShape() : triangleShape, + isShape1Convex ? triangleShape : mConvexProxyShape->getCollisionShape(), + shape1->getLocalToWorldTransform(), + shape2->getLocalToWorldTransform(), + shape1->getCachedCollisionData(), + shape2->getCachedCollisionData(), mAllocator); narrowPhaseInfoList->next = firstNarrowPhaseInfo; }