From 3f5916a280c5efceec541076b0d564d9fb7901e2 Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Mon, 3 Jun 2019 07:12:50 +0200 Subject: [PATCH] Working on testOverlap() and testCollisionMethods --- CHANGELOG.md | 8 + src/collision/CollisionDetection.cpp | 754 ++++++------------ src/collision/CollisionDetection.h | 58 +- .../narrowphase/CapsuleVsCapsuleAlgorithm.cpp | 8 +- .../narrowphase/CapsuleVsCapsuleAlgorithm.h | 3 +- .../CapsuleVsConvexPolyhedronAlgorithm.cpp | 9 +- .../CapsuleVsConvexPolyhedronAlgorithm.h | 3 +- ...xPolyhedronVsConvexPolyhedronAlgorithm.cpp | 9 +- ...vexPolyhedronVsConvexPolyhedronAlgorithm.h | 5 +- .../narrowphase/SAT/SATAlgorithm.cpp | 19 +- src/collision/narrowphase/SAT/SATAlgorithm.h | 4 +- .../narrowphase/SphereVsCapsuleAlgorithm.cpp | 5 +- .../narrowphase/SphereVsCapsuleAlgorithm.h | 3 +- .../SphereVsConvexPolyhedronAlgorithm.cpp | 11 +- .../SphereVsConvexPolyhedronAlgorithm.h | 5 +- .../narrowphase/SphereVsSphereAlgorithm.cpp | 5 +- .../narrowphase/SphereVsSphereAlgorithm.h | 3 +- src/containers/Set.h | 2 +- src/engine/CollisionWorld.cpp | 33 +- src/engine/CollisionWorld.h | 64 +- src/systems/BroadPhaseSystem.h | 2 +- test/tests/collision/TestCollisionWorld.h | 97 +-- 22 files changed, 370 insertions(+), 740 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cedb3ff7..619ba311 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Develop + +### Changed + + - The CollisionWorld::testCollision() methods do not have the 'categoryMaskBits' parameter anymore. + - The CollisionWorld::testOverlap() methods do not have the 'categoryMaskBits' parameter anymore. + ## Release Candidate ### Fixed @@ -25,6 +32,7 @@ - The methods CollisionBody::getProxyShapesList() has been remove. You can now use the CollisionBody::getNbProxyShapes() method to know the number of proxy-shapes of a body and the CollisionBody::getProxyShape(uint proxyShapeIndex) method to get a given proxy-shape of the body. + - The CollisionWorld::testAABBOverlap() methods have been removed. ## Version 0.7.0 (May 1, 2018) diff --git a/src/collision/CollisionDetection.cpp b/src/collision/CollisionDetection.cpp index 04d266ba..f38c4982 100644 --- a/src/collision/CollisionDetection.cpp +++ b/src/collision/CollisionDetection.cpp @@ -90,7 +90,7 @@ void CollisionDetection::computeCollisionDetection() { computeBroadPhase(); // Compute the middle-phase collision detection - computeMiddlePhase(); + computeMiddlePhase(mOverlappingPairs, mNarrowPhaseInput); // Compute the narrow-phase collision detection computeNarrowPhase(); @@ -142,9 +142,7 @@ void CollisionDetection::removeNonOverlappingPairs() { } // Take a list of overlapping nodes in the broad-phase and create new overlapping pairs if necessary -void CollisionDetection::updateOverlappingPairs(List>& overlappingNodes) { - - List newOverlappingPairs(mMemoryManager.getPoolAllocator(), overlappingNodes.size()); +void CollisionDetection::updateOverlappingPairs(const List>& overlappingNodes) { // For each overlapping pair of nodes for (uint i=0; i < overlappingNodes.size(); i++) { @@ -196,7 +194,6 @@ void CollisionDetection::updateOverlappingPairs(List>& overlappin // Add the new overlapping pair mOverlappingPairs.add(Pair, OverlappingPair*>(pairID, newPair)); - newOverlappingPairs.add(newPair); } } } @@ -205,15 +202,15 @@ void CollisionDetection::updateOverlappingPairs(List>& overlappin } // Compute the middle-phase collision detection -void CollisionDetection::computeMiddlePhase() { +void CollisionDetection::computeMiddlePhase(OverlappingPairMap& overlappingPairs, NarrowPhaseInput& narrowPhaseInput) { RP3D_PROFILE("CollisionDetection::computeMiddlePhase()", mProfiler); // Reserve memory for the narrow-phase input using cached capacity from previous frame - mNarrowPhaseInput.reserveMemory(); + narrowPhaseInput.reserveMemory(); // For each possible collision pair of bodies - for (auto it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ++it) { + for (auto it = overlappingPairs.begin(); it != overlappingPairs.end(); ++it) { OverlappingPair* pair = it->second; @@ -240,7 +237,7 @@ void CollisionDetection::computeMiddlePhase() { const Entity body1Entity = body1->getEntity(); const Entity body2Entity = body2->getEntity(); - // Check that at least one body is awake and not static + // Check that at least one body is enabled (active and awake) and not static bool isBody1Active = !mWorld->mBodyComponents.getIsEntityDisabled(body1Entity) && body1->getType() != BodyType::STATIC; bool isBody2Active = !mWorld->mBodyComponents.getIsEntityDisabled(body2Entity) && body2->getType() != BodyType::STATIC; if (!isBody1Active && !isBody2Active) continue; @@ -261,7 +258,7 @@ void CollisionDetection::computeMiddlePhase() { // No middle-phase is necessary, simply create a narrow phase info // for the narrow-phase collision detection - mNarrowPhaseInput.addNarrowPhaseTest(pair, shape1->getCollisionShape(), shape2->getCollisionShape(), + narrowPhaseInput.addNarrowPhaseTest(pair, shape1->getCollisionShape(), shape2->getCollisionShape(), shape1->getLocalToWorldTransform(), shape2->getLocalToWorldTransform(), algorithmType, mMemoryManager.getSingleFrameAllocator()); @@ -269,7 +266,7 @@ void CollisionDetection::computeMiddlePhase() { // Concave vs Convex algorithm else if ((!isShape1Convex && isShape2Convex) || (!isShape2Convex && isShape1Convex)) { - computeConvexVsConcaveMiddlePhase(pair, mMemoryManager.getSingleFrameAllocator(), mNarrowPhaseInput); + computeConvexVsConcaveMiddlePhase(pair, mMemoryManager.getSingleFrameAllocator(), narrowPhaseInput); } // Concave vs Concave shape else { @@ -337,8 +334,7 @@ void CollisionDetection::computeConvexVsConcaveMiddlePhase(OverlappingPair* pair } // Execute the narrow-phase collision detection algorithm on batches -bool CollisionDetection::testNarrowPhaseCollision(NarrowPhaseInput& narrowPhaseInput, bool stopFirstContactFound, - bool reportContacts, MemoryAllocator& allocator) { +bool CollisionDetection::testNarrowPhaseCollision(NarrowPhaseInput& narrowPhaseInput, bool reportContacts, MemoryAllocator& allocator) { bool contactFound = false; @@ -360,38 +356,37 @@ bool CollisionDetection::testNarrowPhaseCollision(NarrowPhaseInput& narrowPhaseI // Compute the narrow-phase collision detection for each kind of collision shapes if (sphereVsSphereBatch.getNbObjects() > 0) { - contactFound |= sphereVsSphereAlgo->testCollision(sphereVsSphereBatch, 0, sphereVsSphereBatch.getNbObjects(), reportContacts, stopFirstContactFound, allocator); - if (stopFirstContactFound && contactFound) return true; + contactFound |= sphereVsSphereAlgo->testCollision(sphereVsSphereBatch, 0, sphereVsSphereBatch.getNbObjects(), reportContacts, allocator); } if (sphereVsCapsuleBatch.getNbObjects() > 0) { - contactFound |= sphereVsCapsuleAlgo->testCollision(sphereVsCapsuleBatch, 0, sphereVsCapsuleBatch.getNbObjects(), reportContacts, stopFirstContactFound, allocator); - if (stopFirstContactFound && contactFound) return true; + contactFound |= sphereVsCapsuleAlgo->testCollision(sphereVsCapsuleBatch, 0, sphereVsCapsuleBatch.getNbObjects(), reportContacts, allocator); } if (capsuleVsCapsuleBatch.getNbObjects() > 0) { - contactFound |= capsuleVsCapsuleAlgo->testCollision(capsuleVsCapsuleBatch, 0, capsuleVsCapsuleBatch.getNbObjects(), reportContacts, stopFirstContactFound, allocator); - if (stopFirstContactFound && contactFound) return true; + contactFound |= capsuleVsCapsuleAlgo->testCollision(capsuleVsCapsuleBatch, 0, capsuleVsCapsuleBatch.getNbObjects(), reportContacts, allocator); } if (sphereVsConvexPolyhedronBatch.getNbObjects() > 0) { - contactFound |= sphereVsConvexPolyAlgo->testCollision(sphereVsConvexPolyhedronBatch, 0, sphereVsConvexPolyhedronBatch.getNbObjects(), reportContacts, stopFirstContactFound, allocator); - if (stopFirstContactFound && contactFound) return true; + contactFound |= sphereVsConvexPolyAlgo->testCollision(sphereVsConvexPolyhedronBatch, 0, sphereVsConvexPolyhedronBatch.getNbObjects(), reportContacts, allocator); } if (capsuleVsConvexPolyhedronBatch.getNbObjects() > 0) { - contactFound |= capsuleVsConvexPolyAlgo->testCollision(capsuleVsConvexPolyhedronBatch, 0, capsuleVsConvexPolyhedronBatch.getNbObjects(), reportContacts, stopFirstContactFound, allocator); - if (stopFirstContactFound && contactFound) return true; + contactFound |= capsuleVsConvexPolyAlgo->testCollision(capsuleVsConvexPolyhedronBatch, 0, capsuleVsConvexPolyhedronBatch.getNbObjects(), reportContacts, allocator); } if (convexPolyhedronVsConvexPolyhedronBatch.getNbObjects() > 0) { - contactFound |= convexPolyVsConvexPolyAlgo->testCollision(convexPolyhedronVsConvexPolyhedronBatch, 0, convexPolyhedronVsConvexPolyhedronBatch.getNbObjects(), reportContacts, stopFirstContactFound, allocator); - if (stopFirstContactFound && contactFound) return true; + contactFound |= convexPolyVsConvexPolyAlgo->testCollision(convexPolyhedronVsConvexPolyhedronBatch, 0, convexPolyhedronVsConvexPolyhedronBatch.getNbObjects(), reportContacts, allocator); } return contactFound; } // Process the potential contacts after narrow-phase collision detection -void CollisionDetection::processAllPotentialContacts(NarrowPhaseInput& narrowPhaseInput, bool updateLastFrameInfo) { +void CollisionDetection::processAllPotentialContacts(NarrowPhaseInput& narrowPhaseInput, bool updateLastFrameInfo, + List& potentialContactPoints, + Map* mapPairIdToContactPairIndex, + List& potentialContactManifolds, + List* contactPairs, + Map>& mapBodyToContactPairs) { - assert(mCurrentContactPairs->size() == 0); - assert(mCurrentMapPairIdToContactPairIndex->size() == 0); + assert(contactPairs->size() == 0); + assert(mapPairIdToContactPairIndex->size() == 0); // get the narrow-phase batches to test for collision NarrowPhaseInfoBatch& sphereVsSphereBatch = narrowPhaseInput.getSphereVsSphereBatch(); @@ -402,12 +397,18 @@ void CollisionDetection::processAllPotentialContacts(NarrowPhaseInput& narrowPha NarrowPhaseInfoBatch& convexPolyhedronVsConvexPolyhedronBatch = narrowPhaseInput.getConvexPolyhedronVsConvexPolyhedronBatch(); // Process the potential contacts - processPotentialContacts(sphereVsSphereBatch, updateLastFrameInfo); - processPotentialContacts(sphereVsCapsuleBatch, updateLastFrameInfo); - processPotentialContacts(capsuleVsCapsuleBatch, updateLastFrameInfo); - processPotentialContacts(sphereVsConvexPolyhedronBatch, updateLastFrameInfo); - processPotentialContacts(capsuleVsConvexPolyhedronBatch, updateLastFrameInfo); - processPotentialContacts(convexPolyhedronVsConvexPolyhedronBatch, updateLastFrameInfo); + processPotentialContacts(sphereVsSphereBatch, updateLastFrameInfo, potentialContactPoints, mapPairIdToContactPairIndex, + potentialContactManifolds, contactPairs, mapBodyToContactPairs); + processPotentialContacts(sphereVsCapsuleBatch, updateLastFrameInfo, potentialContactPoints, mapPairIdToContactPairIndex, + potentialContactManifolds, contactPairs, mapBodyToContactPairs); + processPotentialContacts(capsuleVsCapsuleBatch, updateLastFrameInfo, potentialContactPoints, mapPairIdToContactPairIndex, + potentialContactManifolds, contactPairs, mapBodyToContactPairs); + processPotentialContacts(sphereVsConvexPolyhedronBatch, updateLastFrameInfo, potentialContactPoints, mapPairIdToContactPairIndex, + potentialContactManifolds, contactPairs, mapBodyToContactPairs); + processPotentialContacts(capsuleVsConvexPolyhedronBatch, updateLastFrameInfo, potentialContactPoints, mapPairIdToContactPairIndex, + potentialContactManifolds, contactPairs, mapBodyToContactPairs); + processPotentialContacts(convexPolyhedronVsConvexPolyhedronBatch, updateLastFrameInfo, potentialContactPoints, mapPairIdToContactPairIndex, + potentialContactManifolds, contactPairs, mapBodyToContactPairs); } // Compute the narrow-phase collision detection @@ -421,13 +422,14 @@ void CollisionDetection::computeNarrowPhase() { swapPreviousAndCurrentContacts(); // Test the narrow-phase collision detection on the batches to be tested - testNarrowPhaseCollision(mNarrowPhaseInput, false, true, allocator); + testNarrowPhaseCollision(mNarrowPhaseInput, true, allocator); // Process all the potential contacts after narrow-phase collision - processAllPotentialContacts(mNarrowPhaseInput, true); + processAllPotentialContacts(mNarrowPhaseInput, true, mPotentialContactPoints, mCurrentMapPairIdToContactPairIndex, + mPotentialContactManifolds, mCurrentContactPairs, mMapBodyToContactPairs); // Reduce the number of contact points in the manifolds - reducePotentialContactManifolds(); + reducePotentialContactManifolds(mCurrentContactPairs, mPotentialContactManifolds, mPotentialContactPoints); // Report contacts to the user reportAllContacts(); @@ -440,6 +442,36 @@ void CollisionDetection::computeNarrowPhase() { mNarrowPhaseInput.clear(); } +// Compute the narrow-phase collision detection for the testCollision() methods. +// This method returns true if contacts are found. +bool CollisionDetection::computeNarrowPhaseSnapshot(NarrowPhaseInput& narrowPhaseInput, bool reportContacts) { + + RP3D_PROFILE("CollisionDetection::computeNarrowPhaseSnapshot()", mProfiler); + + MemoryAllocator& allocator = mMemoryManager.getPoolAllocator(); + + // Test the narrow-phase collision detection on the batches to be tested + bool collisionFound = testNarrowPhaseCollision(narrowPhaseInput, reportContacts, allocator); + if (!reportContacts) { + return collisionFound; + } + + List potentialContactPoints(allocator); + List potentialContactManifolds(allocator); + Map mapPairIdToContactPairIndex(allocator); + List contactPairs(allocator); + Map> mapBodyToContactPairs(allocator); + + // Process all the potential contacts after narrow-phase collision + processAllPotentialContacts(narrowPhaseInput, true, potentialContactPoints, &mapPairIdToContactPairIndex, potentialContactManifolds, + &contactPairs, mapBodyToContactPairs); + + // Reduce the number of contact points in the manifolds + reducePotentialContactManifolds(&contactPairs, potentialContactManifolds, potentialContactPoints); + + return collisionFound; +} + // Swap the previous and current contacts lists void CollisionDetection::swapPreviousAndCurrentContacts() { @@ -716,8 +748,13 @@ void CollisionDetection::raycast(RaycastCallback* raycastCallback, mBroadPhaseSystem.raycast(ray, rayCastTest, raycastWithCategoryMaskBits); } -/// Convert the potential contact into actual contacts -void CollisionDetection::processPotentialContacts(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, bool updateLastFrameInfo) { +// Convert the potential contact into actual contacts +void CollisionDetection::processPotentialContacts(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, bool updateLastFrameInfo, + List& potentialContactPoints, + Map* mapPairIdToContactPairIndex, + List& potentialContactManifolds, + List* contactPairs, + Map>& mapBodyToContactPairs) { RP3D_PROFILE("CollisionDetection::processPotentialContacts()", mProfiler); @@ -739,24 +776,24 @@ void CollisionDetection::processPotentialContacts(NarrowPhaseInfoBatch& narrowPh const ContactPointInfo& contactPoint = *(narrowPhaseInfoBatch.contactPoints[i][j]); // Add the contact point to the list of potential contact points - const uint contactPointIndex = static_cast(mPotentialContactPoints.size()); + const uint contactPointIndex = static_cast(potentialContactPoints.size()); - // TODO : We should probably use single frame allocator here for mPotentialContactPoints - // If so, do not forget to call mPotentialContactPoints.clear(true) at the end of frame - mPotentialContactPoints.add(contactPoint); + // TODO : We should probably use single frame allocator here for potentialContactPoints + // If so, do not forget to call potentialContactPoints.clear(true) at the end of frame + potentialContactPoints.add(contactPoint); bool similarManifoldFound = false; // If there is already a contact pair for this overlapping pair OverlappingPair::OverlappingPairId pairId = narrowPhaseInfoBatch.overlappingPairs[i]->getId(); - auto it = mCurrentMapPairIdToContactPairIndex->find(pairId); + auto it = mapPairIdToContactPairIndex->find(pairId); ContactPair* pairContact = nullptr; - if (it != mCurrentMapPairIdToContactPairIndex->end()) { + if (it != mapPairIdToContactPairIndex->end()) { assert(it->first == pairId); const uint pairContactIndex = it->second; - pairContact = &((*mCurrentContactPairs)[pairContactIndex]); + pairContact = &((*contactPairs)[pairContactIndex]); assert(pairContact->potentialContactManifoldsIndices.size() > 0); @@ -766,16 +803,16 @@ void CollisionDetection::processPotentialContacts(NarrowPhaseInfoBatch& narrowPh uint contactManifoldIndex = pairContact->potentialContactManifoldsIndices[m]; // Get the first contact point of the current manifold - assert(mPotentialContactManifolds[contactManifoldIndex].potentialContactPointsIndices.size() > 0); - const uint manifoldContactPointIndex = mPotentialContactManifolds[contactManifoldIndex].potentialContactPointsIndices[0]; - const ContactPointInfo& manifoldContactPoint = mPotentialContactPoints[manifoldContactPointIndex]; + assert(potentialContactManifolds[contactManifoldIndex].potentialContactPointsIndices.size() > 0); + const uint manifoldContactPointIndex = potentialContactManifolds[contactManifoldIndex].potentialContactPointsIndices[0]; + const ContactPointInfo& manifoldContactPoint = potentialContactPoints[manifoldContactPointIndex]; // If we have found a corresponding manifold for the new contact point // (a manifold with a similar contact normal direction) if (manifoldContactPoint.normal.dot(contactPoint.normal) >= mWorld->mConfig.cosAngleSimilarContactManifold) { // Add the contact point to the manifold - mPotentialContactManifolds[contactManifoldIndex].potentialContactPointsIndices.add(contactPointIndex); + potentialContactManifolds[contactManifoldIndex].potentialContactPointsIndices.add(contactPointIndex); similarManifoldFound = true; @@ -789,7 +826,7 @@ void CollisionDetection::processPotentialContacts(NarrowPhaseInfoBatch& narrowPh // Create a new contact manifold for the overlapping pair // TODO : We should probably use single frame allocator here - // If so, do not forget to call mPotentialContactPoints.clear(true) at the end of frame + // If so, do not forget to call potentialContactPoints.clear(true) at the end of frame ContactManifoldInfo contactManifoldInfo(pairId, mMemoryManager.getPoolAllocator()); // Add the contact point to the manifold @@ -804,40 +841,40 @@ void CollisionDetection::processPotentialContacts(NarrowPhaseInfoBatch& narrowPh assert(!mWorld->mBodyComponents.getIsEntityDisabled(body1Entity) || !mWorld->mBodyComponents.getIsEntityDisabled(body2Entity)); // TODO : We should probably use a single frame allocator here - const uint newContactPairIndex = mCurrentContactPairs->size(); + const uint newContactPairIndex = contactPairs->size(); ContactPair overlappingPairContact(pairId, body1Entity, body2Entity, narrowPhaseInfoBatch.overlappingPairs[i]->getShape1()->getEntity(), narrowPhaseInfoBatch.overlappingPairs[i]->getShape2()->getEntity(), newContactPairIndex, mMemoryManager.getPoolAllocator()); - mCurrentContactPairs->add(overlappingPairContact); - pairContact = &((*mCurrentContactPairs)[newContactPairIndex]); - mCurrentMapPairIdToContactPairIndex->add(Pair(pairId, newContactPairIndex)); + contactPairs->add(overlappingPairContact); + pairContact = &((*contactPairs)[newContactPairIndex]); + mapPairIdToContactPairIndex->add(Pair(pairId, newContactPairIndex)); - auto itbodyContactPairs = mMapBodyToContactPairs.find(body1Entity); - if (itbodyContactPairs != mMapBodyToContactPairs.end()) { + auto itbodyContactPairs = mapBodyToContactPairs.find(body1Entity); + if (itbodyContactPairs != mapBodyToContactPairs.end()) { itbodyContactPairs->second.add(newContactPairIndex); } else { - List contactPairs(mMemoryManager.getSingleFrameAllocator(), 1); + List contactPairs(mMemoryManager.getPoolAllocator(), 1); contactPairs.add(newContactPairIndex); - mMapBodyToContactPairs.add(Pair>(body1Entity, contactPairs)); + mapBodyToContactPairs.add(Pair>(body1Entity, contactPairs)); } - itbodyContactPairs = mMapBodyToContactPairs.find(body2Entity); - if (itbodyContactPairs != mMapBodyToContactPairs.end()) { + itbodyContactPairs = mapBodyToContactPairs.find(body2Entity); + if (itbodyContactPairs != mapBodyToContactPairs.end()) { itbodyContactPairs->second.add(newContactPairIndex); } else { - List contactPairs(mMemoryManager.getSingleFrameAllocator(), 1); + List contactPairs(mMemoryManager.getPoolAllocator(), 1); contactPairs.add(newContactPairIndex); - mMapBodyToContactPairs.add(Pair>(body2Entity, contactPairs)); + mapBodyToContactPairs.add(Pair>(body2Entity, contactPairs)); } } assert(pairContact != nullptr); // Add the potential contact manifold - uint contactManifoldIndex = static_cast(mPotentialContactManifolds.size()); - mPotentialContactManifolds.add(contactManifoldInfo); + uint contactManifoldIndex = static_cast(potentialContactManifolds.size()); + potentialContactManifolds.add(contactManifoldInfo); // Add the contact manifold to the overlapping pair contact assert(pairContact->pairId == contactManifoldInfo.pairId); @@ -852,14 +889,16 @@ void CollisionDetection::processPotentialContacts(NarrowPhaseInfoBatch& narrowPh } // Clear the obsolete manifolds and contact points and reduce the number of contacts points of the remaining manifolds -void CollisionDetection::reducePotentialContactManifolds() { +void CollisionDetection::reducePotentialContactManifolds(List* contactPairs, + List& potentialContactManifolds, + const List& potentialContactPoints) const { RP3D_PROFILE("CollisionDetection::reducePotentialContactManifolds()", mProfiler); // Reduce the number of potential contact manifolds in a contact pair - for (uint i=0; i < mCurrentContactPairs->size(); i++) { + for (uint i=0; i < contactPairs->size(); i++) { - ContactPair& contactPair = (*mCurrentContactPairs)[i]; + ContactPair& contactPair = (*contactPairs)[i]; assert(contactPair.potentialContactManifoldsIndices.size() > 0); @@ -871,10 +910,10 @@ void CollisionDetection::reducePotentialContactManifolds() { int minDepthManifoldIndex = -1; for (uint j=0; j < contactPair.potentialContactManifoldsIndices.size(); j++) { - ContactManifoldInfo& manifold = mPotentialContactManifolds[contactPair.potentialContactManifoldsIndices[j]]; + ContactManifoldInfo& manifold = potentialContactManifolds[contactPair.potentialContactManifoldsIndices[j]]; // Get the largest contact point penetration depth of the manifold - const decimal depth = computePotentialManifoldLargestContactDepth(manifold); + const decimal depth = computePotentialManifoldLargestContactDepth(manifold, potentialContactPoints); if (depth < minDepth) { minDepth = depth; @@ -889,14 +928,14 @@ void CollisionDetection::reducePotentialContactManifolds() { } // Reduce the number of potential contact points in the manifolds - for (uint i=0; i < mCurrentContactPairs->size(); i++) { + for (uint i=0; i < contactPairs->size(); i++) { - const ContactPair& pairContact = (*mCurrentContactPairs)[i]; + const ContactPair& pairContact = (*contactPairs)[i]; // For each potential contact manifold for (uint j=0; j < pairContact.potentialContactManifoldsIndices.size(); j++) { - ContactManifoldInfo& manifold = mPotentialContactManifolds[pairContact.potentialContactManifoldsIndices[j]]; + ContactManifoldInfo& manifold = potentialContactManifolds[pairContact.potentialContactManifoldsIndices[j]]; // If there are two many contact points in the manifold if (manifold.potentialContactPointsIndices.size() > MAX_CONTACT_POINTS_IN_MANIFOLD) { @@ -904,7 +943,7 @@ void CollisionDetection::reducePotentialContactManifolds() { Transform shape1LocalToWorldTransoform = mOverlappingPairs[manifold.pairId]->getShape1()->getLocalToWorldTransform(); // Reduce the number of contact points in the manifold - reduceContactPoints(manifold, shape1LocalToWorldTransoform); + reduceContactPoints(manifold, shape1LocalToWorldTransoform, potentialContactPoints); } assert(manifold.potentialContactPointsIndices.size() <= MAX_CONTACT_POINTS_IN_MANIFOLD); @@ -913,14 +952,15 @@ void CollisionDetection::reducePotentialContactManifolds() { } // Return the largest depth of all the contact points of a potential manifold -decimal CollisionDetection::computePotentialManifoldLargestContactDepth(const ContactManifoldInfo& manifold) const { +decimal CollisionDetection::computePotentialManifoldLargestContactDepth(const ContactManifoldInfo& manifold, + const List& potentialContactPoints) const { decimal largestDepth = 0.0f; assert(manifold.potentialContactPointsIndices.size() > 0); for (uint i=0; i < manifold.potentialContactPointsIndices.size(); i++) { - decimal depth = mPotentialContactPoints[manifold.potentialContactPointsIndices[i]].penetrationDepth; + decimal depth = potentialContactPoints[manifold.potentialContactPointsIndices[i]].penetrationDepth; if (depth > largestDepth) { largestDepth = depth; @@ -934,7 +974,8 @@ decimal CollisionDetection::computePotentialManifoldLargestContactDepth(const Co // This is based on the technique described by Dirk Gregorius in his // "Contacts Creation" GDC presentation. This method will reduce the number of // contact points to a maximum of 4 points (but it can be less). -void CollisionDetection::reduceContactPoints(ContactManifoldInfo& manifold, const Transform& shape1ToWorldTransform) { +void CollisionDetection::reduceContactPoints(ContactManifoldInfo& manifold, const Transform& shape1ToWorldTransform, + const List& potentialContactPoints) const { assert(manifold.potentialContactPointsIndices.size() > MAX_CONTACT_POINTS_IN_MANIFOLD); @@ -945,9 +986,6 @@ void CollisionDetection::reduceContactPoints(ContactManifoldInfo& manifold, cons // point we want to keep, we will remove it from this list List candidatePointsIndices(manifold.potentialContactPointsIndices); - // TODO : DELETE THIS - uint nbPoints = candidatePointsIndices.size(); - int8 nbReducedPoints = 0; uint pointsToKeepIndices[MAX_CONTACT_POINTS_IN_MANIFOLD]; @@ -964,7 +1002,7 @@ void CollisionDetection::reduceContactPoints(ContactManifoldInfo& manifold, cons // Compute the contact normal of the manifold (we use the first contact point) // in the local-space of the first collision shape - const Vector3 contactNormalShape1Space = worldToShape1Transform.getOrientation() * mPotentialContactPoints[candidatePointsIndices[0]].normal; + const Vector3 contactNormalShape1Space = worldToShape1Transform.getOrientation() * potentialContactPoints[candidatePointsIndices[0]].normal; // Compute a search direction const Vector3 searchDirection(1, 1, 1); @@ -972,7 +1010,7 @@ void CollisionDetection::reduceContactPoints(ContactManifoldInfo& manifold, cons uint elementIndexToKeep = 0; for (uint i=0; i < candidatePointsIndices.size(); i++) { - const ContactPointInfo& element = mPotentialContactPoints[candidatePointsIndices[i]]; + const ContactPointInfo& element = potentialContactPoints[candidatePointsIndices[i]]; decimal dotProduct = searchDirection.dot(element.localPoint1); if (dotProduct > maxDotProduct) { maxDotProduct = dotProduct; @@ -991,8 +1029,8 @@ void CollisionDetection::reduceContactPoints(ContactManifoldInfo& manifold, cons elementIndexToKeep = 0; for (uint i=0; i < candidatePointsIndices.size(); i++) { - const ContactPointInfo& element = mPotentialContactPoints[candidatePointsIndices[i]]; - const ContactPointInfo& pointToKeep0 = mPotentialContactPoints[pointsToKeepIndices[0]]; + const ContactPointInfo& element = potentialContactPoints[candidatePointsIndices[i]]; + const ContactPointInfo& pointToKeep0 = potentialContactPoints[pointsToKeepIndices[0]]; assert(candidatePointsIndices[i] != pointsToKeepIndices[0]); @@ -1020,9 +1058,9 @@ void CollisionDetection::reduceContactPoints(ContactManifoldInfo& manifold, cons bool isPreviousAreaPositive = true; for (uint i=0; i < candidatePointsIndices.size(); i++) { - const ContactPointInfo& element = mPotentialContactPoints[candidatePointsIndices[i]]; - const ContactPointInfo& pointToKeep0 = mPotentialContactPoints[pointsToKeepIndices[0]]; - const ContactPointInfo& pointToKeep1 = mPotentialContactPoints[pointsToKeepIndices[1]]; + const ContactPointInfo& element = potentialContactPoints[candidatePointsIndices[i]]; + const ContactPointInfo& pointToKeep0 = potentialContactPoints[pointsToKeepIndices[0]]; + const ContactPointInfo& pointToKeep1 = potentialContactPoints[pointsToKeepIndices[1]]; assert(candidatePointsIndices[i] != pointsToKeepIndices[0]); assert(candidatePointsIndices[i] != pointsToKeepIndices[1]); @@ -1067,7 +1105,7 @@ void CollisionDetection::reduceContactPoints(ContactManifoldInfo& manifold, cons // For each remaining candidate points for (uint i=0; i < candidatePointsIndices.size(); i++) { - const ContactPointInfo& element = mPotentialContactPoints[candidatePointsIndices[i]]; + const ContactPointInfo& element = potentialContactPoints[candidatePointsIndices[i]]; assert(candidatePointsIndices[i] != pointsToKeepIndices[0]); assert(candidatePointsIndices[i] != pointsToKeepIndices[1]); @@ -1079,8 +1117,8 @@ void CollisionDetection::reduceContactPoints(ContactManifoldInfo& manifold, cons uint edgeVertex1Index = j; uint edgeVertex2Index = j < 2 ? j + 1 : 0; - const ContactPointInfo& pointToKeepEdgeV1 = mPotentialContactPoints[pointsToKeepIndices[edgeVertex1Index]]; - const ContactPointInfo& pointToKeepEdgeV2 = mPotentialContactPoints[pointsToKeepIndices[edgeVertex2Index]]; + const ContactPointInfo& pointToKeepEdgeV1 = potentialContactPoints[pointsToKeepIndices[edgeVertex1Index]]; + const ContactPointInfo& pointToKeepEdgeV2 = potentialContactPoints[pointsToKeepIndices[edgeVertex2Index]]; const Vector3 newToFirst = pointToKeepEdgeV1.localPoint1 - element.localPoint1; const Vector3 newToSecond = pointToKeepEdgeV2.localPoint1 - element.localPoint1; @@ -1113,6 +1151,7 @@ void CollisionDetection::reduceContactPoints(ContactManifoldInfo& manifold, cons } // Report contacts for all the colliding overlapping pairs +// TODO : What do we do with this method void CollisionDetection::reportAllContacts() { RP3D_PROFILE("CollisionDetection::reportAllContacts()", mProfiler); @@ -1136,452 +1175,177 @@ void CollisionDetection::reportAllContacts() { */ } -// Compute the middle-phase collision detection between two proxy shapes -void CollisionDetection::computeMiddlePhaseForProxyShapes(OverlappingPair* pair, NarrowPhaseInput& outNarrowPhaseInput) { - - ProxyShape* shape1 = pair->getShape1(); - ProxyShape* shape2 = pair->getShape2(); - - // ------------------------------------------------------- - - const bool isShape1Convex = shape1->getCollisionShape()->isConvex(); - const bool isShape2Convex = shape2->getCollisionShape()->isConvex(); - - pair->makeLastFrameCollisionInfosObsolete(); - - // If both shapes are convex - if ((isShape1Convex && isShape2Convex)) { - - // Select the narrow phase algorithm to use according to the two collision shapes - NarrowPhaseAlgorithmType algorithmType = mCollisionDispatch.selectNarrowPhaseAlgorithm(shape1->getCollisionShape()->getType(), - shape2->getCollisionShape()->getType()); - // No middle-phase is necessary, simply create a narrow phase info - // for the narrow-phase collision detection - outNarrowPhaseInput.addNarrowPhaseTest(pair, shape1->getCollisionShape(), shape2->getCollisionShape(), - shape1->getLocalToWorldTransform(), shape2->getLocalToWorldTransform(), - algorithmType, mMemoryManager.getPoolAllocator()); - - } - // Concave vs Convex algorithm - else if ((!isShape1Convex && isShape2Convex) || (!isShape2Convex && isShape1Convex)) { - - // Run the middle-phase collision detection algorithm to find the triangles of the concave - // shape we need to use during the narrow-phase collision detection - computeConvexVsConcaveMiddlePhase(pair, mMemoryManager.getPoolAllocator(), outNarrowPhaseInput); - } - - pair->clearObsoleteLastFrameCollisionInfos(); -} - -// Report all the bodies that overlap with the aabb in parameter -void CollisionDetection::testAABBOverlap(const AABB& aabb, OverlapCallback* overlapCallback, - unsigned short categoryMaskBits) { - assert(overlapCallback != nullptr); - - Set reportedBodies(mMemoryManager.getPoolAllocator()); - - // Ask the broad-phase to get all the overlapping shapes - List overlappingNodes(mMemoryManager.getPoolAllocator()); - mBroadPhaseSystem.reportAllShapesOverlappingWithAABB(aabb, overlappingNodes); - - // For each overlaping proxy shape - for (uint i=0; i < overlappingNodes.size(); i++) { - - // Get the overlapping proxy shape - const int broadPhaseId = overlappingNodes[i]; - ProxyShape* proxyShape = mBroadPhaseSystem.getProxyShapeForBroadPhaseId(broadPhaseId); - - CollisionBody* overlapBody = proxyShape->getBody(); - - // If the proxy shape is from a body that we have not already reported collision - if (reportedBodies.find(overlapBody->getId()) == reportedBodies.end()) { - - // Check if the collision filtering allows collision between the two shapes - if ((proxyShape->getCollisionCategoryBits() & categoryMaskBits) != 0) { - - // Add the body into the set of reported bodies - reportedBodies.add(overlapBody->getId()); - - // Notify the overlap to the user - overlapCallback->notifyOverlap(overlapBody); - } - } - } -} - // Return true if two bodies overlap bool CollisionDetection::testOverlap(CollisionBody* body1, CollisionBody* body2) { NarrowPhaseInput narrowPhaseInput(mMemoryManager.getPoolAllocator()); - // For each proxy shape proxy shape of the first body - const List& body1ProxyShapesEntities = mWorld->mBodyComponents.getProxyShapes(body1->getEntity()); - const List& body2ProxyShapesEntities = mWorld->mBodyComponents.getProxyShapes(body2->getEntity()); - for (uint i=0; i < body1ProxyShapesEntities.size(); i++) { + // Compute the broad-phase collision detection + computeBroadPhase(); - ProxyShape* body1ProxyShape = mWorld->mProxyShapesComponents.getProxyShape(body1ProxyShapesEntities[i]); - - AABB aabb1 = body1ProxyShape->getWorldAABB(); - - // For each proxy shape of the second body - for (uint j=0; j < body2ProxyShapesEntities.size(); j++) { - - ProxyShape* body2ProxyShape = mWorld->mProxyShapesComponents.getProxyShape(body2ProxyShapesEntities[j]); - - AABB aabb2 = body2ProxyShape->getWorldAABB(); - - // Test if the AABBs of the two proxy shapes overlap - if (aabb1.testCollision(aabb2)) { - - // Create a temporary overlapping pair - OverlappingPair pair(body1ProxyShape, body2ProxyShape, mMemoryManager.getPoolAllocator(), - mMemoryManager.getPoolAllocator(), mWorld->mConfig); - - // Compute the middle-phase collision detection between the two shapes - computeMiddlePhaseForProxyShapes(&pair, narrowPhaseInput); - - } - } - } - - // Test narrow-phase collision - bool isCollisionFound = testNarrowPhaseCollision(narrowPhaseInput, true, false, mMemoryManager.getPoolAllocator()); - - // No overlap has been found - return isCollisionFound; -} - -// Report all the bodies that overlap with the body in parameter -void CollisionDetection::testOverlap(CollisionBody* body, OverlapCallback* overlapCallback, - unsigned short categoryMaskBits) { - - assert(overlapCallback != nullptr); - - Set reportedBodies(mMemoryManager.getPoolAllocator()); - NarrowPhaseInput narrowPhaseInput(mMemoryManager.getPoolAllocator()); - - // For each proxy shape proxy shape of the body - const List& proxyShapesEntities = mWorld->mBodyComponents.getProxyShapes(body->getEntity()); - for (uint i=0; i < proxyShapesEntities.size(); i++) { - - ProxyShape* bodyProxyShape = mWorld->mProxyShapesComponents.getProxyShape(proxyShapesEntities[i]); - - if (bodyProxyShape->getBroadPhaseId() != -1) { - - // Get the AABB of the shape - const AABB& shapeAABB = mBroadPhaseSystem.getFatAABB(bodyProxyShape->getBroadPhaseId()); - - // Ask the broad-phase to get all the overlapping shapes - List overlappingNodes(mMemoryManager.getPoolAllocator()); - mBroadPhaseSystem.reportAllShapesOverlappingWithAABB(shapeAABB, overlappingNodes); - - const bodyindex bodyId = body->getId(); - - // For each overlaping proxy shape - for (uint i=0; i < overlappingNodes.size(); i++) { - - // Get the overlapping proxy shape - const int broadPhaseId = overlappingNodes[i]; - ProxyShape* proxyShape = mBroadPhaseSystem.getProxyShapeForBroadPhaseId(broadPhaseId); - - // If the proxy shape is from a body that we have not already reported collision and the - // two proxy collision shapes are not from the same body - if (reportedBodies.find(proxyShape->getBody()->getId()) == reportedBodies.end() && - proxyShape->getBody()->getId() != bodyId) { - - // Check if the collision filtering allows collision between the two shapes - if ((proxyShape->getCollisionCategoryBits() & categoryMaskBits) != 0) { - - // Create a temporary overlapping pair - OverlappingPair pair(bodyProxyShape, proxyShape, mMemoryManager.getPoolAllocator(), - mMemoryManager.getPoolAllocator(), mWorld->mConfig); - - // Compute the middle-phase collision detection between the two shapes - computeMiddlePhaseForProxyShapes(&pair, narrowPhaseInput); - - // Test narrow-phase collision - if (testNarrowPhaseCollision(narrowPhaseInput, true, false, mMemoryManager.getPoolAllocator())) { - - CollisionBody* overlapBody = proxyShape->getBody(); - - // Add the body into the set of reported bodies - reportedBodies.add(overlapBody->getId()); - - // Notify the overlap to the user - overlapCallback->notifyOverlap(overlapBody); - } - - narrowPhaseInput.clear(); - } - } - } - } - } -} - -// Test and report collisions between two bodies -void CollisionDetection::testCollision(CollisionBody* body1, CollisionBody* body2, CollisionCallback* collisionCallback) { - - assert(collisionCallback != nullptr); - - NarrowPhaseInput narrowPhaseInput(mMemoryManager.getPoolAllocator()); + // Filter the overlapping pairs to get only the ones with the selected body involved OverlappingPairMap overlappingPairs(mMemoryManager.getPoolAllocator()); + filterOverlappingPairs(body1->getEntity(), body2->getEntity(), overlappingPairs); - // For each proxy shape proxy shape of the first body - const List& body1ProxyShapesEntities = mWorld->mBodyComponents.getProxyShapes(body1->getEntity()); - const List& body2ProxyShapesEntities = mWorld->mBodyComponents.getProxyShapes(body2->getEntity()); - for (uint i=0; i < body1ProxyShapesEntities.size(); i++) { + if (overlappingPairs.size() > 0) { - ProxyShape* body1ProxyShape = mWorld->mProxyShapesComponents.getProxyShape(body1ProxyShapesEntities[i]); + // Compute the middle-phase collision detection + computeMiddlePhase(overlappingPairs, narrowPhaseInput); - AABB aabb1 = body1ProxyShape->getWorldAABB(); - - // For each proxy shape of the second body - for (uint j=0; j < body2ProxyShapesEntities.size(); j++) { - - ProxyShape* body2ProxyShape = mWorld->mProxyShapesComponents.getProxyShape(body2ProxyShapesEntities[i]); - - AABB aabb2 = body2ProxyShape->getWorldAABB(); - - // Test if the AABBs of the two proxy shapes overlap - if (aabb1.testCollision(aabb2)) { - - OverlappingPair* pair; - const Pair pairID = OverlappingPair::computeID(body1ProxyShape->getBroadPhaseId(), body2ProxyShape->getBroadPhaseId()); - - // Try to retrieve a corresponding copy of the overlapping pair (if it exists) - auto itPair = overlappingPairs.find(pairID); - - // If a copy of the overlapping pair does not exist yet - if (itPair == overlappingPairs.end()) { - - // Create a temporary copy of the overlapping pair - pair = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(OverlappingPair))) - OverlappingPair(body1ProxyShape, body2ProxyShape, mMemoryManager.getPoolAllocator(), - mMemoryManager.getPoolAllocator(), mWorld->mConfig); - - overlappingPairs.add(Pair, OverlappingPair*>(pairID, pair)); - } - else { // If a temporary copy of this overlapping pair already exists - - // Retrieve the existing copy of the overlapping pair - pair = itPair->second; - } - - // Compute the middle-phase collision detection between the two shapes - computeMiddlePhaseForProxyShapes(pair, narrowPhaseInput); - } - } + // Compute the narrow-phase collision detection + return computeNarrowPhaseSnapshot(narrowPhaseInput, true); } - // Test narrow-phase collision - testNarrowPhaseCollision(narrowPhaseInput, false, true, mMemoryManager.getPoolAllocator()); - - // Process the potential contacts - processAllPotentialContacts(narrowPhaseInput, false); - - // Reduce the number of contact points in the manifolds - //reducePotentialContactManifolds(overlappingPairs); - - // TODO : Rework how we report contacts - /* - // For each overlapping pair - for (auto it = overlappingPairs.begin(); it != overlappingPairs.end(); ++it) { - - OverlappingPair* pair = it->second; - - if (pair->hasContacts()) { - - // Report the contacts to the user - CollisionCallback::CollisionCallbackInfo collisionInfo(pair, mMemoryManager); - collisionCallback->notifyContact(collisionInfo); - } - - // Destroy the temporary overlapping pair - pair->~OverlappingPair(); - mMemoryManager.release(MemoryManager::AllocationType::Pool, pair, sizeof(OverlappingPair)); - } - */ + return false; } -// Test and report collisions between a body and all the others bodies of the world -void CollisionDetection::testCollision(CollisionBody* body, CollisionCallback* callback, unsigned short categoryMaskBits) { +// Report all the bodies that overlap in the world +void CollisionDetection::testOverlap(OverlapCallback* callback) { assert(callback != nullptr); NarrowPhaseInput narrowPhaseInput(mMemoryManager.getPoolAllocator()); - OverlappingPairMap overlappingPairs(mMemoryManager.getPoolAllocator()); - - // For each proxy shape proxy shape of the body - const List& proxyShapesEntities = mWorld->mBodyComponents.getProxyShapes(body->getEntity()); - for (uint i=0; i < proxyShapesEntities.size(); i++) { - - ProxyShape* bodyProxyShape = mWorld->mProxyShapesComponents.getProxyShape(proxyShapesEntities[i]); - - if (bodyProxyShape->getBroadPhaseId() != -1) { - - // Get the AABB of the shape - const AABB& shapeAABB = mBroadPhaseSystem.getFatAABB(bodyProxyShape->getBroadPhaseId()); - - // Ask the broad-phase to get all the overlapping shapes - List overlappingNodes(mMemoryManager.getPoolAllocator()); - mBroadPhaseSystem.reportAllShapesOverlappingWithAABB(shapeAABB, overlappingNodes); - - const bodyindex bodyId = body->getId(); - - // For each overlaping proxy shape - for (uint i=0; i < overlappingNodes.size(); i++) { - - // Get the overlapping proxy shape - const int broadPhaseId = overlappingNodes[i]; - ProxyShape* proxyShape = mBroadPhaseSystem.getProxyShapeForBroadPhaseId(broadPhaseId); - - // If the two proxy collision shapes are not from the same body - if (proxyShape->getBody()->getId() != bodyId) { - - // Check if the collision filtering allows collision between the two shapes - if ((proxyShape->getCollisionCategoryBits() & categoryMaskBits) != 0) { - - OverlappingPair* pair; - const Pair pairID = OverlappingPair::computeID(bodyProxyShape->getBroadPhaseId(), proxyShape->getBroadPhaseId()); - - // Try to retrieve a corresponding copy of the overlapping pair (if it exists) - auto itPair = overlappingPairs.find(pairID); - - // If a copy of the overlapping pair does not exist yet - if (itPair == overlappingPairs.end()) { - - // Create a temporary overlapping pair - pair = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(OverlappingPair))) - OverlappingPair(bodyProxyShape, proxyShape, mMemoryManager.getPoolAllocator(), - mMemoryManager.getPoolAllocator(), mWorld->mConfig); - - overlappingPairs.add(Pair, OverlappingPair*>(pairID, pair)); - } - else { // If a temporary copy of this overlapping pair already exists - - // Retrieve the existing copy of the overlapping pair - pair = itPair->second; - } - - // Compute the middle-phase collision detection between the two shapes - computeMiddlePhaseForProxyShapes(pair, narrowPhaseInput); - } - } - } - } - } - - // Test narrow-phase collision - testNarrowPhaseCollision(narrowPhaseInput, false, true, mMemoryManager.getPoolAllocator()); - - // Process the potential contacts - processAllPotentialContacts(narrowPhaseInput, false); - - // Reduce the number of contact points in the manifolds - //reducePotentialContactManifolds(overlappingPairs); - - // TODO : Rework how we report contacts - /* - // For each overlapping pair - for (auto it = overlappingPairs.begin(); it != overlappingPairs.end(); ++it) { - - OverlappingPair* pair = it->second; - - if (pair->hasContacts()) { - - // Report the contacts to the user - CollisionCallback::CollisionCallbackInfo collisionInfo(pair, mMemoryManager); - callback->notifyContact(collisionInfo); - } - - // Destroy the temporary overlapping pair - pair->~OverlappingPair(); - mMemoryManager.release(MemoryManager::AllocationType::Pool, pair, sizeof(OverlappingPair)); - } - */ -} - -// Test and report collisions between all shapes of the world -void CollisionDetection::testCollision(CollisionCallback* callback) { - - assert(callback != nullptr); // Compute the broad-phase collision detection computeBroadPhase(); + // Compute the middle-phase collision detection + computeMiddlePhase(mOverlappingPairs, narrowPhaseInput); + + // Compute the narrow-phase collision detection + computeNarrowPhaseSnapshot(narrowPhaseInput, false); + + // TODO : Report overlaps +} + +// Report all the bodies that overlap with the body in parameter +void CollisionDetection::testOverlap(CollisionBody* body, OverlapCallback* callback) { + + assert(callback != nullptr); + NarrowPhaseInput narrowPhaseInput(mMemoryManager.getPoolAllocator()); + + // Compute the broad-phase collision detection + computeBroadPhase(); + + // Filter the overlapping pairs to get only the ones with the selected body involved OverlappingPairMap overlappingPairs(mMemoryManager.getPoolAllocator()); + filterOverlappingPairs(body->getEntity(), overlappingPairs); + + if (overlappingPairs.size() > 0) { + + // Compute the middle-phase collision detection + computeMiddlePhase(overlappingPairs, narrowPhaseInput); + + // Compute the narrow-phase collision detection + computeNarrowPhaseSnapshot(narrowPhaseInput, false); + + // TODO : Report contacts + } +} + +// Test collision and report contacts between two bodies. +void CollisionDetection::testCollision(CollisionBody* body1, CollisionBody* body2, CollisionCallback* callback) { + + assert(callback != nullptr); + + NarrowPhaseInput narrowPhaseInput(mMemoryManager.getPoolAllocator()); + + // Compute the broad-phase collision detection + computeBroadPhase(); + + // Filter the overlapping pairs to get only the ones with the selected body involved + OverlappingPairMap overlappingPairs(mMemoryManager.getPoolAllocator()); + filterOverlappingPairs(body1->getEntity(), body2->getEntity(), overlappingPairs); + + if (overlappingPairs.size() > 0) { + + // Compute the middle-phase collision detection + computeMiddlePhase(overlappingPairs, narrowPhaseInput); + + // Compute the narrow-phase collision detection + computeNarrowPhaseSnapshot(narrowPhaseInput, true); + + // TODO : Report contacts + } +} + +// Test collision and report all the contacts involving the body in parameter +void CollisionDetection::testCollision(CollisionBody* body, CollisionCallback* callback) { + + assert(callback != nullptr); + + NarrowPhaseInput narrowPhaseInput(mMemoryManager.getPoolAllocator()); + + // Compute the broad-phase collision detection + computeBroadPhase(); + + // Filter the overlapping pairs to get only the ones with the selected body involved + OverlappingPairMap overlappingPairs(mMemoryManager.getPoolAllocator()); + filterOverlappingPairs(body->getEntity(), overlappingPairs); + + if (overlappingPairs.size() > 0) { + + // Compute the middle-phase collision detection + computeMiddlePhase(overlappingPairs, narrowPhaseInput); + + // Compute the narrow-phase collision detection + computeNarrowPhaseSnapshot(narrowPhaseInput, true); + + // TODO : Report contacts + } +} + +// Test collision and report contacts between each colliding bodies in the world +void CollisionDetection::testCollision(CollisionCallback* callback) { + + assert(callback != nullptr); + + NarrowPhaseInput narrowPhaseInput(mMemoryManager.getPoolAllocator()); + + // Compute the broad-phase collision detection + computeBroadPhase(); + + // Compute the middle-phase collision detection + computeMiddlePhase(mOverlappingPairs, narrowPhaseInput); + + // Compute the narrow-phase collision detection + computeNarrowPhaseSnapshot(narrowPhaseInput, true); + + // TODO : Report contacts +} + +// Filter the overlapping pairs to keep only the pairs where a given body is involved +void CollisionDetection::filterOverlappingPairs(Entity bodyEntity, OverlappingPairMap& outFilteredPairs) const { // For each possible collision pair of bodies for (auto it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ++it) { - OverlappingPair* originalPair = it->second; + OverlappingPair* pair = it->second; - OverlappingPair* pair; - const Pair pairID = OverlappingPair::computeID(originalPair->getShape1()->getBroadPhaseId(), originalPair->getShape2()->getBroadPhaseId()); + if (pair->getShape1()->getBody()->getEntity() == bodyEntity || pair->getShape2()->getBody()->getEntity() == bodyEntity) { - // Try to retrieve a corresponding copy of the overlapping pair (if it exists) - auto itPair = overlappingPairs.find(pairID); - - // If a copy of the overlapping pair does not exist yet - if (itPair == overlappingPairs.end()) { - - // Create a temporary overlapping pair - pair = new (mMemoryManager.allocate(MemoryManager::AllocationType::Pool, sizeof(OverlappingPair))) - OverlappingPair(originalPair->getShape1(), originalPair->getShape2(), mMemoryManager.getPoolAllocator(), - mMemoryManager.getPoolAllocator(), mWorld->mConfig); - - overlappingPairs.add(Pair, OverlappingPair*>(pairID, pair)); - } - else { // If a temporary copy of this overlapping pair already exists - - // Retrieve the existing copy of the overlapping pair - pair = itPair->second; - } - - ProxyShape* shape1 = pair->getShape1(); - ProxyShape* shape2 = pair->getShape2(); - - // Check if the collision filtering allows collision between the two shapes and - // that the two shapes are still overlapping. - if (((shape1->getCollideWithMaskBits() & shape2->getCollisionCategoryBits()) != 0 && - (shape1->getCollisionCategoryBits() & shape2->getCollideWithMaskBits()) != 0) && - mBroadPhaseSystem.testOverlappingShapes(shape1, shape2)) { - - // Compute the middle-phase collision detection between the two shapes - computeMiddlePhaseForProxyShapes(pair, narrowPhaseInput); + outFilteredPairs.add(Pair, OverlappingPair*>(it->first, pair)); } } - // Test narrow-phase collision - testNarrowPhaseCollision(narrowPhaseInput, false, true, mMemoryManager.getPoolAllocator()); +} - // Process the potential contacts - processAllPotentialContacts(narrowPhaseInput, false); +// Filter the overlapping pairs to keep only the pairs where two given bodies are involved +void CollisionDetection::filterOverlappingPairs(Entity body1Entity, Entity body2Entity, OverlappingPairMap& outFilteredPairs) const { - // Reduce the number of contact points in the manifolds - //reducePotentialContactManifolds(overlappingPairs); - - // TODO : Rework how we report contacts - /* - // For each overlapping pair - for (auto it = overlappingPairs.begin(); it != overlappingPairs.end(); ++it) { + // For each possible collision pair of bodies + for (auto it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ++it) { OverlappingPair* pair = it->second; - if (pair->hasContacts()) { + if ((pair->getShape1()->getBody()->getEntity() == body1Entity && pair->getShape2()->getBody()->getEntity() == body2Entity) || + (pair->getShape1()->getBody()->getEntity() == body2Entity && pair->getShape2()->getBody()->getEntity() == body1Entity)) { - // Report the contacts to the user - CollisionCallback::CollisionCallbackInfo collisionInfo(pair, mMemoryManager); - callback->notifyContact(collisionInfo); + outFilteredPairs.add(Pair, OverlappingPair*>(it->first, pair)); } - - // Destroy the temporary overlapping pair - pair->~OverlappingPair(); - mMemoryManager.release(MemoryManager::AllocationType::Pool, pair, sizeof(OverlappingPair)); } - */ + } // Return the world event listener diff --git a/src/collision/CollisionDetection.h b/src/collision/CollisionDetection.h index a0d52357..fdba64b4 100644 --- a/src/collision/CollisionDetection.h +++ b/src/collision/CollisionDetection.h @@ -181,40 +181,46 @@ class CollisionDetection { void computeBroadPhase(); /// Compute the middle-phase collision detection - void computeMiddlePhase(); + void computeMiddlePhase(OverlappingPairMap& overlappingPairs, NarrowPhaseInput& narrowPhaseInput); /// Compute the narrow-phase collision detection void computeNarrowPhase(); + /// Compute the narrow-phase collision detection for the testCollision() methods + bool computeNarrowPhaseSnapshot(NarrowPhaseInput& narrowPhaseInput, bool reportContacts); + /// Take a list of overlapping nodes in the broad-phase and create new overlapping pairs if necessary - void updateOverlappingPairs(List >& overlappingNodes); + void updateOverlappingPairs(const List>& overlappingNodes); /// Remove pairs that are not overlapping anymore void removeNonOverlappingPairs(); /// Execute the narrow-phase collision detection algorithm on batches - bool testNarrowPhaseCollision(NarrowPhaseInput& narrowPhaseInput, bool stopFirstContactFound, - bool reportContacts, MemoryAllocator& allocator); + bool testNarrowPhaseCollision(NarrowPhaseInput& narrowPhaseInput, bool reportContacts, MemoryAllocator& allocator); /// Compute the concave vs convex middle-phase algorithm for a given pair of bodies void computeConvexVsConcaveMiddlePhase(OverlappingPair* pair, MemoryAllocator& allocator, NarrowPhaseInput& narrowPhaseInput); - /// Compute the middle-phase collision detection between two proxy shapes - void computeMiddlePhaseForProxyShapes(OverlappingPair* pair, NarrowPhaseInput& outNarrowPhaseInput); - /// Swap the previous and current contacts lists void swapPreviousAndCurrentContacts(); /// Convert the potential contact into actual contacts void processPotentialContacts(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, - bool updateLastFrameInfo); + bool updateLastFrameInfo, List& potentialContactPoints, + Map* mapPairIdToContactPairIndex, + List& potentialContactManifolds, List* contactPairs, + Map>& mapBodyToContactPairs); /// Process the potential contacts after narrow-phase collision detection - void processAllPotentialContacts(NarrowPhaseInput& narrowPhaseInput, bool updateLastFrameInfo); + void processAllPotentialContacts(NarrowPhaseInput& narrowPhaseInput, bool updateLastFrameInfo, List& potentialContactPoints, + Map* mapPairIdToContactPairIndex, + List &potentialContactManifolds, List* contactPairs, + Map>& mapBodyToContactPairs); /// Reduce the potential contact manifolds and contact points of the overlapping pair contacts - void reducePotentialContactManifolds(); + void reducePotentialContactManifolds(List* contactPairs, List& potentialContactManifolds, + const List& potentialContactPoints) const; /// Create the actual contact manifolds and contacts points (from potential contacts) for a given contact pair void createContacts(); @@ -223,17 +229,25 @@ class CollisionDetection { void initContactsWithPreviousOnes(); /// Reduce the number of contact points of a potential contact manifold - void reduceContactPoints(ContactManifoldInfo& manifold, const Transform& shape1ToWorldTransform); + void reduceContactPoints(ContactManifoldInfo& manifold, const Transform& shape1ToWorldTransform, + const List& potentialContactPoints) const; /// Report contacts for all the colliding overlapping pairs void reportAllContacts(); /// Return the largest depth of all the contact points of a potential manifold - decimal computePotentialManifoldLargestContactDepth(const ContactManifoldInfo& manifold) const; + decimal computePotentialManifoldLargestContactDepth(const ContactManifoldInfo& manifold, + const List& potentialContactPoints) const; /// Process the potential contacts where one collion is a concave shape void processSmoothMeshContacts(OverlappingPair* pair); + /// Filter the overlapping pairs to keep only the pairs where a given body is involved + void filterOverlappingPairs(Entity bodyEntity, OverlappingPairMap& outFilteredPairs) const; + + /// Filter the overlapping pairs to keep only the pairs where two given bodies are involved + void filterOverlappingPairs(Entity body1Entity, Entity body2Entity, OverlappingPairMap& outFilteredPairs) const; + public : // -------------------- Methods -------------------- // @@ -283,22 +297,22 @@ class CollisionDetection { void raycast(RaycastCallback* raycastCallback, const Ray& ray, unsigned short raycastWithCategoryMaskBits) const; - /// Report all the bodies that overlap with the aabb in parameter - void testAABBOverlap(const AABB& aabb, OverlapCallback* overlapCallback, unsigned short categoryMaskBits = 0xFFFF); - - /// Return true if two bodies overlap + /// Return true if two bodies (collide) overlap bool testOverlap(CollisionBody* body1, CollisionBody* body2); - /// Report all the bodies that overlap with the body in parameter - void testOverlap(CollisionBody* body, OverlapCallback* overlapCallback, unsigned short categoryMaskBits = 0xFFFF); + /// Report all the bodies that overlap (collide) with the body in parameter + void testOverlap(CollisionBody* body, OverlapCallback* callback); - /// Test and report collisions between two bodies + /// Report all the bodies that overlap (collide) in the world + void testOverlap(OverlapCallback* overlapCallback); + + /// Test collision and report contacts between two bodies. void testCollision(CollisionBody* body1, CollisionBody* body2, CollisionCallback* callback); - /// Test and report collisions between a body and all the others bodies of the world - void testCollision(CollisionBody* body, CollisionCallback* callback, unsigned short categoryMaskBits = 0xFFFF); + /// Test collision and report all the contacts involving the body in parameter + void testCollision(CollisionBody* body, CollisionCallback* callback); - /// Test and report collisions between all shapes of the world + /// Test collision and report contacts between each colliding bodies in the world void testCollision(CollisionCallback* callback); /// Return a reference to the memory manager diff --git a/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.cpp b/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.cpp index ecf69ee1..7b4831fc 100755 --- a/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.cpp +++ b/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.cpp @@ -35,7 +35,7 @@ using namespace reactphysics3d; // This technique is based on the "Robust Contact Creation for Physics Simulations" presentation // by Dirk Gregorius. bool CapsuleVsCapsuleAlgorithm::testCollision(CapsuleVsCapsuleNarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, - bool reportContacts, bool stopFirstContactFound, MemoryAllocator& memoryAllocator) { + bool reportContacts, MemoryAllocator& memoryAllocator) { bool isCollisionFound = false; @@ -154,9 +154,6 @@ bool CapsuleVsCapsuleAlgorithm::testCollision(CapsuleVsCapsuleNarrowPhaseInfoBat narrowPhaseInfoBatch.isColliding[batchIndex] = true; isCollisionFound = true; - if (stopFirstContactFound) { - return isCollisionFound; - } continue; } } @@ -234,9 +231,6 @@ bool CapsuleVsCapsuleAlgorithm::testCollision(CapsuleVsCapsuleNarrowPhaseInfoBat narrowPhaseInfoBatch.isColliding[batchIndex] = true; isCollisionFound = true; - if (stopFirstContactFound) { - return isCollisionFound; - } } } diff --git a/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.h b/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.h index 32f76abe..d8b69bca 100644 --- a/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.h +++ b/src/collision/narrowphase/CapsuleVsCapsuleAlgorithm.h @@ -68,8 +68,7 @@ class CapsuleVsCapsuleAlgorithm : public NarrowPhaseAlgorithm { /// Compute the narrow-phase collision detection between two capsules bool testCollision(CapsuleVsCapsuleNarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, - uint batchNbItems, bool reportContacts, bool stopFirstContactFound, - MemoryAllocator& memoryAllocator); + uint batchNbItems, bool reportContacts, MemoryAllocator& memoryAllocator); }; } diff --git a/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp b/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp index d425b80e..ff02fa38 100644 --- a/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp +++ b/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp @@ -41,8 +41,7 @@ using namespace reactphysics3d; // by Dirk Gregorius. bool CapsuleVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, - bool reportContacts, bool stopFirstContactFound, - MemoryAllocator& memoryAllocator) { + bool reportContacts, MemoryAllocator& memoryAllocator) { bool isCollisionFound = false; @@ -166,9 +165,6 @@ bool CapsuleVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& nar // Colision found narrowPhaseInfoBatch.isColliding[batchIndex] = true; isCollisionFound = true; - if (stopFirstContactFound) { - return isCollisionFound; - } continue; } @@ -183,9 +179,6 @@ bool CapsuleVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& nar if (narrowPhaseInfoBatch.isColliding[batchIndex]) { isCollisionFound = true; - if (stopFirstContactFound) { - return isCollisionFound; - } } } } diff --git a/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.h b/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.h index 70f223b5..42d8ada2 100644 --- a/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.h +++ b/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.h @@ -71,8 +71,7 @@ class CapsuleVsConvexPolyhedronAlgorithm : public NarrowPhaseAlgorithm { /// Compute the narrow-phase collision detection between a capsule and a polyhedron bool testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, - uint batchNbItems, bool reportContacts, bool stopFirstContactFound, - MemoryAllocator& memoryAllocator); + uint batchNbItems, bool reportContacts, MemoryAllocator& memoryAllocator); }; } diff --git a/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp b/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp index 3ed15c74..08d9e9f7 100644 --- a/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp +++ b/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp @@ -37,8 +37,7 @@ using namespace reactphysics3d; // by Dirk Gregorius. bool ConvexPolyhedronVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, - bool reportContacts, bool stopFirstContactFound, - MemoryAllocator& memoryAllocator) { + bool reportContacts, MemoryAllocator& memoryAllocator) { // Run the SAT algorithm to find the separating axis and compute contact point SATAlgorithm satAlgorithm(memoryAllocator); @@ -50,7 +49,7 @@ bool ConvexPolyhedronVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoB #endif bool isCollisionFound = satAlgorithm.testCollisionConvexPolyhedronVsConvexPolyhedron(narrowPhaseInfoBatch, batchStartIndex, - batchNbItems, reportContacts, stopFirstContactFound); + batchNbItems, reportContacts); for (uint batchIndex = batchStartIndex; batchIndex < batchStartIndex + batchNbItems; batchIndex++) { @@ -59,10 +58,6 @@ bool ConvexPolyhedronVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoB lastFrameCollisionInfo->wasUsingSAT = true; lastFrameCollisionInfo->wasUsingGJK = false; - - if (isCollisionFound && stopFirstContactFound) { - return isCollisionFound; - } } return isCollisionFound; diff --git a/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.h b/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.h index 7f9fccd2..b4bd70e6 100644 --- a/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.h +++ b/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.h @@ -65,9 +65,8 @@ class ConvexPolyhedronVsConvexPolyhedronAlgorithm : public NarrowPhaseAlgorithm ConvexPolyhedronVsConvexPolyhedronAlgorithm& operator=(const ConvexPolyhedronVsConvexPolyhedronAlgorithm& algorithm) = delete; /// Compute the narrow-phase collision detection between two convex polyhedra - bool testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, - uint batchNbItems, bool reportContacts, bool stopFirstContactFound, - MemoryAllocator& memoryAllocator); + bool testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, bool reportContacts, + MemoryAllocator& memoryAllocator); }; } diff --git a/src/collision/narrowphase/SAT/SATAlgorithm.cpp b/src/collision/narrowphase/SAT/SATAlgorithm.cpp index 3c467ea3..42d77256 100644 --- a/src/collision/narrowphase/SAT/SATAlgorithm.cpp +++ b/src/collision/narrowphase/SAT/SATAlgorithm.cpp @@ -54,7 +54,7 @@ SATAlgorithm::SATAlgorithm(MemoryAllocator& memoryAllocator) : mMemoryAllocator( // Test collision between a sphere and a convex mesh bool SATAlgorithm::testCollisionSphereVsConvexPolyhedron(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, - bool reportContacts, bool stopFirstContactFound) const { + bool reportContacts) const { bool isCollisionFound = false; @@ -136,9 +136,6 @@ bool SATAlgorithm::testCollisionSphereVsConvexPolyhedron(NarrowPhaseInfoBatch& n narrowPhaseInfoBatch.isColliding[batchIndex] = true; isCollisionFound = true; - if (stopFirstContactFound) { - return isCollisionFound; - } } return isCollisionFound; @@ -476,7 +473,7 @@ bool SATAlgorithm::isMinkowskiFaceCapsuleVsEdge(const Vector3& capsuleSegment, c } // Test collision between two convex polyhedrons -bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, bool reportContacts, bool stopFirstContactFound) const { +bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, bool reportContacts) const { RP3D_PROFILE("SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron()", mProfiler); @@ -548,9 +545,6 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn // Therefore, we can return without running the whole SAT algorithm narrowPhaseInfoBatch.isColliding[batchIndex] = true; isCollisionFound = true; - if (stopFirstContactFound) { - return isCollisionFound; - } continue; } @@ -591,9 +585,6 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn // Therefore, we can return without running the whole SAT algorithm narrowPhaseInfoBatch.isColliding[batchIndex] = true; isCollisionFound = true; - if (stopFirstContactFound) { - return isCollisionFound; - } continue; } @@ -683,9 +674,6 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn // we return without running the whole SAT algorithm narrowPhaseInfoBatch.isColliding[batchIndex] = true; isCollisionFound = true; - if (stopFirstContactFound) { - return isCollisionFound; - } continue; } @@ -878,9 +866,6 @@ bool SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn narrowPhaseInfoBatch.isColliding[batchIndex] = true; isCollisionFound = true; - if (stopFirstContactFound) { - return isCollisionFound; - } } return isCollisionFound; diff --git a/src/collision/narrowphase/SAT/SATAlgorithm.h b/src/collision/narrowphase/SAT/SATAlgorithm.h index 1eb1b923..4ed5e821 100644 --- a/src/collision/narrowphase/SAT/SATAlgorithm.h +++ b/src/collision/narrowphase/SAT/SATAlgorithm.h @@ -140,7 +140,7 @@ class SATAlgorithm { /// Test collision between a sphere and a convex mesh bool testCollisionSphereVsConvexPolyhedron(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, - bool reportContacts, bool stopFirstContactFound) const; + bool reportContacts) const; /// Test collision between a capsule and a convex mesh bool testCollisionCapsuleVsConvexPolyhedron(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchIndex, bool reportContacts) const; @@ -158,7 +158,7 @@ class SATAlgorithm { /// Test collision between two convex meshes bool testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, - uint batchNbItems, bool reportContacts, bool stopFirstContactFound) const; + uint batchNbItems, bool reportContacts) const; #ifdef IS_PROFILING_ACTIVE diff --git a/src/collision/narrowphase/SphereVsCapsuleAlgorithm.cpp b/src/collision/narrowphase/SphereVsCapsuleAlgorithm.cpp index 68a02509..3abb1f09 100755 --- a/src/collision/narrowphase/SphereVsCapsuleAlgorithm.cpp +++ b/src/collision/narrowphase/SphereVsCapsuleAlgorithm.cpp @@ -36,7 +36,7 @@ using namespace reactphysics3d; // This technique is based on the "Robust Contact Creation for Physics Simulations" presentation // by Dirk Gregorius. bool SphereVsCapsuleAlgorithm::testCollision(SphereVsCapsuleNarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, - bool reportContacts, bool stopFirstContactFound, MemoryAllocator& memoryAllocator) { + bool reportContacts, MemoryAllocator& memoryAllocator) { bool isCollisionFound = false; @@ -137,9 +137,6 @@ bool SphereVsCapsuleAlgorithm::testCollision(SphereVsCapsuleNarrowPhaseInfoBatch narrowPhaseInfoBatch.isColliding[batchIndex] = true; isCollisionFound = true; - if (stopFirstContactFound) { - return isCollisionFound; - } continue; } } diff --git a/src/collision/narrowphase/SphereVsCapsuleAlgorithm.h b/src/collision/narrowphase/SphereVsCapsuleAlgorithm.h index 7394bfb2..25926fce 100644 --- a/src/collision/narrowphase/SphereVsCapsuleAlgorithm.h +++ b/src/collision/narrowphase/SphereVsCapsuleAlgorithm.h @@ -68,8 +68,7 @@ class SphereVsCapsuleAlgorithm : public NarrowPhaseAlgorithm { /// Compute the narrow-phase collision detection between a sphere and a capsule bool testCollision(SphereVsCapsuleNarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, - uint batchNbItems, bool reportContacts, bool stopFirstContactFound, - MemoryAllocator& memoryAllocator); + uint batchNbItems, bool reportContacts, MemoryAllocator& memoryAllocator); }; } diff --git a/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp b/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp index a8e638be..48e5390b 100644 --- a/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp +++ b/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp @@ -36,7 +36,7 @@ using namespace reactphysics3d; // This technique is based on the "Robust Contact Creation for Physics Simulations" presentation // by Dirk Gregorius. bool SphereVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, - bool reportContacts, bool stopFirstContactFound, MemoryAllocator& memoryAllocator) { + bool reportContacts, MemoryAllocator& memoryAllocator) { // First, we run the GJK algorithm GJKAlgorithm gjkAlgorithm; @@ -73,9 +73,6 @@ bool SphereVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narr // Return true narrowPhaseInfoBatch.isColliding[batchIndex] = true; isCollisionFound = true; - if (stopFirstContactFound) { - return isCollisionFound; - } continue; } @@ -91,15 +88,11 @@ bool SphereVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narr #endif - isCollisionFound |= satAlgorithm.testCollisionSphereVsConvexPolyhedron(narrowPhaseInfoBatch, batchIndex, 1, reportContacts, stopFirstContactFound); + isCollisionFound |= satAlgorithm.testCollisionSphereVsConvexPolyhedron(narrowPhaseInfoBatch, batchIndex, 1, reportContacts); lastFrameCollisionInfo->wasUsingGJK = false; lastFrameCollisionInfo->wasUsingSAT = true; - if (isCollisionFound && stopFirstContactFound) { - return isCollisionFound; - } - continue; } } diff --git a/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.h b/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.h index 040caec6..e0d6ea0a 100644 --- a/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.h +++ b/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.h @@ -71,9 +71,8 @@ class SphereVsConvexPolyhedronAlgorithm : public NarrowPhaseAlgorithm { SphereVsConvexPolyhedronAlgorithm& operator=(const SphereVsConvexPolyhedronAlgorithm& algorithm) = delete; /// Compute the narrow-phase collision detection between a sphere and a convex polyhedron - bool testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, - uint batchNbItems, bool reportContacts, bool stopFirstContactFound, - MemoryAllocator& memoryAllocator); + bool testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, bool reportContacts, + MemoryAllocator& memoryAllocator); }; } diff --git a/src/collision/narrowphase/SphereVsSphereAlgorithm.cpp b/src/collision/narrowphase/SphereVsSphereAlgorithm.cpp index 52bf5d96..a6d5a61d 100755 --- a/src/collision/narrowphase/SphereVsSphereAlgorithm.cpp +++ b/src/collision/narrowphase/SphereVsSphereAlgorithm.cpp @@ -32,7 +32,7 @@ using namespace reactphysics3d; bool SphereVsSphereAlgorithm::testCollision(SphereVsSphereNarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, uint batchNbItems, - bool reportContacts, bool stopFirstContactFound, MemoryAllocator& memoryAllocator) { + bool reportContacts, MemoryAllocator& memoryAllocator) { bool isCollisionFound = false; @@ -94,9 +94,6 @@ bool SphereVsSphereAlgorithm::testCollision(SphereVsSphereNarrowPhaseInfoBatch& narrowPhaseInfoBatch.isColliding[batchIndex] = true; isCollisionFound = true; - if (stopFirstContactFound) { - return isCollisionFound; - } } } diff --git a/src/collision/narrowphase/SphereVsSphereAlgorithm.h b/src/collision/narrowphase/SphereVsSphereAlgorithm.h index e0f4c5be..5e9554b4 100644 --- a/src/collision/narrowphase/SphereVsSphereAlgorithm.h +++ b/src/collision/narrowphase/SphereVsSphereAlgorithm.h @@ -67,8 +67,7 @@ class SphereVsSphereAlgorithm : public NarrowPhaseAlgorithm { /// Compute a contact info if the two bounding volume collide bool testCollision(SphereVsSphereNarrowPhaseInfoBatch& narrowPhaseInfoBatch, uint batchStartIndex, - uint batchNbItems, bool reportContacts, bool stopFirstContactFound, - MemoryAllocator& memoryAllocator); + uint batchNbItems, bool reportContacts, MemoryAllocator& memoryAllocator); }; } diff --git a/src/containers/Set.h b/src/containers/Set.h index 93cba1ca..c6162c44 100755 --- a/src/containers/Set.h +++ b/src/containers/Set.h @@ -543,7 +543,7 @@ class Set { } /// Return a list with all the values of the set - List toList(MemoryAllocator& listAllocator) { + List toList(MemoryAllocator& listAllocator) const { List list(listAllocator); diff --git a/src/engine/CollisionWorld.cpp b/src/engine/CollisionWorld.cpp index 55ee9861..c63d017a 100644 --- a/src/engine/CollisionWorld.cpp +++ b/src/engine/CollisionWorld.cpp @@ -256,37 +256,10 @@ void CollisionWorld::notifyBodyDisabled(Entity bodyEntity, bool isDisabled) { } } -// Test if the AABBs of two bodies overlap -/** - * @param body1 Pointer to the first body to test - * @param body2 Pointer to the second body to test - * @return True if the AABBs of the two bodies overlap and false otherwise - */ -bool CollisionWorld::testAABBOverlap(const CollisionBody* body1, - const CollisionBody* body2) const { - - // If one of the body is not active, we return no overlap - if (!body1->isActive() || !body2->isActive()) return false; - - // Compute the AABBs of both bodies - AABB body1AABB = body1->getAABB(); - AABB body2AABB = body2->getAABB(); - - // Return true if the two AABBs overlap - return body1AABB.testCollision(body2AABB); -} - -// Report all the bodies which have an AABB that overlaps with the AABB in parameter -/** - * @param aabb AABB used to test for overlap - * @param overlapCallback Pointer to the callback class to report overlap - * @param categoryMaskBits bits mask used to filter the bodies to test overlap with - */ -void CollisionWorld::testAABBOverlap(const AABB& aabb, OverlapCallback* overlapCallback, unsigned short categoryMaskBits) { - mCollisionDetection.testAABBOverlap(aabb, overlapCallback, categoryMaskBits); -} - // Return true if two bodies overlap +/// Use this method if you are not interested in contacts but if you simply want to know +/// if the two bodies overlap. If you want to get the contacts, you need to use the +/// testCollision() method instead. /** * @param body1 Pointer to the first body * @param body2 Pointer to a second body diff --git a/src/engine/CollisionWorld.h b/src/engine/CollisionWorld.h index ac407bff..8f513ef1 100644 --- a/src/engine/CollisionWorld.h +++ b/src/engine/CollisionWorld.h @@ -162,25 +162,22 @@ class CollisionWorld { /// Ray cast method void raycast(const Ray& ray, RaycastCallback* raycastCallback, unsigned short raycastWithCategoryMaskBits = 0xFFFF) const; - /// Test if the AABBs of two bodies overlap - bool testAABBOverlap(const CollisionBody* body1, const CollisionBody* body2) const; - - /// Report all the bodies which have an AABB that overlaps with the AABB in parameter - void testAABBOverlap(const AABB& aabb, OverlapCallback* overlapCallback, unsigned short categoryMaskBits = 0xFFFF); - - /// Return true if two bodies overlap + /// Return true if two bodies overlap (collide) bool testOverlap(CollisionBody* body1, CollisionBody* body2); - /// Report all the bodies that overlap with the body in parameter - void testOverlap(CollisionBody* body, OverlapCallback* overlapCallback, unsigned short categoryMaskBits = 0xFFFF); + /// Report all the bodies that overlap (collide) with the body in parameter + void testOverlap(CollisionBody* body, OverlapCallback* overlapCallback); - /// Test and report collisions between two bodies + /// Report all the bodies that overlap (collide) in the world + void testOverlap(OverlapCallback* overlapCallback); + + /// Test collision and report contacts between two bodies. void testCollision(CollisionBody* body1, CollisionBody* body2, CollisionCallback* callback); - /// Test and report collisions between a body and all the others bodies of the world - void testCollision(CollisionBody* body, CollisionCallback* callback, unsigned short categoryMaskBits = 0xFFFF); + /// Test collision and report all the contacts involving the body in parameter + void testCollision(CollisionBody* body, CollisionCallback* callback); - /// Test and report collisions between all shapes of the world + /// Test collision and report contacts between each colliding bodies in the world void testCollision(CollisionCallback* callback); #ifdef IS_PROFILING_ACTIVE @@ -236,7 +233,11 @@ inline void CollisionWorld::raycast(const Ray& ray, mCollisionDetection.raycast(raycastCallback, ray, raycastWithCategoryMaskBits); } -// Test and report collisions between two bodies +// Test collision and report contacts between two bodies. +/// Use this method if you only want to get all the contacts between two bodies. +/// All the contacts will be reported using the callback object in paramater. +/// If you are not interested in the contacts but you only want to know if the bodies collide, +/// you can use the testOverlap() method instead. /** * @param body1 Pointer to the first body to test * @param body2 Pointer to the second body to test @@ -246,17 +247,24 @@ inline void CollisionWorld::testCollision(CollisionBody* body1, CollisionBody* b mCollisionDetection.testCollision(body1, body2, callback); } -// Test and report collisions between a body and all the others bodies of the world +// Test collision and report all the contacts involving the body in parameter +/// Use this method if you only want to get all the contacts involving a given body. +/// All the contacts will be reported using the callback object in paramater. +/// If you are not interested in the contacts but you only want to know if the bodies collide, +/// you can use the testOverlap() method instead. /** * @param body Pointer to the body against which we need to test collision * @param callback Pointer to the object with the callback method to report contacts - * @param categoryMaskBits Bits mask corresponding to the category of bodies we need to test collision with */ -inline void CollisionWorld::testCollision(CollisionBody* body, CollisionCallback* callback, unsigned short categoryMaskBits) { - mCollisionDetection.testCollision(body, callback, categoryMaskBits); +inline void CollisionWorld::testCollision(CollisionBody* body, CollisionCallback* callback) { + mCollisionDetection.testCollision(body, callback); } -// Test and report collisions between all bodies of the world +// Test collision and report contacts between each colliding bodies in the world +/// Use this method if you want to get all the contacts between colliding bodies in the world. +/// All the contacts will be reported using the callback object in paramater. +/// If you are not interested in the contacts but you only want to know if the bodies collide, +/// you can use the testOverlap() method instead. /** * @param callback Pointer to the object with the callback method to report contacts */ @@ -264,14 +272,24 @@ inline void CollisionWorld::testCollision(CollisionCallback* callback) { mCollisionDetection.testCollision(callback); } -// Report all the bodies that overlap with the body in parameter +// Report all the bodies that overlap (collide) with the body in parameter +/// Use this method if you are not interested in contacts but if you simply want to know +/// which bodies overlap with the body in parameter. If you want to get the contacts, you need to use the +/// testCollision() method instead. /** * @param body Pointer to the collision body to test overlap with * @param overlapCallback Pointer to the callback class to report overlap - * @param categoryMaskBits bits mask used to filter the bodies to test overlap with */ -inline void CollisionWorld::testOverlap(CollisionBody* body, OverlapCallback* overlapCallback, unsigned short categoryMaskBits) { - mCollisionDetection.testOverlap(body, overlapCallback, categoryMaskBits); +inline void CollisionWorld::testOverlap(CollisionBody* body, OverlapCallback* overlapCallback) { + mCollisionDetection.testOverlap(body, overlapCallback); +} + +// Report all the bodies that overlap (collide) in the world +/// Use this method if you are not interested in contacts but if you simply want to know +/// which bodies overlap. If you want to get the contacts, you need to use the +/// testCollision() method instead. +inline void CollisionWorld::testOverlap(OverlapCallback* overlapCallback) { + mCollisionDetection.testOverlap(overlapCallback); } // Return the name of the world diff --git a/src/systems/BroadPhaseSystem.h b/src/systems/BroadPhaseSystem.h index 140486c3..7931da92 100644 --- a/src/systems/BroadPhaseSystem.h +++ b/src/systems/BroadPhaseSystem.h @@ -186,7 +186,7 @@ class BroadPhaseSystem { void reportAllShapesOverlappingWithAABB(const AABB& aabb, List& overlappingNodes) const; /// Compute all the overlapping pairs of collision shapes - void computeOverlappingPairs(MemoryManager& memoryManager, List >& overlappingNodes); + void computeOverlappingPairs(MemoryManager& memoryManager, List>& overlappingNodes); /// Return the proxy shape corresponding to the broad-phase node id in parameter ProxyShape* getProxyShapeForBroadPhaseId(int broadPhaseId) const; diff --git a/test/tests/collision/TestCollisionWorld.h b/test/tests/collision/TestCollisionWorld.h index 63ea12f1..185dcf47 100644 --- a/test/tests/collision/TestCollisionWorld.h +++ b/test/tests/collision/TestCollisionWorld.h @@ -32,6 +32,7 @@ #include "constraint/ContactPoint.h" #include "collision/ContactManifold.h" #include +#include /// Reactphysics3D namespace namespace reactphysics3d { @@ -481,7 +482,6 @@ class TestCollisionWorld : public Test { testNoCollisions(); testNoOverlap(); - testNoAABBOverlap(); testSphereVsSphereCollision(); testSphereVsBoxCollision(); @@ -624,21 +624,6 @@ class TestCollisionWorld : public Test { rp3d_test(!mWorld->testOverlap(mBoxBody2, mSphereBody2)); } - void testNoAABBOverlap() { - - // All the shapes of the world are not touching when they are created. - // Here we test that at the beginning, there is no AABB overlap at all. - - // Two bodies test - - rp3d_test(!mWorld->testAABBOverlap(mBoxBody1, mBoxBody2)); - rp3d_test(!mWorld->testAABBOverlap(mSphereBody1, mSphereBody2)); - rp3d_test(!mWorld->testAABBOverlap(mBoxBody1, mSphereBody1)); - rp3d_test(!mWorld->testAABBOverlap(mBoxBody1, mSphereBody2)); - rp3d_test(!mWorld->testAABBOverlap(mBoxBody2, mSphereBody1)); - rp3d_test(!mWorld->testAABBOverlap(mBoxBody2, mSphereBody2)); - } - void testSphereVsSphereCollision() { Transform initTransform1 = mSphereBody1->getTransform(); @@ -651,10 +636,6 @@ class TestCollisionWorld : public Test { mSphereBody1->setTransform(transform1); mSphereBody2->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mSphereBody2)); - mOverlapCallback.reset(); mWorld->testOverlap(mSphereBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -771,10 +752,6 @@ class TestCollisionWorld : public Test { mSphereBody1->setTransform(transform1); mBoxBody1->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mBoxBody1)); - mOverlapCallback.reset(); mWorld->testOverlap(mSphereBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -881,10 +858,6 @@ class TestCollisionWorld : public Test { mSphereBody1->setTransform(transform1); mBoxBody1->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mBoxBody1)); - mOverlapCallback.reset(); mWorld->testOverlap(mSphereBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -991,10 +964,6 @@ class TestCollisionWorld : public Test { mSphereBody1->setTransform(transform1); mBoxBody1->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mBoxBody1)); - mOverlapCallback.reset(); mWorld->testOverlap(mSphereBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -1111,10 +1080,6 @@ class TestCollisionWorld : public Test { mSphereBody1->setTransform(transform1); mCapsuleBody1->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mCapsuleBody1)); - mOverlapCallback.reset(); mWorld->testOverlap(mSphereBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -1221,10 +1186,6 @@ class TestCollisionWorld : public Test { mSphereBody1->setTransform(transform1); mCapsuleBody1->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mCapsuleBody1)); - mOverlapCallback.reset(); mWorld->testOverlap(mSphereBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -1341,10 +1302,6 @@ class TestCollisionWorld : public Test { mSphereBody1->setTransform(transform1); mConvexMeshBody1->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mConvexMeshBody1)); - mOverlapCallback.reset(); mWorld->testOverlap(mSphereBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -1451,10 +1408,6 @@ class TestCollisionWorld : public Test { mSphereBody1->setTransform(transform1); mConvexMeshBody1->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mConvexMeshBody1)); - mOverlapCallback.reset(); mWorld->testOverlap(mSphereBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -1561,10 +1514,6 @@ class TestCollisionWorld : public Test { mSphereBody1->setTransform(transform1); mConvexMeshBody1->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mConvexMeshBody1)); - mOverlapCallback.reset(); mWorld->testOverlap(mSphereBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -1681,10 +1630,6 @@ class TestCollisionWorld : public Test { mSphereBody1->setTransform(transform1); mConcaveMeshBody->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mSphereBody1, mConcaveMeshBody)); - mOverlapCallback.reset(); mWorld->testOverlap(mSphereBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -1801,10 +1746,6 @@ class TestCollisionWorld : public Test { mBoxBody1->setTransform(transform1); mBoxBody2->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mBoxBody1, mBoxBody2)); - mOverlapCallback.reset(); mWorld->testOverlap(mBoxBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -1965,10 +1906,6 @@ class TestCollisionWorld : public Test { mBoxBody1->setTransform(transform1); mConvexMeshBody2->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mBoxBody1, mConvexMeshBody2)); - mOverlapCallback.reset(); mWorld->testOverlap(mBoxBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -2129,10 +2066,6 @@ class TestCollisionWorld : public Test { mConvexMeshBody1->setTransform(transform1); mConvexMeshBody2->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mConvexMeshBody1, mConvexMeshBody2)); - mOverlapCallback.reset(); mWorld->testOverlap(mConvexMeshBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -2293,10 +2226,6 @@ class TestCollisionWorld : public Test { mBoxBody1->setTransform(transform1); mCapsuleBody1->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mBoxBody1, mCapsuleBody1)); - mOverlapCallback.reset(); mWorld->testOverlap(mBoxBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -2412,10 +2341,6 @@ class TestCollisionWorld : public Test { mConvexMeshBody1->setTransform(transform1); mCapsuleBody1->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mConvexMeshBody1, mCapsuleBody1)); - mOverlapCallback.reset(); mWorld->testOverlap(mConvexMeshBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -2531,10 +2456,6 @@ class TestCollisionWorld : public Test { mBoxBody1->setTransform(transform1); mConcaveMeshBody->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mBoxBody1, mConcaveMeshBody)); - mOverlapCallback.reset(); mWorld->testOverlap(mBoxBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -2633,10 +2554,6 @@ class TestCollisionWorld : public Test { mConvexMeshBody1->setTransform(transform1); mConcaveMeshBody->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mConvexMeshBody1, mConcaveMeshBody)); - mOverlapCallback.reset(); mWorld->testOverlap(mConvexMeshBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -2735,10 +2652,6 @@ class TestCollisionWorld : public Test { mCapsuleBody1->setTransform(transform1); mCapsuleBody2->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mCapsuleBody1, mCapsuleBody2)); - mOverlapCallback.reset(); mWorld->testOverlap(mCapsuleBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -2845,10 +2758,6 @@ class TestCollisionWorld : public Test { mCapsuleBody1->setTransform(transform1); mCapsuleBody2->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mCapsuleBody1, mCapsuleBody2)); - mOverlapCallback.reset(); mWorld->testOverlap(mCapsuleBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap()); @@ -2965,10 +2874,6 @@ class TestCollisionWorld : public Test { mCapsuleBody1->setTransform(transform1); mConcaveMeshBody->setTransform(transform2); - // ----- Test AABB overlap ----- // - - rp3d_test(mWorld->testAABBOverlap(mCapsuleBody1, mConcaveMeshBody)); - mOverlapCallback.reset(); mWorld->testOverlap(mCapsuleBody1, &mOverlapCallback); rp3d_test(mOverlapCallback.hasOverlap());