Skip to content

Commit

Permalink
preserve pair.contacts order
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Mar 3, 2024
1 parent 89963f7 commit e891d37
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions src/collision/Pair.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,21 @@ var Contact = require('./Contact');
pair.contactCount = supportCount;
collision.pair = pair;

var support = supports[0],
contact = contacts[0];

// reset first contact if support changed
if (contact.vertex !== support) {
contact.vertex = support;
contact.normalImpulse = 0;
contact.tangentImpulse = 0;
}

if (supportCount < 2) {
return;
var supportA = supports[0],
contactA = contacts[0],
supportB = supports[1],
contactB = contacts[1];

// match contacts to supports
if (contactB.vertex === supportA || contactA.vertex === supportB) {
contacts[1] = contactA;
contacts[0] = contactA = contactB;
contactB = contacts[1];
}

support = supports[1];
contact = contacts[1];

// reset second contact if support changed
if (contact.vertex !== support) {
contact.vertex = support;
contact.normalImpulse = 0;
contact.tangentImpulse = 0;
}
// update contacts
contactA.vertex = supportA;
contactB.vertex = supportB;
};

/**
Expand Down

0 comments on commit e891d37

Please sign in to comment.