Remove mIsActive variable from OverlappingPairs
This commit is contained in:
parent
eeb5b07f35
commit
05e3b00689
@ -57,7 +57,7 @@ class RigidBody : public CollisionBody {
|
|||||||
void setIsSleeping(bool isSleeping);
|
void setIsSleeping(bool isSleeping);
|
||||||
|
|
||||||
/// Update whether the current overlapping pairs where this body is involed are active or not
|
/// 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
|
/// Compute and return the local-space center of mass of the body using its colliders
|
||||||
Vector3 computeCenterOfMass() const;
|
Vector3 computeCenterOfMass() const;
|
||||||
|
@ -358,6 +358,7 @@ class RigidBodyComponents : public Components {
|
|||||||
|
|
||||||
friend class PhysicsWorld;
|
friend class PhysicsWorld;
|
||||||
friend class ContactSolverSystem;
|
friend class ContactSolverSystem;
|
||||||
|
friend class CollisionDetectionSystem;
|
||||||
friend class SolveBallAndSocketJointSystem;
|
friend class SolveBallAndSocketJointSystem;
|
||||||
friend class SolveFixedJointSystem;
|
friend class SolveFixedJointSystem;
|
||||||
friend class SolveHingeJointSystem;
|
friend class SolveHingeJointSystem;
|
||||||
|
@ -166,9 +166,6 @@ class OverlappingPairs {
|
|||||||
/// True if we need to test if the convex vs convex overlapping pairs of shapes still overlap
|
/// True if we need to test if the convex vs convex overlapping pairs of shapes still overlap
|
||||||
bool* mNeedToTestOverlap;
|
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
|
/// Array with the pointer to the narrow-phase algorithm for each overlapping pair
|
||||||
NarrowPhaseAlgorithmType* mNarrowPhaseAlgorithmType;
|
NarrowPhaseAlgorithmType* mNarrowPhaseAlgorithmType;
|
||||||
|
|
||||||
@ -263,9 +260,6 @@ class OverlappingPairs {
|
|||||||
/// Return the entity of the second collider
|
/// Return the entity of the second collider
|
||||||
Entity getCollider2(uint64 pairId) const;
|
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
|
/// Return the index of a given overlapping pair in the internal array
|
||||||
uint64 getPairIndex(uint64 pairId) const;
|
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
|
/// 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);
|
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
|
/// Delete all the obsolete last frame collision info
|
||||||
void clearObsoleteLastFrameCollisionInfos();
|
void clearObsoleteLastFrameCollisionInfos();
|
||||||
|
|
||||||
@ -326,14 +317,6 @@ RP3D_FORCE_INLINE Entity OverlappingPairs::getCollider2(uint64 pairId) const {
|
|||||||
return mColliders2[mMapPairIdToPairIndex[pairId]];
|
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
|
// Return the index of a given overlapping pair in the internal array
|
||||||
RP3D_FORCE_INLINE uint64 OverlappingPairs::getPairIndex(uint64 pairId) const {
|
RP3D_FORCE_INLINE uint64 OverlappingPairs::getPairIndex(uint64 pairId) const {
|
||||||
assert(mMapPairIdToPairIndex.containsKey(pairId));
|
assert(mMapPairIdToPairIndex.containsKey(pairId));
|
||||||
|
@ -133,7 +133,11 @@ bool isPrimeNumber(int number);
|
|||||||
/// Here we assume that the two parameter numbers are sorted such that
|
/// Here we assume that the two parameter numbers are sorted such that
|
||||||
/// number1 = max(number1, number2)
|
/// number1 = max(number1, number2)
|
||||||
/// http://szudzik.com/ElegantPairing.pdf
|
/// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,11 +108,7 @@ void RigidBody::setType(BodyType type) {
|
|||||||
setIsSleeping(false);
|
setIsSleeping(false);
|
||||||
|
|
||||||
// Update the active status of currently overlapping pairs
|
// Update the active status of currently overlapping pairs
|
||||||
updateOverlappingPairs();
|
resetOverlappingPairs();
|
||||||
|
|
||||||
// Ask the broad-phase to test again the collision shapes of the body for collision
|
|
||||||
// detection (as if the body has moved)
|
|
||||||
askForBroadPhaseCollisionCheck();
|
|
||||||
|
|
||||||
// Reset the force and torque on the body
|
// Reset the force and torque on the body
|
||||||
mWorld.mRigidBodyComponents.setExternalForce(mEntity, Vector3::zero());
|
mWorld.mRigidBodyComponents.setExternalForce(mEntity, Vector3::zero());
|
||||||
@ -856,7 +852,7 @@ void RigidBody::setIsSleeping(bool isSleeping) {
|
|||||||
mWorld.setBodyDisabled(mEntity, isSleeping);
|
mWorld.setBodyDisabled(mEntity, isSleeping);
|
||||||
|
|
||||||
// Update the currently overlapping pairs
|
// Update the currently overlapping pairs
|
||||||
updateOverlappingPairs();
|
resetOverlappingPairs();
|
||||||
|
|
||||||
if (isSleeping) {
|
if (isSleeping) {
|
||||||
|
|
||||||
@ -871,8 +867,8 @@ void RigidBody::setIsSleeping(bool isSleeping) {
|
|||||||
(isSleeping ? "true" : "false"), __FILE__, __LINE__);
|
(isSleeping ? "true" : "false"), __FILE__, __LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update whether the current overlapping pairs where this body is involed are active or not
|
// 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::updateOverlappingPairs() {
|
void RigidBody::resetOverlappingPairs() {
|
||||||
|
|
||||||
// For each collider of the body
|
// For each collider of the body
|
||||||
const List<Entity>& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
const List<Entity>& colliderEntities = mWorld.mCollisionBodyComponents.getColliders(mEntity);
|
||||||
@ -883,9 +879,12 @@ void RigidBody::updateOverlappingPairs() {
|
|||||||
|
|
||||||
for (uint j=0; j < overlappingPairs.size(); j++) {
|
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.
|
/// Compute the inverse of the inertia tensor in world coordinates.
|
||||||
|
@ -64,8 +64,8 @@ void GJKAlgorithm::testCollision(NarrowPhaseInfoBatch& narrowPhaseInfoBatch, uin
|
|||||||
decimal prevDistSquare;
|
decimal prevDistSquare;
|
||||||
bool contactFound = false;
|
bool contactFound = false;
|
||||||
|
|
||||||
assert(narrowPhaseInfoBatch.narrowPhaseInfo[[batchIndex].collisionShape1->isConvex());
|
assert(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape1->isConvex());
|
||||||
assert(narrowPhaseInfoBatch.narrowPhaseInfo[[batchIndex].collisionShape2->isConvex());
|
assert(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape2->isConvex());
|
||||||
|
|
||||||
const ConvexShape* shape1 = static_cast<const ConvexShape*>(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape1);
|
const ConvexShape* shape1 = static_cast<const ConvexShape*>(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape1);
|
||||||
const ConvexShape* shape2 = static_cast<const ConvexShape*>(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape2);
|
const ConvexShape* shape2 = static_cast<const ConvexShape*>(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape2);
|
||||||
|
@ -55,7 +55,7 @@ void NarrowPhaseInfoBatch::clear() {
|
|||||||
// TODO OPTI : Better manage this
|
// TODO OPTI : Better manage this
|
||||||
for (uint i=0; i < narrowPhaseInfos.size(); i++) {
|
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
|
// Release the memory of the TriangleShape (this memory was allocated in the
|
||||||
// MiddlePhaseTriangleCallback::testTriangle() method)
|
// MiddlePhaseTriangleCallback::testTriangle() method)
|
||||||
|
@ -57,10 +57,10 @@ bool SphereVsConvexPolyhedronAlgorithm::testCollision(NarrowPhaseInfoBatch& narr
|
|||||||
// For each item in the batch
|
// For each item in the batch
|
||||||
for (uint batchIndex = batchStartIndex; batchIndex < batchStartIndex + batchNbItems; batchIndex++) {
|
for (uint batchIndex = batchStartIndex; batchIndex < batchStartIndex + batchNbItems; batchIndex++) {
|
||||||
|
|
||||||
assert(narrowPhaseInfoBatch.narrowPhaseInfo[[batchIndex].collisionShape1->getType() == CollisionShapeType::CONVEX_POLYHEDRON ||
|
assert(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape1->getType() == CollisionShapeType::CONVEX_POLYHEDRON ||
|
||||||
narrowPhaseInfoBatch.narrowPhaseInfo[[batchIndex].collisionShape2->getType() == CollisionShapeType::CONVEX_POLYHEDRON);
|
narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape2->getType() == CollisionShapeType::CONVEX_POLYHEDRON);
|
||||||
assert(narrowPhaseInfoBatch.narrowPhaseInfo[[batchIndex].collisionShape1->getType() == CollisionShapeType::SPHERE ||
|
assert(narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape1->getType() == CollisionShapeType::SPHERE ||
|
||||||
narrowPhaseInfoBatch.narrowPhaseInfo[[batchIndex].collisionShape2->getType() == CollisionShapeType::SPHERE);
|
narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].collisionShape2->getType() == CollisionShapeType::SPHERE);
|
||||||
|
|
||||||
// Get the last frame collision info
|
// Get the last frame collision info
|
||||||
LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].lastFrameCollisionInfo;
|
LastFrameCollisionInfo* lastFrameCollisionInfo = narrowPhaseInfoBatch.narrowPhaseInfos[batchIndex].lastFrameCollisionInfo;
|
||||||
|
@ -39,7 +39,7 @@ OverlappingPairs::OverlappingPairs(MemoryAllocator& persistentMemoryAllocator, M
|
|||||||
: mPersistentAllocator(persistentMemoryAllocator), mTempMemoryAllocator(temporaryMemoryAllocator),
|
: mPersistentAllocator(persistentMemoryAllocator), mTempMemoryAllocator(temporaryMemoryAllocator),
|
||||||
mNbPairs(0), mConcavePairsStartIndex(0), mPairDataSize(sizeof(uint64) + sizeof(int32) + sizeof(int32) + sizeof(Entity) +
|
mNbPairs(0), mConcavePairsStartIndex(0), mPairDataSize(sizeof(uint64) + sizeof(int32) + sizeof(int32) + sizeof(Entity) +
|
||||||
sizeof(Entity) + sizeof(Map<uint64, LastFrameCollisionInfo*>) +
|
sizeof(Entity) + sizeof(Map<uint64, LastFrameCollisionInfo*>) +
|
||||||
sizeof(bool) + sizeof(bool) + sizeof(NarrowPhaseAlgorithmType) +
|
sizeof(bool) + sizeof(NarrowPhaseAlgorithmType) +
|
||||||
sizeof(bool) + sizeof(bool) + sizeof(bool)),
|
sizeof(bool) + sizeof(bool) + sizeof(bool)),
|
||||||
mNbAllocatedPairs(0), mBuffer(nullptr),
|
mNbAllocatedPairs(0), mBuffer(nullptr),
|
||||||
mMapPairIdToPairIndex(persistentMemoryAllocator),
|
mMapPairIdToPairIndex(persistentMemoryAllocator),
|
||||||
@ -208,8 +208,7 @@ void OverlappingPairs::allocate(uint64 nbPairsToAllocate) {
|
|||||||
Entity* newColliders2 = reinterpret_cast<Entity*>(newColliders1 + nbPairsToAllocate);
|
Entity* newColliders2 = reinterpret_cast<Entity*>(newColliders1 + nbPairsToAllocate);
|
||||||
Map<uint64, LastFrameCollisionInfo*>* newLastFrameCollisionInfos = reinterpret_cast<Map<uint64, LastFrameCollisionInfo*>*>(newColliders2 + nbPairsToAllocate);
|
Map<uint64, LastFrameCollisionInfo*>* newLastFrameCollisionInfos = reinterpret_cast<Map<uint64, LastFrameCollisionInfo*>*>(newColliders2 + nbPairsToAllocate);
|
||||||
bool* newNeedToTestOverlap = reinterpret_cast<bool*>(newLastFrameCollisionInfos + nbPairsToAllocate);
|
bool* newNeedToTestOverlap = reinterpret_cast<bool*>(newLastFrameCollisionInfos + nbPairsToAllocate);
|
||||||
bool* newIsActive = reinterpret_cast<bool*>(newNeedToTestOverlap + nbPairsToAllocate);
|
NarrowPhaseAlgorithmType* newNarrowPhaseAlgorithmType = reinterpret_cast<NarrowPhaseAlgorithmType*>(newNeedToTestOverlap + nbPairsToAllocate);
|
||||||
NarrowPhaseAlgorithmType* newNarrowPhaseAlgorithmType = reinterpret_cast<NarrowPhaseAlgorithmType*>(newIsActive + nbPairsToAllocate);
|
|
||||||
bool* newIsShape1Convex = reinterpret_cast<bool*>(newNarrowPhaseAlgorithmType + nbPairsToAllocate);
|
bool* newIsShape1Convex = reinterpret_cast<bool*>(newNarrowPhaseAlgorithmType + nbPairsToAllocate);
|
||||||
bool* wereCollidingInPreviousFrame = reinterpret_cast<bool*>(newIsShape1Convex + nbPairsToAllocate);
|
bool* wereCollidingInPreviousFrame = reinterpret_cast<bool*>(newIsShape1Convex + nbPairsToAllocate);
|
||||||
bool* areCollidingInCurrentFrame = reinterpret_cast<bool*>(wereCollidingInPreviousFrame + nbPairsToAllocate);
|
bool* areCollidingInCurrentFrame = reinterpret_cast<bool*>(wereCollidingInPreviousFrame + nbPairsToAllocate);
|
||||||
@ -225,7 +224,6 @@ void OverlappingPairs::allocate(uint64 nbPairsToAllocate) {
|
|||||||
memcpy(newColliders2, mColliders2, mNbPairs * sizeof(Entity));
|
memcpy(newColliders2, mColliders2, mNbPairs * sizeof(Entity));
|
||||||
memcpy(newLastFrameCollisionInfos, mLastFrameCollisionInfos, mNbPairs * sizeof(Map<uint64, LastFrameCollisionInfo*>));
|
memcpy(newLastFrameCollisionInfos, mLastFrameCollisionInfos, mNbPairs * sizeof(Map<uint64, LastFrameCollisionInfo*>));
|
||||||
memcpy(newNeedToTestOverlap, mNeedToTestOverlap, mNbPairs * sizeof(bool));
|
memcpy(newNeedToTestOverlap, mNeedToTestOverlap, mNbPairs * sizeof(bool));
|
||||||
memcpy(newIsActive, mIsActive, mNbPairs * sizeof(bool));
|
|
||||||
memcpy(newNarrowPhaseAlgorithmType, mNarrowPhaseAlgorithmType, mNbPairs * sizeof(NarrowPhaseAlgorithmType));
|
memcpy(newNarrowPhaseAlgorithmType, mNarrowPhaseAlgorithmType, mNbPairs * sizeof(NarrowPhaseAlgorithmType));
|
||||||
memcpy(newIsShape1Convex, mIsShape1Convex, mNbPairs * sizeof(bool));
|
memcpy(newIsShape1Convex, mIsShape1Convex, mNbPairs * sizeof(bool));
|
||||||
memcpy(wereCollidingInPreviousFrame, mCollidingInPreviousFrame, mNbPairs * sizeof(bool));
|
memcpy(wereCollidingInPreviousFrame, mCollidingInPreviousFrame, mNbPairs * sizeof(bool));
|
||||||
@ -243,7 +241,6 @@ void OverlappingPairs::allocate(uint64 nbPairsToAllocate) {
|
|||||||
mColliders2 = newColliders2;
|
mColliders2 = newColliders2;
|
||||||
mLastFrameCollisionInfos = newLastFrameCollisionInfos;
|
mLastFrameCollisionInfos = newLastFrameCollisionInfos;
|
||||||
mNeedToTestOverlap = newNeedToTestOverlap;
|
mNeedToTestOverlap = newNeedToTestOverlap;
|
||||||
mIsActive = newIsActive;
|
|
||||||
mNarrowPhaseAlgorithmType = newNarrowPhaseAlgorithmType;
|
mNarrowPhaseAlgorithmType = newNarrowPhaseAlgorithmType;
|
||||||
mIsShape1Convex = newIsShape1Convex;
|
mIsShape1Convex = newIsShape1Convex;
|
||||||
mCollidingInPreviousFrame = wereCollidingInPreviousFrame;
|
mCollidingInPreviousFrame = wereCollidingInPreviousFrame;
|
||||||
@ -301,7 +298,6 @@ uint64 OverlappingPairs::addPair(Collider* shape1, Collider* shape2) {
|
|||||||
new (mColliders2 + index) Entity(shape2->getEntity());
|
new (mColliders2 + index) Entity(shape2->getEntity());
|
||||||
new (mLastFrameCollisionInfos + index) Map<uint64, LastFrameCollisionInfo*>(mPersistentAllocator);
|
new (mLastFrameCollisionInfos + index) Map<uint64, LastFrameCollisionInfo*>(mPersistentAllocator);
|
||||||
new (mNeedToTestOverlap + index) bool(false);
|
new (mNeedToTestOverlap + index) bool(false);
|
||||||
new (mIsActive + index) bool(true);
|
|
||||||
new (mNarrowPhaseAlgorithmType + index) NarrowPhaseAlgorithmType(algorithmType);
|
new (mNarrowPhaseAlgorithmType + index) NarrowPhaseAlgorithmType(algorithmType);
|
||||||
new (mIsShape1Convex + index) bool(isShape1Convex);
|
new (mIsShape1Convex + index) bool(isShape1Convex);
|
||||||
new (mCollidingInPreviousFrame + index) bool(false);
|
new (mCollidingInPreviousFrame + index) bool(false);
|
||||||
@ -321,8 +317,6 @@ uint64 OverlappingPairs::addPair(Collider* shape1, Collider* shape2) {
|
|||||||
assert(mConcavePairsStartIndex <= mNbPairs);
|
assert(mConcavePairsStartIndex <= mNbPairs);
|
||||||
assert(mNbPairs == static_cast<uint64>(mMapPairIdToPairIndex.size()));
|
assert(mNbPairs == static_cast<uint64>(mMapPairIdToPairIndex.size()));
|
||||||
|
|
||||||
updateOverlappingPairIsActive(pairId);
|
|
||||||
|
|
||||||
return pairId;
|
return pairId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,7 +334,6 @@ void OverlappingPairs::movePairToIndex(uint64 srcIndex, uint64 destIndex) {
|
|||||||
new (mColliders2 + destIndex) Entity(mColliders2[srcIndex]);
|
new (mColliders2 + destIndex) Entity(mColliders2[srcIndex]);
|
||||||
new (mLastFrameCollisionInfos + destIndex) Map<uint64, LastFrameCollisionInfo*>(mLastFrameCollisionInfos[srcIndex]);
|
new (mLastFrameCollisionInfos + destIndex) Map<uint64, LastFrameCollisionInfo*>(mLastFrameCollisionInfos[srcIndex]);
|
||||||
mNeedToTestOverlap[destIndex] = mNeedToTestOverlap[srcIndex];
|
mNeedToTestOverlap[destIndex] = mNeedToTestOverlap[srcIndex];
|
||||||
mIsActive[destIndex] = mIsActive[srcIndex];
|
|
||||||
new (mNarrowPhaseAlgorithmType + destIndex) NarrowPhaseAlgorithmType(mNarrowPhaseAlgorithmType[srcIndex]);
|
new (mNarrowPhaseAlgorithmType + destIndex) NarrowPhaseAlgorithmType(mNarrowPhaseAlgorithmType[srcIndex]);
|
||||||
mIsShape1Convex[destIndex] = mIsShape1Convex[srcIndex];
|
mIsShape1Convex[destIndex] = mIsShape1Convex[srcIndex];
|
||||||
mCollidingInPreviousFrame[destIndex] = mCollidingInPreviousFrame[srcIndex];
|
mCollidingInPreviousFrame[destIndex] = mCollidingInPreviousFrame[srcIndex];
|
||||||
@ -368,7 +361,6 @@ void OverlappingPairs::swapPairs(uint64 index1, uint64 index2) {
|
|||||||
Entity collider2 = mColliders2[index1];
|
Entity collider2 = mColliders2[index1];
|
||||||
Map<uint64, LastFrameCollisionInfo*> lastFrameCollisionInfo(mLastFrameCollisionInfos[index1]);
|
Map<uint64, LastFrameCollisionInfo*> lastFrameCollisionInfo(mLastFrameCollisionInfos[index1]);
|
||||||
bool needTestOverlap = mNeedToTestOverlap[index1];
|
bool needTestOverlap = mNeedToTestOverlap[index1];
|
||||||
bool isActive = mIsActive[index1];
|
|
||||||
NarrowPhaseAlgorithmType narrowPhaseAlgorithmType = mNarrowPhaseAlgorithmType[index1];
|
NarrowPhaseAlgorithmType narrowPhaseAlgorithmType = mNarrowPhaseAlgorithmType[index1];
|
||||||
bool isShape1Convex = mIsShape1Convex[index1];
|
bool isShape1Convex = mIsShape1Convex[index1];
|
||||||
bool wereCollidingInPreviousFrame = mCollidingInPreviousFrame[index1];
|
bool wereCollidingInPreviousFrame = mCollidingInPreviousFrame[index1];
|
||||||
@ -387,7 +379,6 @@ void OverlappingPairs::swapPairs(uint64 index1, uint64 index2) {
|
|||||||
new (mColliders2 + index2) Entity(collider2);
|
new (mColliders2 + index2) Entity(collider2);
|
||||||
new (mLastFrameCollisionInfos + index2) Map<uint64, LastFrameCollisionInfo*>(lastFrameCollisionInfo);
|
new (mLastFrameCollisionInfos + index2) Map<uint64, LastFrameCollisionInfo*>(lastFrameCollisionInfo);
|
||||||
mNeedToTestOverlap[index2] = needTestOverlap;
|
mNeedToTestOverlap[index2] = needTestOverlap;
|
||||||
mIsActive[index2] = isActive;
|
|
||||||
new (mNarrowPhaseAlgorithmType + index2) NarrowPhaseAlgorithmType(narrowPhaseAlgorithmType);
|
new (mNarrowPhaseAlgorithmType + index2) NarrowPhaseAlgorithmType(narrowPhaseAlgorithmType);
|
||||||
mIsShape1Convex[index2] = isShape1Convex;
|
mIsShape1Convex[index2] = isShape1Convex;
|
||||||
mCollidingInPreviousFrame[index2] = wereCollidingInPreviousFrame;
|
mCollidingInPreviousFrame[index2] = wereCollidingInPreviousFrame;
|
||||||
@ -416,36 +407,6 @@ void OverlappingPairs::destroyPair(uint64 index) {
|
|||||||
mNarrowPhaseAlgorithmType[index].~NarrowPhaseAlgorithmType();
|
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
|
// 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) {
|
LastFrameCollisionInfo* OverlappingPairs::addLastFrameInfoIfNecessary(uint64 pairIndex, uint32 shapeId1, uint32 shapeId2) {
|
||||||
|
|
||||||
|
@ -403,13 +403,3 @@ bool reactphysics3d::isPrimeNumber(int number) {
|
|||||||
|
|
||||||
return number == 2;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -192,6 +192,29 @@ void CollisionDetectionSystem::updateOverlappingPairs(const List<Pair<int32, int
|
|||||||
// If the two colliders are from the same body, skip it
|
// If the two colliders are from the same body, skip it
|
||||||
if (body1Entity != body2Entity) {
|
if (body1Entity != body2Entity) {
|
||||||
|
|
||||||
|
const uint32 nbEnabledColliderComponents = mCollidersComponents.getNbEnabledComponents();
|
||||||
|
const bool isBody1Enabled = collider1Index < nbEnabledColliderComponents;
|
||||||
|
const bool isBody2Enabled = collider2Index < nbEnabledColliderComponents;
|
||||||
|
bool isBody1Static = false;
|
||||||
|
bool isBody2Static = false;
|
||||||
|
uint32 rigidBody1Index, rigidBody2Index;
|
||||||
|
if (mRigidBodyComponents.hasComponentGetIndex(body1Entity, rigidBody1Index)) {
|
||||||
|
isBody1Static = mRigidBodyComponents.mBodyTypes[rigidBody1Index] == BodyType::STATIC;
|
||||||
|
}
|
||||||
|
if (mRigidBodyComponents.hasComponentGetIndex(body2Entity, rigidBody2Index)) {
|
||||||
|
isBody2Static = mRigidBodyComponents.mBodyTypes[rigidBody2Index] == BodyType::STATIC;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool isBody1Active = isBody1Enabled && !isBody1Static;
|
||||||
|
const bool isBody2Active = isBody2Enabled && !isBody2Static;
|
||||||
|
|
||||||
|
if (isBody1Active || isBody2Active) {
|
||||||
|
|
||||||
|
// Check if the bodies are in the set of bodies that cannot collide between each other
|
||||||
|
// TODO OPTI : What not use the pairId here ??
|
||||||
|
const bodypair bodiesIndex = OverlappingPairs::computeBodiesIndexPair(body1Entity, body2Entity);
|
||||||
|
if (!mNoCollisionPairs.contains(bodiesIndex)) {
|
||||||
|
|
||||||
// Compute the overlapping pair ID
|
// Compute the overlapping pair ID
|
||||||
const uint64 pairId = pairNumbers(std::max(nodePair.first, nodePair.second), std::min(nodePair.first, nodePair.second));
|
const uint64 pairId = pairNumbers(std::max(nodePair.first, nodePair.second), std::min(nodePair.first, nodePair.second));
|
||||||
|
|
||||||
@ -229,6 +252,8 @@ void CollisionDetectionSystem::updateOverlappingPairs(const List<Pair<int32, int
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Compute the middle-phase collision detection
|
// Compute the middle-phase collision detection
|
||||||
void CollisionDetectionSystem::computeMiddlePhase(NarrowPhaseInput& narrowPhaseInput, bool needToReportContacts) {
|
void CollisionDetectionSystem::computeMiddlePhase(NarrowPhaseInput& narrowPhaseInput, bool needToReportContacts) {
|
||||||
@ -249,8 +274,6 @@ void CollisionDetectionSystem::computeMiddlePhase(NarrowPhaseInput& narrowPhaseI
|
|||||||
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i]) != -1);
|
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i]) != -1);
|
||||||
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders1[i]) != mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i]));
|
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 collider1Entity = mOverlappingPairs.mColliders1[i];
|
||||||
const Entity collider2Entity = mOverlappingPairs.mColliders2[i];
|
const Entity collider2Entity = mOverlappingPairs.mColliders2[i];
|
||||||
@ -276,7 +299,6 @@ void CollisionDetectionSystem::computeMiddlePhase(NarrowPhaseInput& narrowPhaseI
|
|||||||
|
|
||||||
mOverlappingPairs.mCollidingInCurrentFrame[i] = false;
|
mOverlappingPairs.mCollidingInCurrentFrame[i] = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// For each possible convex vs concave pair of bodies
|
// For each possible convex vs concave pair of bodies
|
||||||
const uint64 convexVsConcaveStartIndex = mOverlappingPairs.getConvexVsConcavePairsStartIndex();
|
const uint64 convexVsConcaveStartIndex = mOverlappingPairs.getConvexVsConcavePairsStartIndex();
|
||||||
@ -287,15 +309,11 @@ void CollisionDetectionSystem::computeMiddlePhase(NarrowPhaseInput& narrowPhaseI
|
|||||||
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i]) != -1);
|
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i]) != -1);
|
||||||
assert(mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders1[i]) != mCollidersComponents.getBroadPhaseId(mOverlappingPairs.mColliders2[i]));
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Compute the middle-phase collision detection
|
// Compute the middle-phase collision detection
|
||||||
void CollisionDetectionSystem::computeMiddlePhaseCollisionSnapshot(List<uint64>& convexPairs, List<uint64>& concavePairs, NarrowPhaseInput& narrowPhaseInput,
|
void CollisionDetectionSystem::computeMiddlePhaseCollisionSnapshot(List<uint64>& convexPairs, List<uint64>& concavePairs, NarrowPhaseInput& narrowPhaseInput,
|
||||||
|
@ -131,8 +131,6 @@ void ContactSolverSystem::initializeForIsland(uint islandIndex) {
|
|||||||
const uint rigidBodyIndex2 = mRigidBodyComponents.getEntityIndex(externalManifold.bodyEntity2);
|
const uint rigidBodyIndex2 = mRigidBodyComponents.getEntityIndex(externalManifold.bodyEntity2);
|
||||||
|
|
||||||
// Get the two bodies of the contact
|
// Get the two bodies of the contact
|
||||||
assert(body1 != nullptr);
|
|
||||||
assert(body2 != nullptr);
|
|
||||||
assert(!mBodyComponents.getIsEntityDisabled(externalManifold.bodyEntity1));
|
assert(!mBodyComponents.getIsEntityDisabled(externalManifold.bodyEntity1));
|
||||||
assert(!mBodyComponents.getIsEntityDisabled(externalManifold.bodyEntity2));
|
assert(!mBodyComponents.getIsEntityDisabled(externalManifold.bodyEntity2));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user