mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
constraints now account for timeScale
This commit is contained in:
parent
613e63699b
commit
537f0912c3
2 changed files with 8 additions and 6 deletions
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue