From cce315266436d58458ab4feca9195639897e0ad9 Mon Sep 17 00:00:00 2001 From: liabru Date: Fri, 2 Sep 2022 17:18:02 +0100 Subject: [PATCH] refactor Resolver.solvePosition damping argument --- src/collision/Resolver.js | 6 +++--- src/core/Engine.js | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/collision/Resolver.js b/src/collision/Resolver.js index 86a946c..d1be837 100644 --- a/src/collision/Resolver.js +++ b/src/collision/Resolver.js @@ -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; diff --git a/src/core/Engine.js b/src/core/Engine.js index 3c1c716..cb4fa13 100644 --- a/src/core/Engine.js +++ b/src/core/Engine.js @@ -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);