0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-30 10:20:52 -05:00

use speed getter in Matter.Sleeping and Matter.Render

This commit is contained in:
liabru 2022-01-06 11:10:05 +00:00
parent b6de9ed8c5
commit 6579dfd83e
2 changed files with 10 additions and 5 deletions

View file

@ -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++) {

View file

@ -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;