diff --git a/include/reactphysics3d/body/RigidBody.h b/include/reactphysics3d/body/RigidBody.h index b2481e2b..bbc583b0 100644 --- a/include/reactphysics3d/body/RigidBody.h +++ b/include/reactphysics3d/body/RigidBody.h @@ -57,7 +57,7 @@ class RigidBody : public CollisionBody { void setIsSleeping(bool isSleeping); /// Update whether the current overlapping pairs where this body is involed are active or not - void updateOverlappingPairs(); + void resetOverlappingPairs(); /// Compute and return the local-space center of mass of the body using its colliders Vector3 computeCenterOfMass() const; diff --git a/include/reactphysics3d/components/RigidBodyComponents.h b/include/reactphysics3d/components/RigidBodyComponents.h index 7ceb9a1d..45d986e8 100644 --- a/include/reactphysics3d/components/RigidBodyComponents.h +++ b/include/reactphysics3d/components/RigidBodyComponents.h @@ -358,6 +358,7 @@ class RigidBodyComponents : public Components { friend class PhysicsWorld; friend class ContactSolverSystem; + friend class CollisionDetectionSystem; friend class SolveBallAndSocketJointSystem; friend class SolveFixedJointSystem; friend class SolveHingeJointSystem; diff --git a/include/reactphysics3d/engine/OverlappingPairs.h b/include/reactphysics3d/engine/OverlappingPairs.h index 9d65b3e0..206d43bc 100644 --- a/include/reactphysics3d/engine/OverlappingPairs.h +++ b/include/reactphysics3d/engine/OverlappingPairs.h @@ -166,9 +166,6 @@ class OverlappingPairs { /// True if we need to test if the convex vs convex overlapping pairs of shapes still overlap bool* mNeedToTestOverlap; - /// True if the overlapping pair is active (at least one body of the pair is active and not static) - bool* mIsActive; - /// Array with the pointer to the narrow-phase algorithm for each overlapping pair NarrowPhaseAlgorithmType* mNarrowPhaseAlgorithmType; @@ -263,9 +260,6 @@ class OverlappingPairs { /// Return the entity of the second collider Entity getCollider2(uint64 pairId) const; - /// Notify if a given pair is active or not - void setIsPairActive(uint64 pairId, bool isActive); - /// Return the index of a given overlapping pair in the internal array uint64 getPairIndex(uint64 pairId) const; @@ -278,9 +272,6 @@ class OverlappingPairs { /// Add a new last frame collision info if it does not exist for the given shapes already LastFrameCollisionInfo* addLastFrameInfoIfNecessary(uint64 pairIndex, uint32 shapeId1, uint32 shapeId2); - /// Update whether a given overlapping pair is active or not - void updateOverlappingPairIsActive(uint64 pairId); - /// Delete all the obsolete last frame collision info void clearObsoleteLastFrameCollisionInfos(); @@ -326,14 +317,6 @@ RP3D_FORCE_INLINE Entity OverlappingPairs::getCollider2(uint64 pairId) const { return mColliders2[mMapPairIdToPairIndex[pairId]]; } -// Notify if a given pair is active or not -RP3D_FORCE_INLINE void OverlappingPairs::setIsPairActive(uint64 pairId, bool isActive) { - - assert(mMapPairIdToPairIndex.containsKey(pairId)); - assert(mMapPairIdToPairIndex[pairId] < mNbPairs); - mIsActive[mMapPairIdToPairIndex[pairId]] = isActive; -} - // Return the index of a given overlapping pair in the internal array RP3D_FORCE_INLINE uint64 OverlappingPairs::getPairIndex(uint64 pairId) const { assert(mMapPairIdToPairIndex.containsKey(pairId)); diff --git a/include/reactphysics3d/mathematics/mathematics_functions.h b/include/reactphysics3d/mathematics/mathematics_functions.h index 74b7a86a..cd98140e 100755 --- a/include/reactphysics3d/mathematics/mathematics_functions.h +++ b/include/reactphysics3d/mathematics/mathematics_functions.h @@ -133,7 +133,11 @@ bool isPrimeNumber(int number); /// Here we assume that the two parameter numbers are sorted such that /// number1 = max(number1, number2) /// http://szudzik.com/ElegantPairing.pdf -uint64 pairNumbers(uint32 number1, uint32 number2); +RP3D_FORCE_INLINE uint64 pairNumbers(uint32 number1, uint32 number2) { + assert(number1 == std::max(number1, number2)); + return number1 * number1 + number1 + number2; +} + } diff --git a/src/body/RigidBody.cpp b/src/body/RigidBody.cpp index 8b08cac2..222a97d9 100644 --- a/src/body/RigidBody.cpp +++ b/src/body/RigidBody.cpp @@ -108,11 +108,7 @@ void RigidBody::setType(BodyType type) { setIsSleeping(false); // Update the active status of currently overlapping pairs - updateOverlappingPairs(); - - // Ask the broad-phase to test again the collision shapes of the body for collision - // detection (as if the body has moved) - askForBroadPhaseCollisionCheck(); + resetOverlappingPairs(); // Reset the force and torque on the body mWorld.mRigidBodyComponents.setExternalForce(mEntity, Vector3::zero()); @@ -856,7 +852,7 @@ void RigidBody::setIsSleeping(bool isSleeping) { mWorld.setBodyDisabled(mEntity, isSleeping); // Update the currently overlapping pairs - updateOverlappingPairs(); + resetOverlappingPairs(); if (isSleeping) { @@ -871,8 +867,8 @@ void RigidBody::setIsSleeping(bool isSleeping) { (isSleeping ? "true" : "false"), __FILE__, __LINE__); } -// Update whether the current overlapping pairs where this body is involed are active or not -void RigidBody::updateOverlappingPairs() { +// Remove all the overlapping pairs in which this body is involved and ask the broad-phase to recompute pairs in the next frame +void RigidBody::resetOverlappingPairs() { // For each collider of the body const List& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity); @@ -883,9 +879,12 @@ void RigidBody::updateOverlappingPairs() { for (uint j=0; j < overlappingPairs.size(); j++) { - mWorld.mCollisionDetection.mOverlappingPairs.updateOverlappingPairIsActive(overlappingPairs[j]); + mWorld.mCollisionDetection.mOverlappingPairs.removePair(overlappingPairs[j]); } } + + // Make sure we recompute the overlapping pairs with this body in the next frame + askForBroadPhaseCollisionCheck(); } /// Compute the inverse of the inertia tensor in world coordinates. diff --git a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp index f3d664a7..74a0dbaa 100644 --- a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp +++ b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp @@ -64,8 +64,8 @@ void GJKAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uin decimal prevDistSquare; bool contactFound = false; - assert(narrowPhaseInfoBatch.narrowPhaseInfo[[batchIndex].collisionShape1->isConvex()); - assert(narrowPhaseInfoBatch.narrowPhaseInfo[[batchIndex].collisionShape2->isConvex()); + assert(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape1->isConvex()); + assert(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape2->isConvex()); const ConvexShape* shape1 = static_cast(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape1); const ConvexShape* shape2 = static_cast(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape2); diff --git a/src/collision/narrowphase/NarrowPhaseInfoBatch.cpp b/src/collision/narrowphase/NarrowPhaseInfoBatch.cpp index 3aef65e3..d0266741 100644 --- a/src/collision/narrowphase/NarrowPhaseInfoBatch.cpp +++ b/src/collision/narrowphase/NarrowPhaseInfoBatch.cpp @@ -55,7 +55,7 @@ void NarrowPhaseInfoBatch::clear() { // TODO OPTI : Better manage this for (uint i=0; i < narrowPhaseInfos.size(); i++) { - assert(narrowPhaseOutputInfos[i].nbContactPoints == 0); + assert(narrowPhaseInfos[i].nbContactPoints == 0); // Release the memory of the TriangleShape (this memory was allocated in the // MiddlePhaseTriangleCallback::testTriangle() method) diff --git a/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp b/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp index 6e732d12..7126b35f 100644 --- a/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp +++ b/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp @@ -57,10 +57,10 @@ bool SphereVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narr // For each item in the batch for (uint batchIndex = batchStartIndex; batchIndex < batchStartIndex + batchNbItems; batchIndex++) { - assert(narrowPhaseInfoBatch.narrowPhaseInfo[[batchIndex].collisionShape1->getType() == CollisionShapeType::CONVEX_POLYHEDRON || - narrowPhaseInfoBatch.narrowPhaseInfo[[batchIndex].collisionShape2->getType() == CollisionShapeType::CONVEX_POLYHEDRON); - assert(narrowPhaseInfoBatch.narrowPhaseInfo[[batchIndex].collisionShape1->getType() == CollisionShapeType::SPHERE || - narrowPhaseInfoBatch.narrowPhaseInfo[[batchIndex].collisionShape2->getType() == CollisionShapeType::SPHERE); + assert(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape1->getType() == CollisionShapeType::CONVEX_POLYHEDRON || + narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape2->getType() == CollisionShapeType::CONVEX_POLYHEDRON); + assert(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape1->getType() == CollisionShapeType::SPHERE || + narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape2->getType() == CollisionShapeType::SPHERE); // Get the last frame collision info LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].lastFrameCollisionInfo; diff --git a/src/engine/OverlappingPairs.cpp b/src/engine/OverlappingPairs.cpp index 2121143e..543a32ef 100644 --- a/src/engine/OverlappingPairs.cpp +++ b/src/engine/OverlappingPairs.cpp @@ -39,7 +39,7 @@ OverlappingPairs::OverlappingPairs(MemoryAllocator& persistentMemoryAllocator, M : mPersistentAllocator(persistentMemoryAllocator), mTempMemoryAllocator(temporaryMemoryAllocator), mNbPairs(0), mConcavePairsStartIndex(0), mPairDataSize(sizeof(uint64) + sizeof(int32) + sizeof(int32) + sizeof(Entity) + sizeof(Entity) + sizeof(Map) + - sizeof(bool) + sizeof(bool) + sizeof(NarrowPhaseAlgorithmType) + + sizeof(bool) + sizeof(NarrowPhaseAlgorithmType) + sizeof(bool) + sizeof(bool) + sizeof(bool)), mNbAllocatedPairs(0), mBuffer(nullptr), mMapPairIdToPairIndex(persistentMemoryAllocator), @@ -208,8 +208,7 @@ void OverlappingPairs::allocate(uint64 nbPairsToAllocate) { Entity* newColliders2 = reinterpret_cast(newColliders1 + nbPairsToAllocate); Map* newLastFrameCollisionInfos = reinterpret_cast*>(newColliders2 + nbPairsToAllocate); bool* newNeedToTestOverlap = reinterpret_cast(newLastFrameCollisionInfos + nbPairsToAllocate); - bool* newIsActive = reinterpret_cast(newNeedToTestOverlap + nbPairsToAllocate); - NarrowPhaseAlgorithmType* newNarrowPhaseAlgorithmType = reinterpret_cast(newIsActive + nbPairsToAllocate); + NarrowPhaseAlgorithmType* newNarrowPhaseAlgorithmType = reinterpret_cast(newNeedToTestOverlap + nbPairsToAllocate); bool* newIsShape1Convex = reinterpret_cast(newNarrowPhaseAlgorithmType + nbPairsToAllocate); bool* wereCollidingInPreviousFrame = reinterpret_cast(newIsShape1Convex + nbPairsToAllocate); bool* areCollidingInCurrentFrame = reinterpret_cast(wereCollidingInPreviousFrame + nbPairsToAllocate); @@ -225,7 +224,6 @@ void OverlappingPairs::allocate(uint64 nbPairsToAllocate) { memcpy(newColliders2, mColliders2, mNbPairs * sizeof(Entity)); memcpy(newLastFrameCollisionInfos, mLastFrameCollisionInfos, mNbPairs * sizeof(Map)); memcpy(newNeedToTestOverlap, mNeedToTestOverlap, mNbPairs * sizeof(bool)); - memcpy(newIsActive, mIsActive, mNbPairs * sizeof(bool)); memcpy(newNarrowPhaseAlgorithmType, mNarrowPhaseAlgorithmType, mNbPairs * sizeof(NarrowPhaseAlgorithmType)); memcpy(newIsShape1Convex, mIsShape1Convex, mNbPairs * sizeof(bool)); memcpy(wereCollidingInPreviousFrame, mCollidingInPreviousFrame, mNbPairs * sizeof(bool)); @@ -243,7 +241,6 @@ void OverlappingPairs::allocate(uint64 nbPairsToAllocate) { mColliders2 = newColliders2; mLastFrameCollisionInfos = newLastFrameCollisionInfos; mNeedToTestOverlap = newNeedToTestOverlap; - mIsActive = newIsActive; mNarrowPhaseAlgorithmType = newNarrowPhaseAlgorithmType; mIsShape1Convex = newIsShape1Convex; mCollidingInPreviousFrame = wereCollidingInPreviousFrame; @@ -301,7 +298,6 @@ uint64 OverlappingPairs::addPair(Collider* shape1, Collider* shape2) { new (mColliders2 + index) Entity(shape2->getEntity()); new (mLastFrameCollisionInfos + index) Map(mPersistentAllocator); new (mNeedToTestOverlap + index) bool(false); - new (mIsActive + index) bool(true); new (mNarrowPhaseAlgorithmType + index) NarrowPhaseAlgorithmType(algorithmType); new (mIsShape1Convex + index) bool(isShape1Convex); new (mCollidingInPreviousFrame + index) bool(false); @@ -321,8 +317,6 @@ uint64 OverlappingPairs::addPair(Collider* shape1, Collider* shape2) { assert(mConcavePairsStartIndex <= mNbPairs); assert(mNbPairs == static_cast(mMapPairIdToPairIndex.size())); - updateOverlappingPairIsActive(pairId); - return pairId; } @@ -340,7 +334,6 @@ void OverlappingPairs::movePairToIndex(uint64 srcIndex, uint64 destIndex) { new (mColliders2 + destIndex) Entity(mColliders2[srcIndex]); new (mLastFrameCollisionInfos + destIndex) Map(mLastFrameCollisionInfos[srcIndex]); mNeedToTestOverlap[destIndex] = mNeedToTestOverlap[srcIndex]; - mIsActive[destIndex] = mIsActive[srcIndex]; new (mNarrowPhaseAlgorithmType + destIndex) NarrowPhaseAlgorithmType(mNarrowPhaseAlgorithmType[srcIndex]); mIsShape1Convex[destIndex] = mIsShape1Convex[srcIndex]; mCollidingInPreviousFrame[destIndex] = mCollidingInPreviousFrame[srcIndex]; @@ -368,7 +361,6 @@ void OverlappingPairs::swapPairs(uint64 index1, uint64 index2) { Entity collider2 = mColliders2[index1]; Map lastFrameCollisionInfo(mLastFrameCollisionInfos[index1]); bool needTestOverlap = mNeedToTestOverlap[index1]; - bool isActive = mIsActive[index1]; NarrowPhaseAlgorithmType narrowPhaseAlgorithmType = mNarrowPhaseAlgorithmType[index1]; bool isShape1Convex = mIsShape1Convex[index1]; bool wereCollidingInPreviousFrame = mCollidingInPreviousFrame[index1]; @@ -387,7 +379,6 @@ void OverlappingPairs::swapPairs(uint64 index1, uint64 index2) { new (mColliders2 + index2) Entity(collider2); new (mLastFrameCollisionInfos + index2) Map(lastFrameCollisionInfo); mNeedToTestOverlap[index2] = needTestOverlap; - mIsActive[index2] = isActive; new (mNarrowPhaseAlgorithmType + index2) NarrowPhaseAlgorithmType(narrowPhaseAlgorithmType); mIsShape1Convex[index2] = isShape1Convex; mCollidingInPreviousFrame[index2] = wereCollidingInPreviousFrame; @@ -416,36 +407,6 @@ void OverlappingPairs::destroyPair(uint64 index) { mNarrowPhaseAlgorithmType[index].~NarrowPhaseAlgorithmType(); } -// Update whether a given overlapping pair is active or not -void OverlappingPairs::updateOverlappingPairIsActive(uint64 pairId) { - - assert(mMapPairIdToPairIndex.containsKey(pairId)); - - const uint64 pairIndex = mMapPairIdToPairIndex[pairId]; - - const Entity collider1 = mColliders1[pairIndex]; - const Entity collider2 = mColliders2[pairIndex]; - - const Entity body1 = mColliderComponents.getBody(collider1); - const Entity body2 = mColliderComponents.getBody(collider2); - - const bool isBody1Enabled = !mCollisionBodyComponents.getIsEntityDisabled(body1); - const bool isBody2Enabled = !mCollisionBodyComponents.getIsEntityDisabled(body2); - const bool isBody1Static = mRigidBodyComponents.hasComponent(body1) && - mRigidBodyComponents.getBodyType(body1) == BodyType::STATIC; - const bool isBody2Static = mRigidBodyComponents.hasComponent(body2) && - mRigidBodyComponents.getBodyType(body2) == BodyType::STATIC; - - const bool isBody1Active = isBody1Enabled && !isBody1Static; - const bool isBody2Active = isBody2Enabled && !isBody2Static; - - // Check if the bodies are in the set of bodies that cannot collide between each other - bodypair bodiesIndex = OverlappingPairs::computeBodiesIndexPair(body1, body2); - bool bodiesCanCollide = !mNoCollisionPairs.contains(bodiesIndex); - - mIsActive[pairIndex] = bodiesCanCollide && (isBody1Active || isBody2Active); -} - // Add a new last frame collision info if it does not exist for the given shapes already LastFrameCollisionInfo* OverlappingPairs::addLastFrameInfoIfNecessary(uint64 pairIndex, uint32 shapeId1, uint32 shapeId2) { diff --git a/src/mathematics/mathematics_functions.cpp b/src/mathematics/mathematics_functions.cpp index 66c3efda..5438c980 100755 --- a/src/mathematics/mathematics_functions.cpp +++ b/src/mathematics/mathematics_functions.cpp @@ -403,13 +403,3 @@ bool reactphysics3d::isPrimeNumber(int number) { return number == 2; } - -// Return an unique integer from two integer numbers (pairing function) -/// Here we assume that the two parameter numbers are sorted such that -/// number1 = max(number1, number2) -/// http://szudzik.com/ElegantPairing.pdf -uint64 reactphysics3d::pairNumbers(uint32 number1, uint32 number2) { - assert(number1 == std::max(number1, number2)); - return number1 * number1 + number1 + number2; -} - diff --git a/src/systems/CollisionDetectionSystem.cpp b/src/systems/CollisionDetectionSystem.cpp index b7de88b0..4315cdb5 100644 --- a/src/systems/CollisionDetectionSystem.cpp +++ b/src/systems/CollisionDetectionSystem.cpp @@ -192,39 +192,64 @@ void CollisionDetectionSystem::updateOverlappingPairs(const ListgetCollisionShape()->isConvex() || shape2->getCollisionShape()->isConvex()) { + const unsigned short shape1CollideWithMaskBits = mCollidersComponents.mCollideWithMaskBits[collider1Index]; + const unsigned short shape2CollideWithMaskBits = mCollidersComponents.mCollideWithMaskBits[collider2Index]; - // Add the new overlapping pair - mOverlappingPairs.addPair(shape1, shape2); + const unsigned short shape1CollisionCategoryBits = mCollidersComponents.mCollisionCategoryBits[collider1Index]; + const unsigned short shape2CollisionCategoryBits = mCollidersComponents.mCollisionCategoryBits[collider2Index]; + + // Check if the collision filtering allows collision between the two shapes + if ((shape1CollideWithMaskBits & shape2CollisionCategoryBits) != 0 && + (shape1CollisionCategoryBits & shape2CollideWithMaskBits) != 0) { + + Collider* shape1 = mCollidersComponents.mColliders[collider1Index]; + Collider* shape2 = mCollidersComponents.mColliders[collider2Index]; + + // Check that at least one collision shape is convex + if (shape1->getCollisionShape()->isConvex() || shape2->getCollisionShape()->isConvex()) { + + // Add the new overlapping pair + mOverlappingPairs.addPair(shape1, shape2); + } + } + } + else { + + // We do not need to test the pair for overlap because it has just been reported that they still overlap + mOverlappingPairs.mNeedToTestOverlap[it->second] = false; } } } - else { - - // We do not need to test the pair for overlap because it has just been reported that they still overlap - mOverlappingPairs.mNeedToTestOverlap[it->second] = false; - } } } } @@ -249,33 +274,30 @@ void CollisionDetectionSystem::computeMiddlePhase(NarrowPhaseInput& narrowPhaseI assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i]) != -1); assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders1[i]) != mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i])); - // Check that at least one body is enabled (active and awake) and not static - if (mOverlappingPairs.mIsActive[i]) { - const Entity collider1Entity = mOverlappingPairs.mColliders1[i]; - const Entity collider2Entity = mOverlappingPairs.mColliders2[i]; + const Entity collider1Entity = mOverlappingPairs.mColliders1[i]; + const Entity collider2Entity = mOverlappingPairs.mColliders2[i]; - const uint collider1Index = mCollidersComponents.getEntityIndex(collider1Entity); - const uint collider2Index = mCollidersComponents.getEntityIndex(collider2Entity); + const uint collider1Index = mCollidersComponents.getEntityIndex(collider1Entity); + const uint collider2Index = mCollidersComponents.getEntityIndex(collider2Entity); - CollisionShape* collisionShape1 = mCollidersComponents.mCollisionShapes[collider1Index]; - CollisionShape* collisionShape2 = mCollidersComponents.mCollisionShapes[collider2Index]; + CollisionShape* collisionShape1 = mCollidersComponents.mCollisionShapes[collider1Index]; + CollisionShape* collisionShape2 = mCollidersComponents.mCollisionShapes[collider2Index]; - NarrowPhaseAlgorithmType algorithmType = mOverlappingPairs.mNarrowPhaseAlgorithmType[i]; + NarrowPhaseAlgorithmType algorithmType = mOverlappingPairs.mNarrowPhaseAlgorithmType[i]; - const bool isCollider1Trigger = mCollidersComponents.mIsTrigger[collider1Index]; - const bool isCollider2Trigger = mCollidersComponents.mIsTrigger[collider2Index]; - const bool reportContacts = needToReportContacts && !isCollider1Trigger && !isCollider2Trigger; + const bool isCollider1Trigger = mCollidersComponents.mIsTrigger[collider1Index]; + const bool isCollider2Trigger = mCollidersComponents.mIsTrigger[collider2Index]; + const bool reportContacts = needToReportContacts && !isCollider1Trigger && !isCollider2Trigger; - // No middle-phase is necessary, simply create a narrow phase info - // for the narrow-phase collision detection - narrowPhaseInput.addNarrowPhaseTest(mOverlappingPairs.mPairIds[i], i, collider1Entity, collider2Entity, collisionShape1, collisionShape2, - mCollidersComponents.mLocalToWorldTransforms[collider1Index], - mCollidersComponents.mLocalToWorldTransforms[collider2Index], - algorithmType, reportContacts, mMemoryManager.getSingleFrameAllocator()); + // No middle-phase is necessary, simply create a narrow phase info + // for the narrow-phase collision detection + narrowPhaseInput.addNarrowPhaseTest(mOverlappingPairs.mPairIds[i], i, collider1Entity, collider2Entity, collisionShape1, collisionShape2, + mCollidersComponents.mLocalToWorldTransforms[collider1Index], + mCollidersComponents.mLocalToWorldTransforms[collider2Index], + algorithmType, reportContacts, mMemoryManager.getSingleFrameAllocator()); - mOverlappingPairs.mCollidingInCurrentFrame[i] = false; - } + mOverlappingPairs.mCollidingInCurrentFrame[i] = false; } // For each possible convex vs concave pair of bodies @@ -287,13 +309,9 @@ void CollisionDetectionSystem::computeMiddlePhase(NarrowPhaseInput& narrowPhaseI assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i]) != -1); assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders1[i]) != mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i])); - // Check that at least one body is enabled (active and awake) and not static - if (mOverlappingPairs.mIsActive[i]) { + computeConvexVsConcaveMiddlePhase(i, mMemoryManager.getSingleFrameAllocator(), narrowPhaseInput); - computeConvexVsConcaveMiddlePhase(i, mMemoryManager.getSingleFrameAllocator(), narrowPhaseInput); - - mOverlappingPairs.mCollidingInCurrentFrame[i] = false; - } + mOverlappingPairs.mCollidingInCurrentFrame[i] = false; } } diff --git a/src/systems/ContactSolverSystem.cpp b/src/systems/ContactSolverSystem.cpp index a3d4936d..1944c143 100644 --- a/src/systems/ContactSolverSystem.cpp +++ b/src/systems/ContactSolverSystem.cpp @@ -131,8 +131,6 @@ void ContactSolverSystem::initializeForIsland(uint islandIndex) { const uint rigidBodyIndex2 = mRigidBodyComponents.getEntityIndex(externalManifold.bodyEntity2); // Get the two bodies of the contact - assert(body1 != nullptr); - assert(body2 != nullptr); assert(!mBodyComponents.getIsEntityDisabled(externalManifold.bodyEntity1)); assert(!mBodyComponents.getIsEntityDisabled(externalManifold.bodyEntity2));