mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
fixed more issues with timing.timeScale
This commit is contained in:
parent
a8d7a40249
commit
186d839942
3 changed files with 16 additions and 13 deletions
|
@ -168,10 +168,11 @@ var Body = {};
|
|||
* @method updateAll
|
||||
* @param {body[]} bodies
|
||||
* @param {number} deltaTime
|
||||
* @param {number} timeScale
|
||||
* @param {number} correction
|
||||
* @param {bounds} worldBounds
|
||||
*/
|
||||
Body.updateAll = function(bodies, deltaTime, correction, worldBounds) {
|
||||
Body.updateAll = function(bodies, deltaTime, timeScale, correction, worldBounds) {
|
||||
for (var i = 0; i < bodies.length; i++) {
|
||||
var body = bodies[i];
|
||||
|
||||
|
@ -184,7 +185,7 @@ var Body = {};
|
|||
|| body.bounds.max.y < worldBounds.min.y || body.bounds.min.y > worldBounds.max.y)
|
||||
continue;
|
||||
|
||||
Body.update(body, deltaTime, correction);
|
||||
Body.update(body, deltaTime, timeScale, correction);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -193,13 +194,14 @@ var Body = {};
|
|||
* @method update
|
||||
* @param {body} body
|
||||
* @param {number} deltaTime
|
||||
* @param {number} timeScale
|
||||
* @param {number} correction
|
||||
*/
|
||||
Body.update = function(body, deltaTime, correction) {
|
||||
var deltaTimeSquared = deltaTime * deltaTime * body.timeScale;
|
||||
Body.update = function(body, deltaTime, timeScale, correction) {
|
||||
var deltaTimeSquared = Math.pow(deltaTime * timeScale * body.timeScale, 2);
|
||||
|
||||
// from the previous step
|
||||
var frictionAir = 1 - body.frictionAir,
|
||||
var frictionAir = 1 - body.frictionAir * timeScale * body.timeScale,
|
||||
velocityPrevX = body.position.x - body.positionPrev.x,
|
||||
velocityPrevY = body.position.y - body.positionPrev.y;
|
||||
|
||||
|
|
|
@ -173,8 +173,9 @@ var Resolver = {};
|
|||
* @method solveVelocity
|
||||
* @param {pair[]} pairs
|
||||
*/
|
||||
Resolver.solveVelocity = function(pairs) {
|
||||
var impulse = {};
|
||||
Resolver.solveVelocity = function(pairs, timeScale) {
|
||||
var impulse = {},
|
||||
timeScaleSquared = timeScale * timeScale;
|
||||
|
||||
for (var i = 0; i < pairs.length; i++) {
|
||||
var pair = pairs[i];
|
||||
|
@ -219,8 +220,8 @@ var Resolver = {};
|
|||
|
||||
// coulomb friction
|
||||
var tangentImpulse = tangentVelocity;
|
||||
if (tangentSpeed > normalForce * pair.friction)
|
||||
tangentImpulse = normalForce * pair.friction * tangentVelocityDirection;
|
||||
if (tangentSpeed > normalForce * pair.friction * timeScaleSquared)
|
||||
tangentImpulse = normalForce * pair.friction * timeScaleSquared * tangentVelocityDirection;
|
||||
|
||||
// modify impulses accounting for mass, inertia and offset
|
||||
var oAcN = Vector.cross(offsetA, normal),
|
||||
|
@ -230,7 +231,7 @@ var Resolver = {};
|
|||
tangentImpulse *= share;
|
||||
|
||||
// handle high velocity and resting collisions separately
|
||||
if (normalVelocity < 0 && normalVelocity * normalVelocity > _restingThresh) {
|
||||
if (normalVelocity < 0 && normalVelocity * normalVelocity > _restingThresh * timeScaleSquared) {
|
||||
// high velocity so clear cached contact impulse
|
||||
contact.normalImpulse = 0;
|
||||
contact.tangentImpulse = 0;
|
||||
|
|
|
@ -191,7 +191,7 @@ var Engine = {};
|
|||
i;
|
||||
|
||||
// increment timestamp
|
||||
timing.timestamp += delta;
|
||||
timing.timestamp += delta * timing.timeScale;
|
||||
timing.correction = correction;
|
||||
|
||||
// create an event object
|
||||
|
@ -216,7 +216,7 @@ var Engine = {};
|
|||
Body.applyGravityAll(allBodies, world.gravity);
|
||||
|
||||
// update all body position and rotation by integration
|
||||
Body.updateAll(allBodies, delta * timing.timeScale, correction, world.bounds);
|
||||
Body.updateAll(allBodies, delta, timing.timeScale, correction, world.bounds);
|
||||
|
||||
// update all constraints
|
||||
for (i = 0; i < engine.constraintIterations; i++) {
|
||||
|
@ -256,7 +256,7 @@ var Engine = {};
|
|||
// iteratively resolve velocity between collisions
|
||||
Resolver.preSolveVelocity(pairs.list);
|
||||
for (i = 0; i < engine.velocityIterations; i++) {
|
||||
Resolver.solveVelocity(pairs.list);
|
||||
Resolver.solveVelocity(pairs.list, timing.timeScale);
|
||||
}
|
||||
|
||||
// iteratively resolve position between collisions
|
||||
|
|
Loading…
Reference in a new issue