0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-26 13:49:01 -05:00

fixed collision incident and reference body mapping

This commit is contained in:
liabru 2015-02-25 00:12:21 +00:00
parent b8f3784b76
commit 757fffaf20

View file

@ -46,9 +46,11 @@ var SAT = {};
if (prevCol && canReusePrevCol) { if (prevCol && canReusePrevCol) {
// if we can reuse the collision result // if we can reuse the collision result
// we only need to test the previously found axis // we only need to test the previously found axis
var axes = [prevCol.bodyA.axes[prevCol.axisNumber]]; var axisBodyA = collision.axisBody,
axisBodyB = axisBodyA === bodyA ? bodyB : bodyA,
axes = [axisBodyA.axes[prevCol.axisNumber]];
minOverlap = _overlapAxes(prevCol.bodyA.vertices, prevCol.bodyB.vertices, axes); minOverlap = _overlapAxes(axisBodyA.vertices, axisBodyB.vertices, axes);
collision.reused = true; collision.reused = true;
if (minOverlap.overlap <= 0) { if (minOverlap.overlap <= 0) {
@ -74,18 +76,18 @@ var SAT = {};
if (overlapAB.overlap < overlapBA.overlap) { if (overlapAB.overlap < overlapBA.overlap) {
minOverlap = overlapAB; minOverlap = overlapAB;
collision.bodyA = bodyA; collision.axisBody = bodyA;
collision.bodyB = bodyB;
} else { } else {
minOverlap = overlapBA; minOverlap = overlapBA;
collision.bodyA = bodyB; collision.axisBody = bodyB;
collision.bodyB = bodyA;
} }
// important for reuse later // important for reuse later
collision.axisNumber = minOverlap.axisNumber; collision.axisNumber = minOverlap.axisNumber;
} }
collision.bodyA = bodyA.id < bodyB.id ? bodyA : bodyB;
collision.bodyB = bodyA.id < bodyB.id ? bodyB : bodyA;
collision.collided = true; collision.collided = true;
collision.normal = minOverlap.axis; collision.normal = minOverlap.axis;
collision.depth = minOverlap.overlap; collision.depth = minOverlap.overlap;