Fix issue with overlap callback

This commit is contained in:
Daniel Chappuis 2020-04-27 15:54:57 +02:00
parent e03ee08462
commit 2efe9d65da
3 changed files with 6 additions and 6 deletions

View File

@ -149,7 +149,7 @@ class OverlapCallback {
// -------------------- Methods -------------------- // // -------------------- Methods -------------------- //
/// Constructor /// Constructor
CallbackData(List<ContactPair>& contactPairs, List<ContactPair>& lostContactPairs, PhysicsWorld& world); CallbackData(List<ContactPair>& contactPairs, List<ContactPair>& lostContactPairs, bool onlyReportTriggers, PhysicsWorld& world);
/// Deleted copy constructor /// Deleted copy constructor
CallbackData(const CallbackData& callbackData) = delete; CallbackData(const CallbackData& callbackData) = delete;

View File

@ -67,7 +67,7 @@ OverlapCallback::OverlapPair::EventType OverlapCallback::OverlapPair::getEventTy
} }
// CollisionCallbackData Constructor // CollisionCallbackData Constructor
OverlapCallback::CallbackData::CallbackData(List<ContactPair>& contactPairs, List<ContactPair>& lostContactPairs, PhysicsWorld& world) OverlapCallback::CallbackData::CallbackData(List<ContactPair>& contactPairs, List<ContactPair>& lostContactPairs, bool onlyReportTriggers, PhysicsWorld& world)
:mContactPairs(contactPairs), mLostContactPairs(lostContactPairs), :mContactPairs(contactPairs), mLostContactPairs(lostContactPairs),
mContactPairsIndices(world.mMemoryManager.getHeapAllocator()), mLostContactPairsIndices(world.mMemoryManager.getHeapAllocator()), mWorld(world) { mContactPairsIndices(world.mMemoryManager.getHeapAllocator()), mLostContactPairsIndices(world.mMemoryManager.getHeapAllocator()), mWorld(world) {
@ -75,7 +75,7 @@ OverlapCallback::CallbackData::CallbackData(List<ContactPair>& contactPairs, Lis
for (uint i=0; i < mContactPairs.size(); i++) { for (uint i=0; i < mContactPairs.size(); i++) {
// If the contact pair contains contacts (and is therefore not an overlap/trigger event) // 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); mContactPairsIndices.add(i);
} }
} }
@ -83,7 +83,7 @@ OverlapCallback::CallbackData::CallbackData(List<ContactPair>& contactPairs, Lis
for (uint i=0; i < mLostContactPairs.size(); i++) { for (uint i=0; i < mLostContactPairs.size(); i++) {
// If the contact pair contains contacts (and is therefore not an overlap/trigger event) // 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); mLostContactPairsIndices.add(i);
} }
} }

View File

@ -553,7 +553,7 @@ bool CollisionDetectionSystem::computeNarrowPhaseOverlapSnapshot(NarrowPhaseInpu
computeOverlapSnapshotContactPairs(narrowPhaseInput, contactPairs); computeOverlapSnapshotContactPairs(narrowPhaseInput, contactPairs);
// Report overlapping colliders // Report overlapping colliders
OverlapCallback::CallbackData callbackData(contactPairs, lostContactPairs, *mWorld); OverlapCallback::CallbackData callbackData(contactPairs, lostContactPairs, false, *mWorld);
(*callback).onOverlap(callbackData); (*callback).onOverlap(callbackData);
} }
@ -1421,7 +1421,7 @@ void CollisionDetectionSystem::reportTriggers(EventListener& eventListener, List
// If there are contacts // If there are contacts
if (contactPairs->size() + lostContactPairs.size() > 0) { 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 // Call the callback method to report the overlapping shapes
eventListener.onTrigger(callbackData); eventListener.onTrigger(callbackData);