0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-27 09:50:52 -05:00

improve delta factors in resolver and constraint stiffness

This commit is contained in:
liabru 2022-08-05 23:41:24 +01:00
parent a5729684d1
commit 07d13fe903
3 changed files with 8 additions and 5 deletions

View file

@ -49,9 +49,10 @@ var Bounds = require('../geometry/Bounds');
* Find a solution for pair positions.
* @method solvePosition
* @param {pair[]} pairs
* @param {number} delta
* @param {number} positionIterations
*/
Resolver.solvePosition = function(pairs, positionIterations) {
Resolver.solvePosition = function(pairs, delta, positionIterations) {
var i,
pair,
collision,
@ -61,6 +62,7 @@ var Bounds = require('../geometry/Bounds');
contactShare,
positionImpulse,
positionDampen = Resolver._positionDampen * Common.clamp(20 / positionIterations, 0, 1),
slopDampen = delta / Common._timeUnit,
pairsLength = pairs.length;
// find impulses required to resolve penetration
@ -91,7 +93,7 @@ var Bounds = require('../geometry/Bounds');
bodyA = collision.parentA;
bodyB = collision.parentB;
normal = collision.normal;
positionImpulse = pair.separation - pair.slop;
positionImpulse = pair.separation - pair.slop * slopDampen;
if (bodyA.isStatic || bodyB.isStatic)
positionImpulse *= 2;

View file

@ -186,8 +186,9 @@ var Common = require('../core/Common');
// solve distance constraint with Gauss-Siedel method
var difference = (currentLength - constraint.length) / currentLength,
isRigid = constraint.stiffness >= 1 || constraint.length === 0,
stiffness = isRigid ? constraint.stiffness : constraint.stiffness * timeScale * timeScale,
damping = constraint.damping * timeScale,
stiffness = isRigid ? constraint.stiffness * timeScale
: constraint.stiffness * timeScale * timeScale,
damping = constraint.damping * timeScale * timeScale,
force = Vector.mult(delta, difference * stiffness),
massTotal = (bodyA ? bodyA.inverseMass : 0) + (bodyB ? bodyB.inverseMass : 0),
inertiaTotal = (bodyA ? bodyA.inverseInertia : 0) + (bodyB ? bodyB.inverseInertia : 0),

View file

@ -149,7 +149,7 @@ var Body = require('../body/Body');
// iteratively resolve position between collisions
Resolver.preSolvePosition(pairs.list);
for (i = 0; i < engine.positionIterations; i++) {
Resolver.solvePosition(pairs.list, engine.positionIterations);
Resolver.solvePosition(pairs.list, delta, engine.positionIterations);
}
Resolver.postSolvePosition(allBodies);