diff --git a/src/collision/CollisionDetection.cpp b/src/collision/CollisionDetection.cpp index 00f38793..cfcce432 100644 --- a/src/collision/CollisionDetection.cpp +++ b/src/collision/CollisionDetection.cpp @@ -248,7 +248,7 @@ void CollisionDetection::computeNarrowPhase() { // If there is no collision algorithm between those two kinds of shapes, skip it if (narrowPhaseAlgorithm != nullptr) { - LastFrameCollisionInfo* lastCollisionFrameInfo = mNarrowPhaseInfoBatch.getLastFrameCollisionInfo(batchIndex); + LastFrameCollisionInfo* lastCollisionFrameInfo = mNarrowPhaseInfoBatch.lastFrameCollisionInfos[batchIndex]; // Use the narrow-phase collision detection algorithm to check // if there really is a collision. If a collision occurs, the diff --git a/src/collision/NarrowPhaseInfoBatch.cpp b/src/collision/NarrowPhaseInfoBatch.cpp index 932b99ed..3888fc29 100644 --- a/src/collision/NarrowPhaseInfoBatch.cpp +++ b/src/collision/NarrowPhaseInfoBatch.cpp @@ -35,7 +35,7 @@ using namespace reactphysics3d; NarrowPhaseInfoBatch::NarrowPhaseInfoBatch(MemoryAllocator& allocator) : mMemoryAllocator(allocator), overlappingPairs(allocator), collisionShapes1(allocator), collisionShapes2(allocator), shape1ToWorldTransforms(allocator), shape2ToWorldTransforms(allocator), - isColliding(allocator), contactPoints(allocator), collisionShapeAllocators(allocator) { + isColliding(allocator), contactPoints(allocator), collisionShapeAllocators(allocator), lastFrameCollisionInfos(allocator) { } @@ -60,6 +60,8 @@ void NarrowPhaseInfoBatch::addNarrowPhaseInfo(OverlappingPair* pair, CollisionSh // Add a collision info for the two collision shapes into the overlapping pair (if not present yet) pair->addLastFrameInfoIfNecessary(shape1->getId(), shape2->getId()); + + lastFrameCollisionInfos.add(pair->getLastFrameCollisionInfo(shape1->getId(), shape2->getId())); } // Add a new contact point @@ -125,6 +127,7 @@ void NarrowPhaseInfoBatch::clear() { shape1ToWorldTransforms.clear(); shape2ToWorldTransforms.clear(); collisionShapeAllocators.clear(); + lastFrameCollisionInfos.clear(); isColliding.clear(); contactPoints.clear(); } diff --git a/src/collision/NarrowPhaseInfoBatch.h b/src/collision/NarrowPhaseInfoBatch.h index 6ccff688..0a9c0ae0 100644 --- a/src/collision/NarrowPhaseInfoBatch.h +++ b/src/collision/NarrowPhaseInfoBatch.h @@ -78,6 +78,9 @@ struct NarrowPhaseInfoBatch { /// Memory allocators for the collision shape (Used to release TriangleShape memory in destructor) List collisionShapeAllocators; + /// Collision infos of the previous frame + List lastFrameCollisionInfos; + /// Constructor NarrowPhaseInfoBatch(MemoryAllocator& allocator); @@ -101,9 +104,6 @@ struct NarrowPhaseInfoBatch { /// Clear all the objects in the batch void clear(); - - /// Get the last collision frame info for temporal coherence - LastFrameCollisionInfo* getLastFrameCollisionInfo(uint index) const; }; /// Return the number of objects in the batch @@ -111,11 +111,6 @@ inline uint NarrowPhaseInfoBatch::getNbObjects() const { return overlappingPairs.size(); } -// Get the last collision frame info for temporal coherence -inline LastFrameCollisionInfo* NarrowPhaseInfoBatch::getLastFrameCollisionInfo(uint index) const { - return overlappingPairs[index]->getLastFrameCollisionInfo(collisionShapes1[index]->getId(), collisionShapes2[index]->getId()); -} - } #endif diff --git a/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp b/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp index c34aa031..54797d86 100644 --- a/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp +++ b/src/collision/narrowphase/CapsuleVsConvexPolyhedronAlgorithm.cpp @@ -64,7 +64,7 @@ void CapsuleVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& nar for (uint batchIndex = batchStartIndex; batchIndex < batchStartIndex + batchNbItems; batchIndex++) { // Get the last frame collision info - LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.getLastFrameCollisionInfo(batchIndex); + LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.lastFrameCollisionInfos[batchIndex]; lastFrameCollisionInfo->wasUsingGJK = true; lastFrameCollisionInfo->wasUsingSAT = false; diff --git a/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp b/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp index eb8cd159..c20d0390 100644 --- a/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp +++ b/src/collision/narrowphase/ConvexPolyhedronVsConvexPolyhedronAlgorithm.cpp @@ -54,7 +54,7 @@ void ConvexPolyhedronVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoB for (uint batchIndex = batchStartIndex; batchIndex < batchStartIndex + batchNbItems; batchIndex++) { // Get the last frame collision info - LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.getLastFrameCollisionInfo(batchIndex); + LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.lastFrameCollisionInfos[batchIndex]; lastFrameCollisionInfo->wasUsingSAT = true; lastFrameCollisionInfo->wasUsingGJK = false; diff --git a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp index e046fcfd..64b9ac87 100644 --- a/src/collision/narrowphase/GJK/GJKAlgorithm.cpp +++ b/src/collision/narrowphase/GJK/GJKAlgorithm.cpp @@ -92,7 +92,7 @@ void GJKAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uin VoronoiSimplex simplex; // Get the last collision frame info - LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.getLastFrameCollisionInfo(batchIndex); + LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.lastFrameCollisionInfos[batchIndex]; // Get the previous point V (last cached separating axis) Vector3 v; diff --git a/src/collision/narrowphase/SAT/SATAlgorithm.cpp b/src/collision/narrowphase/SAT/SATAlgorithm.cpp index d88911e6..8ef648ef 100644 --- a/src/collision/narrowphase/SAT/SATAlgorithm.cpp +++ b/src/collision/narrowphase/SAT/SATAlgorithm.cpp @@ -494,7 +494,7 @@ void SATAlgorithm::testCollisionConvexPolyhedronVsConvexPolyhedron(NarrowPhaseIn Vector3 minEdgeVsEdgeSeparatingAxisPolyhedron2Space; bool isShape1Triangle = polyhedron1->getName() == CollisionShapeName::TRIANGLE; - LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.getLastFrameCollisionInfo(batchIndex); + LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.lastFrameCollisionInfos[batchIndex]; // If the last frame collision info is valid and was also using SAT algorithm if (lastFrameCollisionInfo->isValid && lastFrameCollisionInfo->wasUsingSAT) { diff --git a/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp b/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp index fac9baf9..11574330 100644 --- a/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp +++ b/src/collision/narrowphase/SphereVsConvexPolyhedronAlgorithm.cpp @@ -62,7 +62,7 @@ void SphereVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narr narrowPhaseInfoBatch.collisionShapes2[batchIndex]->getType() == CollisionShapeType::SPHERE); // Get the last frame collision info - LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.getLastFrameCollisionInfo(batchIndex); + LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.lastFrameCollisionInfos[batchIndex]; lastFrameCollisionInfo->wasUsingGJK = true; lastFrameCollisionInfo->wasUsingSAT = false;