From 6579dfd83e21421a933073371eced342c116f669 Mon Sep 17 00:00:00 2001 From: liabru Date: Thu, 6 Jan 2022 11:10:05 +0000 Subject: [PATCH] use speed getter in Matter.Sleeping and Matter.Render --- src/core/Sleeping.js | 10 ++++++---- src/render/Render.js | 5 ++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/Sleeping.js b/src/core/Sleeping.js index e431c57..b9b4512 100644 --- a/src/core/Sleeping.js +++ b/src/core/Sleeping.js @@ -8,6 +8,7 @@ var Sleeping = {}; module.exports = Sleeping; +var Body = require('../body/Body'); var Events = require('./Events'); var Common = require('./Common'); @@ -25,12 +26,14 @@ var Common = require('./Common'); */ Sleeping.update = function(bodies, delta) { var timeScale = delta / Common._timeUnit, - motionSleepThreshold = Sleeping._motionSleepThreshold * timeScale * timeScale; + motionSleepThreshold = Sleeping._motionSleepThreshold; // update bodies sleeping status for (var i = 0; i < bodies.length; i++) { var body = bodies[i], - motion = body.speed * body.speed + body.angularSpeed * body.angularSpeed; + speed = Body.getSpeed(body), + angularSpeed = Body.getAngularSpeed(body), + motion = speed * speed + angularSpeed * angularSpeed; // wake up bodies if they have a force applied if (body.force.x !== 0 || body.force.y !== 0) { @@ -63,8 +66,7 @@ var Common = require('./Common'); * @param {number} delta */ Sleeping.afterCollisions = function(pairs, delta) { - var timeScale = delta / Common._timeUnit, - motionSleepThreshold = Sleeping._motionSleepThreshold * timeScale * timeScale; + var motionSleepThreshold = Sleeping._motionSleepThreshold; // wake up bodies involved in collisions for (var i = 0; i < pairs.length; i++) { diff --git a/src/render/Render.js b/src/render/Render.js index 68739a9..7c6d65c 100644 --- a/src/render/Render.js +++ b/src/render/Render.js @@ -10,6 +10,7 @@ var Render = {}; module.exports = Render; +var Body = require('../body/Body'); var Common = require('../core/Common'); var Composite = require('../body/Composite'); var Bounds = require('../geometry/Bounds'); @@ -1106,8 +1107,10 @@ var Mouse = require('../core/Mouse'); if (!body.render.visible) continue; + var velocity = Body.getVelocity(body); + c.moveTo(body.position.x, body.position.y); - c.lineTo(body.position.x + body.velocity.x * 2, body.position.y + body.velocity.y * 2); + c.lineTo(body.position.x + velocity.x, body.position.y + velocity.y); } c.lineWidth = 3;