0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-28 14:09:01 -05:00

constraints now account for timeScale

This commit is contained in:
liabru 2014-04-23 14:26:57 +01:00
parent 613e63699b
commit 537f0912c3
2 changed files with 8 additions and 6 deletions

View file

@ -67,10 +67,11 @@ var Constraint = {};
* Description
* @method solveAll
* @param {constraint[]} constraints
* @param {number} timeScale
*/
Constraint.solveAll = function(constraints) {
Constraint.solveAll = function(constraints, timeScale) {
for (var i = 0; i < constraints.length; i++) {
Constraint.solve(constraints[i]);
Constraint.solve(constraints[i], timeScale);
}
};
@ -78,8 +79,9 @@ var Constraint = {};
* Description
* @method solve
* @param {constraint} constraint
* @param {number} timeScale
*/
Constraint.solve = function(constraint) {
Constraint.solve = function(constraint, timeScale) {
var bodyA = constraint.bodyA,
bodyB = constraint.bodyB,
pointA = constraint.pointA,
@ -116,10 +118,10 @@ var Constraint = {};
// solve distance constraint with Gauss-Siedel method
var difference = (currentLength - constraint.length) / currentLength,
normal = Vector.div(delta, currentLength),
force = Vector.mult(delta, difference * 0.5 * constraint.stiffness);
force = Vector.mult(delta, difference * 0.5 * constraint.stiffness * timeScale * timeScale);
// if difference is very small, we can skip
if (Math.abs(1 - (currentLength / constraint.length)) < _minDifference)
if (Math.abs(1 - (currentLength / constraint.length)) < _minDifference * timeScale)
return;
var velocityPointA,

View file

@ -255,7 +255,7 @@ var Engine = {};
// update all constraints
for (i = 0; i < engine.constraintIterations; i++) {
Constraint.solveAll(allConstraints);
Constraint.solveAll(allConstraints, engine.timeScale);
}
Constraint.postSolveAll(allBodies);