From e891d37b65ed7e706d37643300c73eca6a222aea Mon Sep 17 00:00:00 2001 From: liabru Date: Sun, 3 Mar 2024 21:50:40 +0000 Subject: [PATCH] preserve pair.contacts order --- src/collision/Pair.js | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/collision/Pair.js b/src/collision/Pair.js index f965313..549ff36 100644 --- a/src/collision/Pair.js +++ b/src/collision/Pair.js @@ -74,29 +74,21 @@ var Contact = require('./Contact'); pair.contactCount = supportCount; collision.pair = pair; - var support = supports[0], - contact = contacts[0]; + var supportA = supports[0], + contactA = contacts[0], + supportB = supports[1], + contactB = contacts[1]; - // reset first contact if support changed - if (contact.vertex !== support) { - contact.vertex = support; - contact.normalImpulse = 0; - contact.tangentImpulse = 0; + // match contacts to supports + if (contactB.vertex === supportA || contactA.vertex === supportB) { + contacts[1] = contactA; + contacts[0] = contactA = contactB; + contactB = contacts[1]; } - if (supportCount < 2) { - return; - } - - 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; }; /**