Move contacts creation before islands creation

This commit is contained in:
Daniel Chappuis 2019-10-11 17:01:53 +02:00
parent 92b39ca6c0
commit 5f05fa372d
4 changed files with 7 additions and 26 deletions

View File

@ -121,9 +121,6 @@ void DynamicsWorld::update(decimal timeStep) {
// Create the islands
createIslands();
// Create the actual narrow-phase contacts
mCollisionDetection.createContacts();
// Report the contacts to the user
mCollisionDetection.reportContacts();
@ -580,9 +577,6 @@ void DynamicsWorld::createIslands() {
nbTotalManifolds += pair.potentialContactManifoldsIndices.size();
// Add the pair into the list of pair to process to create contacts
mCollisionDetection.mContactPairsIndicesOrderingForContacts.add(pair.contactPairIndex);
// Add the contact manifold into the island
mIslands.nbContactManifolds[islandIndex] += pair.potentialContactManifoldsIndices.size();
pair.isAlreadyInIsland = true;
@ -638,11 +632,6 @@ void DynamicsWorld::createIslands() {
}
}
// Add the contact pairs that are not part of islands at the end of the array of pairs for contacts creations
mCollisionDetection.mContactPairsIndicesOrderingForContacts.addRange(nonRigidBodiesContactPairs);
assert(mCollisionDetection.mCurrentContactPairs->size() == mCollisionDetection.mContactPairsIndicesOrderingForContacts.size());
mCollisionDetection.mMapBodyToContactPairs.clear(true);
}

View File

@ -64,7 +64,6 @@ CollisionDetectionSystem::CollisionDetectionSystem(CollisionWorld* world, ProxyS
mContactPairs2(mMemoryManager.getPoolAllocator()), mPreviousContactPairs(&mContactPairs1), mCurrentContactPairs(&mContactPairs2),
mMapPairIdToContactPairIndex1(mMemoryManager.getPoolAllocator()), mMapPairIdToContactPairIndex2(mMemoryManager.getPoolAllocator()),
mPreviousMapPairIdToContactPairIndex(&mMapPairIdToContactPairIndex1), mCurrentMapPairIdToContactPairIndex(&mMapPairIdToContactPairIndex2),
mContactPairsIndicesOrderingForContacts(memoryManager.getSingleFrameAllocator()),
mContactManifolds1(mMemoryManager.getPoolAllocator()), mContactManifolds2(mMemoryManager.getPoolAllocator()),
mPreviousContactManifolds(&mContactManifolds1), mCurrentContactManifolds(&mContactManifolds2),
mContactPoints1(mMemoryManager.getPoolAllocator()),
@ -464,7 +463,8 @@ void CollisionDetectionSystem::computeNarrowPhase() {
assert(mCurrentContactManifolds->size() == 0);
assert(mCurrentContactPoints->size() == 0);
mContactPairsIndicesOrderingForContacts.reserve(mCurrentContactPairs->size());
// Create the actual narrow-phase contacts
createContacts();
mNarrowPhaseInput.clear();
}
@ -605,17 +605,15 @@ void CollisionDetectionSystem::swapPreviousAndCurrentContacts() {
// Create the actual contact manifolds and contacts points
void CollisionDetectionSystem::createContacts() {
RP3D_PROFILE("CollisionDetection::createContacts()", mProfiler);
assert(mCurrentContactPairs->size() == mContactPairsIndicesOrderingForContacts.size());
RP3D_PROFILE("CollisionDetectionSystem::createContacts()", mProfiler);
mCurrentContactManifolds->reserve(mCurrentContactPairs->size());
mCurrentContactPoints->reserve(mCurrentContactManifolds->size());
// For each contact pair
for (uint p=0; p < mContactPairsIndicesOrderingForContacts.size(); p++) {
for (uint p=0; p < (*mCurrentContactPairs).size(); p++) {
ContactPair& contactPair = (*mCurrentContactPairs)[mContactPairsIndicesOrderingForContacts[p]];
ContactPair& contactPair = (*mCurrentContactPairs)[p];
assert(contactPair.potentialContactManifoldsIndices.size() > 0);
contactPair.contactManifoldsIndex = mCurrentContactManifolds->size();
@ -666,7 +664,6 @@ void CollisionDetectionSystem::createContacts() {
// Reset the potential contacts
mPotentialContactPoints.clear(true);
mPotentialContactManifolds.clear(true);
mContactPairsIndicesOrderingForContacts.clear(true);
}
// Create the actual contact manifolds and contacts points for testCollision() methods

View File

@ -135,12 +135,6 @@ class CollisionDetectionSystem {
/// (either mMapPairIdToContactPairIndex1 or mMapPairIdToContactPairIndex2)
Map<OverlappingPair::OverlappingPairId, uint>* mCurrentMapPairIdToContactPairIndex;
/// List of the indices of the contact pairs (in mCurrentContacPairs array) with contact pairs of
/// same islands packed together linearly and contact pairs that are not part of islands at the end.
/// This is used when we create contact manifolds and contact points so that there are also packed
/// together linearly if they are part of the same island.
List<uint> mContactPairsIndicesOrderingForContacts;
/// First list with the contact manifolds
List<ContactManifold> mContactManifolds1;

View File

@ -492,6 +492,8 @@ void ContactSolverSystem::solve() {
decimal lambdaTemp;
uint contactPointIndex = 0;
const decimal beta = mIsSplitImpulseActive ? BETA_SPLIT_IMPULSE : BETA;
// For each contact manifold
for (uint c=0; c<mNbContactManifolds; c++) {
@ -520,7 +522,6 @@ void ContactSolverSystem::solve() {
decimal Jv = deltaVDotN;
// Compute the bias "b" of the constraint
decimal beta = mIsSplitImpulseActive ? BETA_SPLIT_IMPULSE : BETA;
decimal biasPenetrationDepth = 0.0;
if (mContactPoints[contactPointIndex].penetrationDepth > SLOP) biasPenetrationDepth = -(beta/mTimeStep) *
max(0.0f, float(mContactPoints[contactPointIndex].penetrationDepth - SLOP));