Small modifications in CollisionDetectionSystem

This commit is contained in:
Daniel Chappuis 2021-12-16 22:52:07 +01:00
parent 11d2d61936
commit 62e17155e3

View File

@ -201,7 +201,7 @@ void CollisionDetectionSystem::addNoCollisionPair(Entity body1Entity, Entity bod
mNoCollisionPairs.add(OverlappingPairs::computeBodiesIndexPair(body1Entity, body2Entity));
// If there already are OverlappingPairs involved, they should be removed; Or they will remain in collision state
Array<uint64> toBeRemove(mMemoryManager.getPoolAllocator());
Array<uint64> toBeRemoved(mMemoryManager.getPoolAllocator());
const Array<Entity>& colliderEntities = mWorld->mCollisionBodyComponents.getColliders(body1Entity);
for (uint32 i = 0; i < colliderEntities.size(); ++i) {
@ -210,18 +210,21 @@ void CollisionDetectionSystem::addNoCollisionPair(Entity body1Entity, Entity bod
for (uint32 j = 0; j < overlappingPairs.size(); ++j) {
OverlappingPairs::OverlappingPair *pair = mOverlappingPairs.getOverlappingPair(overlappingPairs[j]);
OverlappingPairs::OverlappingPair* pair = mOverlappingPairs.getOverlappingPair(overlappingPairs[j]);
assert(pair != nullptr);
const Entity overlappingBody1 = mOverlappingPairs.mColliderComponents.getBody(pair->collider1);
const Entity overlappingBody2 = mOverlappingPairs.mColliderComponents.getBody(pair->collider2);
if (overlappingBody1 == body2Entity || overlappingBody2 == body2Entity)
toBeRemove.add(overlappingPairs[j]);
if (overlappingBody1 == body2Entity || overlappingBody2 == body2Entity) {
toBeRemoved.add(overlappingPairs[j]);
}
}
}
for (uint32 i = 0; i < toBeRemove.size(); ++i)
mOverlappingPairs.removePair(toBeRemove[i]);
// Remove the overlapping pairs that needs to be removed
for (uint32 i = 0; i < toBeRemoved.size(); ++i) {
mOverlappingPairs.removePair(toBeRemoved[i]);
}
}
// Take an array of overlapping nodes in the broad-phase and create new overlapping pairs if necessary