0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-25 13:39:06 -05:00

refactor Resolver.solvePosition damping argument

This commit is contained in:
liabru 2022-09-02 17:18:02 +01:00
parent ee7b00897d
commit cce3152664
2 changed files with 6 additions and 4 deletions

View file

@ -50,9 +50,9 @@ var Bounds = require('../geometry/Bounds');
* @method solvePosition
* @param {pair[]} pairs
* @param {number} delta
* @param {number} positionIterations
* @param {number} [damping=1]
*/
Resolver.solvePosition = function(pairs, delta, positionIterations) {
Resolver.solvePosition = function(pairs, delta, damping) {
var i,
pair,
collision,
@ -61,7 +61,7 @@ var Bounds = require('../geometry/Bounds');
normal,
contactShare,
positionImpulse,
positionDampen = Resolver._positionDampen * Common.clamp(20 / positionIterations, 0, 1),
positionDampen = Resolver._positionDampen * (damping || 1),
slopDampen = Common.clamp(delta / Common._timeUnit, 0, 1),
pairsLength = pairs.length;

View file

@ -147,9 +147,11 @@ var Body = require('../body/Body');
Sleeping.afterCollisions(pairs.list);
// iteratively resolve position between collisions
var positionDamping = Common.clamp(20 / engine.positionIterations, 0, 1);
Resolver.preSolvePosition(pairs.list);
for (i = 0; i < engine.positionIterations; i++) {
Resolver.solvePosition(pairs.list, delta, engine.positionIterations);
Resolver.solvePosition(pairs.list, delta, positionDamping);
}
Resolver.postSolvePosition(allBodies);