From 2efe9d65da5541d7fc698c7c27a5db20a519664f Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Mon, 27 Apr 2020 15:54:57 +0200 Subject: [PATCH] Fix issue with overlap callback --- include/reactphysics3d/collision/OverlapCallback.h | 2 +- src/collision/OverlapCallback.cpp | 6 +++--- src/systems/CollisionDetectionSystem.cpp | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/reactphysics3d/collision/OverlapCallback.h b/include/reactphysics3d/collision/OverlapCallback.h index 6f3ba12e..79923e47 100644 --- a/include/reactphysics3d/collision/OverlapCallback.h +++ b/include/reactphysics3d/collision/OverlapCallback.h @@ -149,7 +149,7 @@ class OverlapCallback { // -------------------- Methods -------------------- // /// Constructor - CallbackData(List& contactPairs, List& lostContactPairs, PhysicsWorld& world); + CallbackData(List& contactPairs, List& lostContactPairs, bool onlyReportTriggers, PhysicsWorld& world); /// Deleted copy constructor CallbackData(const CallbackData& callbackData) = delete; diff --git a/src/collision/OverlapCallback.cpp b/src/collision/OverlapCallback.cpp index af5f17ff..39678e67 100644 --- a/src/collision/OverlapCallback.cpp +++ b/src/collision/OverlapCallback.cpp @@ -67,7 +67,7 @@ OverlapCallback::OverlapPair::EventType OverlapCallback::OverlapPair::getEventTy } // CollisionCallbackData Constructor -OverlapCallback::CallbackData::CallbackData(List& contactPairs, List& lostContactPairs, PhysicsWorld& world) +OverlapCallback::CallbackData::CallbackData(List& contactPairs, List& lostContactPairs, bool onlyReportTriggers, PhysicsWorld& world) :mContactPairs(contactPairs), mLostContactPairs(lostContactPairs), mContactPairsIndices(world.mMemoryManager.getHeapAllocator()), mLostContactPairsIndices(world.mMemoryManager.getHeapAllocator()), mWorld(world) { @@ -75,7 +75,7 @@ OverlapCallback::CallbackData::CallbackData(List& contactPairs, Lis for (uint i=0; i < mContactPairs.size(); i++) { // If the contact pair contains contacts (and is therefore not an overlap/trigger event) - if (mContactPairs[i].isTrigger) { + if (!onlyReportTriggers || mContactPairs[i].isTrigger) { mContactPairsIndices.add(i); } } @@ -83,7 +83,7 @@ OverlapCallback::CallbackData::CallbackData(List& contactPairs, Lis for (uint i=0; i < mLostContactPairs.size(); i++) { // If the contact pair contains contacts (and is therefore not an overlap/trigger event) - if (mLostContactPairs[i].isTrigger) { + if (!onlyReportTriggers || mLostContactPairs[i].isTrigger) { mLostContactPairsIndices.add(i); } } diff --git a/src/systems/CollisionDetectionSystem.cpp b/src/systems/CollisionDetectionSystem.cpp index 2d104d37..2413f915 100644 --- a/src/systems/CollisionDetectionSystem.cpp +++ b/src/systems/CollisionDetectionSystem.cpp @@ -553,7 +553,7 @@ bool CollisionDetectionSystem::computeNarrowPhaseOverlapSnapshot(NarrowPhaseInpu computeOverlapSnapshotContactPairs(narrowPhaseInput, contactPairs); // Report overlapping colliders - OverlapCallback::CallbackData callbackData(contactPairs, lostContactPairs, *mWorld); + OverlapCallback::CallbackData callbackData(contactPairs, lostContactPairs, false, *mWorld); (*callback).onOverlap(callbackData); } @@ -1421,7 +1421,7 @@ void CollisionDetectionSystem::reportTriggers(EventListener& eventListener, List // If there are contacts if (contactPairs->size() + lostContactPairs.size() > 0) { - OverlapCallback::CallbackData callbackData(*contactPairs, lostContactPairs, *mWorld); + OverlapCallback::CallbackData callbackData(*contactPairs, lostContactPairs, true, *mWorld); // Call the callback method to report the overlapping shapes eventListener.onTrigger(callbackData);