Skip to content

Commit

Permalink
change constraint solve order
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed May 3, 2017
1 parent a8d1950 commit a5bd6b2
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/constraint/Constraint.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,27 @@ var Common = require('../core/Common');
* @param {number} timeScale
*/
Constraint.solveAll = function(constraints, timeScale) {
for (var i = 0; i < constraints.length; i++) {
// Solve fixed constraints first.
for (var i = 0; i < constraints.length; i += 1) {
var constraint = constraints[i],
fixedA = !constraint.bodyA || (constraint.bodyA && constraint.bodyA.isStatic),
fixedB = !constraint.bodyB || (constraint.bodyB && constraint.bodyB.isStatic);

if (fixedA || fixedB) {
Constraint.solve(constraints[i], timeScale);
}
}

// Solve free constraints last.
for (i = 0; i < constraints.length; i += 1) {
constraint = constraints[i];
fixedA = !constraint.bodyA || (constraint.bodyA && constraint.bodyA.isStatic);
fixedB = !constraint.bodyB || (constraint.bodyB && constraint.bodyB.isStatic);

if (!fixedA && !fixedB) {
Constraint.solve(constraints[i], timeScale);
}
}
};

/**
Expand Down

0 comments on commit a5bd6b2

Please sign in to comment.