mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-12 16:08:50 -05:00
optimised Collision.collides
This commit is contained in:
parent
51f49ce9d3
commit
6f8a54b253
1 changed files with 18 additions and 13 deletions
|
@ -100,27 +100,32 @@ var Pair = require('./Pair');
|
||||||
}
|
}
|
||||||
|
|
||||||
var normal = collision.normal,
|
var normal = collision.normal,
|
||||||
|
tangent = collision.tangent,
|
||||||
|
penetration = collision.penetration,
|
||||||
supports = collision.supports,
|
supports = collision.supports,
|
||||||
|
depth = minOverlap.overlap,
|
||||||
minAxis = minOverlap.axis,
|
minAxis = minOverlap.axis,
|
||||||
minAxisX = minAxis.x,
|
normalX = minAxis.x,
|
||||||
minAxisY = minAxis.y;
|
normalY = minAxis.y,
|
||||||
|
deltaX = bodyB.position.x - bodyA.position.x,
|
||||||
|
deltaY = bodyB.position.y - bodyA.position.y;
|
||||||
|
|
||||||
// ensure normal is facing away from bodyA
|
// ensure normal is facing away from bodyA
|
||||||
if (minAxisX * (bodyB.position.x - bodyA.position.x) + minAxisY * (bodyB.position.y - bodyA.position.y) < 0) {
|
if (normalX * deltaX + normalY * deltaY >= 0) {
|
||||||
normal.x = minAxisX;
|
normalX = -normalX;
|
||||||
normal.y = minAxisY;
|
normalY = -normalY;
|
||||||
} else {
|
|
||||||
normal.x = -minAxisX;
|
|
||||||
normal.y = -minAxisY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
normal.x = normalX;
|
||||||
|
normal.y = normalY;
|
||||||
|
|
||||||
collision.tangent.x = -normal.y;
|
tangent.x = -normalY;
|
||||||
collision.tangent.y = normal.x;
|
tangent.y = normalX;
|
||||||
|
|
||||||
collision.depth = minOverlap.overlap;
|
penetration.x = normalX * depth;
|
||||||
|
penetration.y = normalY * depth;
|
||||||
|
|
||||||
collision.penetration.x = normal.x * collision.depth;
|
collision.depth = depth;
|
||||||
collision.penetration.y = normal.y * collision.depth;
|
|
||||||
|
|
||||||
// find support points, there is always either exactly one or two
|
// find support points, there is always either exactly one or two
|
||||||
var supportsB = Collision._findSupports(bodyA, bodyB, normal, 1),
|
var supportsB = Collision._findSupports(bodyA, bodyB, normal, 1),
|
||||||
|
|
Loading…
Reference in a new issue