mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-12 16:08:50 -05:00
added second pass for constraint solving
This commit is contained in:
parent
a5bd6b2d55
commit
f49d053e1f
2 changed files with 11 additions and 8 deletions
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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++) {
|
||||
|
|
Loading…
Reference in a new issue