mirror of
https://github.com/liabru/matter-js.git
synced 2025-02-07 19:06:26 -05:00
optimised Resolver.solvePosition
This commit is contained in:
parent
a882a74cd5
commit
3cf65e8051
1 changed files with 17 additions and 17 deletions
|
@ -29,10 +29,11 @@ var Bounds = require('../geometry/Bounds');
|
||||||
Resolver.preSolvePosition = function(pairs) {
|
Resolver.preSolvePosition = function(pairs) {
|
||||||
var i,
|
var i,
|
||||||
pair,
|
pair,
|
||||||
activeCount;
|
activeCount,
|
||||||
|
pairsLength = pairs.length;
|
||||||
|
|
||||||
// find total contacts on each body
|
// find total contacts on each body
|
||||||
for (i = 0; i < pairs.length; i++) {
|
for (i = 0; i < pairsLength; i++) {
|
||||||
pair = pairs[i];
|
pair = pairs[i];
|
||||||
|
|
||||||
if (!pair.isActive)
|
if (!pair.isActive)
|
||||||
|
@ -57,17 +58,13 @@ var Bounds = require('../geometry/Bounds');
|
||||||
bodyA,
|
bodyA,
|
||||||
bodyB,
|
bodyB,
|
||||||
normal,
|
normal,
|
||||||
bodyBtoA,
|
|
||||||
contactShare,
|
contactShare,
|
||||||
positionImpulse,
|
positionImpulse,
|
||||||
contactCount = {},
|
positionDampen = Resolver._positionDampen,
|
||||||
tempA = Vector._temp[0],
|
pairsLength = pairs.length;
|
||||||
tempB = Vector._temp[1],
|
|
||||||
tempC = Vector._temp[2],
|
|
||||||
tempD = Vector._temp[3];
|
|
||||||
|
|
||||||
// find impulses required to resolve penetration
|
// find impulses required to resolve penetration
|
||||||
for (i = 0; i < pairs.length; i++) {
|
for (i = 0; i < pairsLength; i++) {
|
||||||
pair = pairs[i];
|
pair = pairs[i];
|
||||||
|
|
||||||
if (!pair.isActive || pair.isSensor)
|
if (!pair.isActive || pair.isSensor)
|
||||||
|
@ -78,15 +75,18 @@ var Bounds = require('../geometry/Bounds');
|
||||||
bodyB = collision.parentB;
|
bodyB = collision.parentB;
|
||||||
normal = collision.normal;
|
normal = collision.normal;
|
||||||
|
|
||||||
|
// TODO: behaviour change: replace with fully simplified version
|
||||||
// get current separation between body edges involved in collision
|
// get current separation between body edges involved in collision
|
||||||
bodyBtoA = Vector.sub(Vector.add(bodyB.positionImpulse, bodyB.position, tempA),
|
pair.separation =
|
||||||
Vector.add(bodyA.positionImpulse,
|
normal.x * (
|
||||||
Vector.sub(bodyB.position, collision.penetration, tempB), tempC), tempD);
|
(bodyB.positionImpulse.x + bodyB.position.x) - (bodyA.positionImpulse.x + (bodyB.position.x - collision.penetration.x))
|
||||||
|
)
|
||||||
pair.separation = Vector.dot(normal, bodyBtoA);
|
+ normal.y * (
|
||||||
|
(bodyB.positionImpulse.y + bodyB.position.y) - (bodyA.positionImpulse.y + (bodyB.position.y - collision.penetration.y))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < pairs.length; i++) {
|
for (i = 0; i < pairsLength; i++) {
|
||||||
pair = pairs[i];
|
pair = pairs[i];
|
||||||
|
|
||||||
if (!pair.isActive || pair.isSensor)
|
if (!pair.isActive || pair.isSensor)
|
||||||
|
@ -102,13 +102,13 @@ var Bounds = require('../geometry/Bounds');
|
||||||
positionImpulse *= 2;
|
positionImpulse *= 2;
|
||||||
|
|
||||||
if (!(bodyA.isStatic || bodyA.isSleeping)) {
|
if (!(bodyA.isStatic || bodyA.isSleeping)) {
|
||||||
contactShare = Resolver._positionDampen / bodyA.totalContacts;
|
contactShare = positionDampen / bodyA.totalContacts;
|
||||||
bodyA.positionImpulse.x += normal.x * positionImpulse * contactShare;
|
bodyA.positionImpulse.x += normal.x * positionImpulse * contactShare;
|
||||||
bodyA.positionImpulse.y += normal.y * positionImpulse * contactShare;
|
bodyA.positionImpulse.y += normal.y * positionImpulse * contactShare;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(bodyB.isStatic || bodyB.isSleeping)) {
|
if (!(bodyB.isStatic || bodyB.isSleeping)) {
|
||||||
contactShare = Resolver._positionDampen / bodyB.totalContacts;
|
contactShare = positionDampen / bodyB.totalContacts;
|
||||||
bodyB.positionImpulse.x -= normal.x * positionImpulse * contactShare;
|
bodyB.positionImpulse.x -= normal.x * positionImpulse * contactShare;
|
||||||
bodyB.positionImpulse.y -= normal.y * positionImpulse * contactShare;
|
bodyB.positionImpulse.y -= normal.y * positionImpulse * contactShare;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue