Skip to content

Commit f49d053

Browse files
committed
added second pass for constraint solving
1 parent a5bd6b2 commit f49d053

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/constraint/Constraint.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ var Common = require('../core/Common');
2121

2222
(function() {
2323

24-
var _zeroVector = { x: 0, y: 0 };
25-
2624
Constraint._warming = 0.4;
27-
Constraint._torqueDampen = 0.8;
25+
Constraint._torqueDampen = 1;
2826
Constraint._minLength = 0.000001;
2927

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

123121
if (!fixedA && !fixedB) {
124-
Constraint.solve(constraints[i], timeScale);
125-
}
122+
Constraint.solve(constraints[i], timeScale);
123+
}
126124
}
127125
};
128126

src/core/Engine.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ var Body = require('../body/Body');
149149
// update all body position and rotation by integration
150150
_bodiesUpdate(allBodies, delta, timing.timeScale, correction, world.bounds);
151151

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

159159
// broadphase pass: find potential collision pairs
160160
if (broadphase.controller) {
161-
162161
// if world is dirty, we must flush the whole grid
163162
if (world.isModified)
164163
broadphase.controller.clear(broadphase);
@@ -167,7 +166,6 @@ var Body = require('../body/Body');
167166
broadphase.controller.update(broadphase, allBodies, engine, world.isModified);
168167
broadphasePairs = broadphase.pairsList;
169168
} else {
170-
171169
// if no broadphase set, we just pass all bodies
172170
broadphasePairs = allBodies;
173171
}
@@ -201,6 +199,13 @@ var Body = require('../body/Body');
201199
}
202200
Resolver.postSolvePosition(allBodies);
203201

202+
// update all constraints (second pass)
203+
Constraint.preSolveAll(allBodies);
204+
for (i = 0; i < engine.constraintIterations; i++) {
205+
Constraint.solveAll(allConstraints, timing.timeScale);
206+
}
207+
Constraint.postSolveAll(allBodies);
208+
204209
// iteratively resolve velocity between collisions
205210
Resolver.preSolveVelocity(pairs.list);
206211
for (i = 0; i < engine.velocityIterations; i++) {

0 commit comments

Comments
 (0)