Skip to content

Commit

Permalink
use speed getter in Matter.Sleeping and Matter.Render
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Jan 6, 2022
1 parent b6de9ed commit 6579dfd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/core/Sleeping.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var Sleeping = {};

module.exports = Sleeping;

var Body = require('../body/Body');
var Events = require('./Events');
var Common = require('./Common');

Expand All @@ -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) {
Expand Down Expand Up @@ -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++) {
Expand Down
5 changes: 4 additions & 1 deletion src/render/Render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6579dfd

Please sign in to comment.