mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-23 09:26:51 -05:00
constraint early out for small differences
This commit is contained in:
parent
e88e94dde7
commit
365152df6e
1 changed files with 15 additions and 9 deletions
|
@ -18,6 +18,7 @@ var Constraint = {};
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
var _minLength = 0.000001,
|
var _minLength = 0.000001,
|
||||||
|
_minDifference = 0.001,
|
||||||
_nextId = 0;
|
_nextId = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -117,6 +118,10 @@ var Constraint = {};
|
||||||
normal = Vector.div(delta, currentLength),
|
normal = Vector.div(delta, currentLength),
|
||||||
force = Vector.mult(delta, difference * 0.5 * constraint.stiffness);
|
force = Vector.mult(delta, difference * 0.5 * constraint.stiffness);
|
||||||
|
|
||||||
|
// if difference is very small, we can skip
|
||||||
|
if (Math.abs(1 - (currentLength / constraint.length)) < _minDifference)
|
||||||
|
return;
|
||||||
|
|
||||||
var velocityPointA,
|
var velocityPointA,
|
||||||
velocityPointB,
|
velocityPointB,
|
||||||
offsetA,
|
offsetA,
|
||||||
|
@ -232,18 +237,19 @@ var Constraint = {};
|
||||||
var body = bodies[i],
|
var body = bodies[i],
|
||||||
impulse = body.constraintImpulse;
|
impulse = body.constraintImpulse;
|
||||||
|
|
||||||
if (impulse.x !== 0 || impulse.y !== 0 || impulse.angle !== 0) {
|
// update geometry and reset
|
||||||
// update geometry
|
|
||||||
Vertices.translate(body.vertices, impulse);
|
Vertices.translate(body.vertices, impulse);
|
||||||
|
|
||||||
|
if (impulse.angle !== 0) {
|
||||||
Vertices.rotate(body.vertices, impulse.angle, body.position);
|
Vertices.rotate(body.vertices, impulse.angle, body.position);
|
||||||
Axes.rotate(body.axes, impulse.angle);
|
Axes.rotate(body.axes, impulse.angle);
|
||||||
Bounds.update(body.bounds, body.vertices);
|
|
||||||
|
|
||||||
// reset body.constraintImpulse
|
|
||||||
impulse.x = 0;
|
|
||||||
impulse.y = 0;
|
|
||||||
impulse.angle = 0;
|
impulse.angle = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Bounds.update(body.bounds, body.vertices);
|
||||||
|
|
||||||
|
impulse.x = 0;
|
||||||
|
impulse.y = 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue