0
0
Fork 0
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:
liabru 2014-03-31 11:22:20 +01:00
parent e88e94dde7
commit 365152df6e

View file

@ -18,6 +18,7 @@ var Constraint = {};
(function() {
var _minLength = 0.000001,
_minDifference = 0.001,
_nextId = 0;
/**
@ -117,6 +118,10 @@ var Constraint = {};
normal = Vector.div(delta, currentLength),
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,
velocityPointB,
offsetA,
@ -232,18 +237,19 @@ var Constraint = {};
var body = bodies[i],
impulse = body.constraintImpulse;
if (impulse.x !== 0 || impulse.y !== 0 || impulse.angle !== 0) {
// update geometry
Vertices.translate(body.vertices, impulse);
// update geometry and reset
Vertices.translate(body.vertices, impulse);
if (impulse.angle !== 0) {
Vertices.rotate(body.vertices, impulse.angle, body.position);
Axes.rotate(body.axes, impulse.angle);
Bounds.update(body.bounds, body.vertices);
// reset body.constraintImpulse
impulse.x = 0;
impulse.y = 0;
impulse.angle = 0;
}
Bounds.update(body.bounds, body.vertices);
impulse.x = 0;
impulse.y = 0;
}
};