Skip to content

Commit

Permalink
added second pass for constraint solving
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed May 3, 2017
1 parent a5bd6b2 commit f49d053
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/constraint/Constraint.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@ var Common = require('../core/Common');

(function() {

var _zeroVector = { x: 0, y: 0 };

Constraint._warming = 0.4;
Constraint._torqueDampen = 0.8;
Constraint._torqueDampen = 1;
Constraint._minLength = 0.000001;

/**
Expand Down Expand Up @@ -121,8 +119,8 @@ var Common = require('../core/Common');
fixedB = !constraint.bodyB || (constraint.bodyB && constraint.bodyB.isStatic);

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

Expand Down
11 changes: 8 additions & 3 deletions src/core/Engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ var Body = require('../body/Body');
// update all body position and rotation by integration
_bodiesUpdate(allBodies, delta, timing.timeScale, correction, world.bounds);

// update all constraints
// update all constraints (first pass)
Constraint.preSolveAll(allBodies);
for (i = 0; i < engine.constraintIterations; i++) {
Constraint.solveAll(allConstraints, timing.timeScale);
Expand All @@ -158,7 +158,6 @@ var Body = require('../body/Body');

// broadphase pass: find potential collision pairs
if (broadphase.controller) {

// if world is dirty, we must flush the whole grid
if (world.isModified)
broadphase.controller.clear(broadphase);
Expand All @@ -167,7 +166,6 @@ var Body = require('../body/Body');
broadphase.controller.update(broadphase, allBodies, engine, world.isModified);
broadphasePairs = broadphase.pairsList;
} else {

// if no broadphase set, we just pass all bodies
broadphasePairs = allBodies;
}
Expand Down Expand Up @@ -201,6 +199,13 @@ var Body = require('../body/Body');
}
Resolver.postSolvePosition(allBodies);

// update all constraints (second pass)
Constraint.preSolveAll(allBodies);
for (i = 0; i < engine.constraintIterations; i++) {
Constraint.solveAll(allConstraints, timing.timeScale);
}
Constraint.postSolveAll(allBodies);

// iteratively resolve velocity between collisions
Resolver.preSolveVelocity(pairs.list);
for (i = 0; i < engine.velocityIterations; i++) {
Expand Down

0 comments on commit f49d053

Please sign in to comment.