From 537f0912c321a1334b239fb2e2d20afc48702a0f Mon Sep 17 00:00:00 2001 From: liabru Date: Wed, 23 Apr 2014 14:26:57 +0100 Subject: [PATCH] constraints now account for timeScale --- src/constraint/Constraint.js | 12 +++++++----- src/core/Engine.js | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/constraint/Constraint.js b/src/constraint/Constraint.js index 3ab7d9f..ce1324b 100644 --- a/src/constraint/Constraint.js +++ b/src/constraint/Constraint.js @@ -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, diff --git a/src/core/Engine.js b/src/core/Engine.js index 79e288d..21f4060 100644 --- a/src/core/Engine.js +++ b/src/core/Engine.js @@ -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);