@@ -13,11 +13,14 @@ var Sleeping = {};
1313 _minBias = 0.9 ;
1414
1515 /**
16- * Description
16+ * Puts bodies to sleep or wakes them up depending on their motion.
1717 * @method update
1818 * @param {body[] } bodies
19+ * @param {number } timeScale
1920 */
20- Sleeping . update = function ( bodies ) {
21+ Sleeping . update = function ( bodies , timeScale ) {
22+ var timeFactor = timeScale * timeScale * timeScale ;
23+
2124 // update bodies sleeping status
2225 for ( var i = 0 ; i < bodies . length ; i ++ ) {
2326 var body = bodies [ i ] ,
@@ -35,7 +38,7 @@ var Sleeping = {};
3538 // biased average motion estimation between frames
3639 body . motion = _minBias * minMotion + ( 1 - _minBias ) * maxMotion ;
3740
38- if ( body . sleepThreshold > 0 && body . motion < _motionSleepThreshold ) {
41+ if ( body . sleepThreshold > 0 && body . motion < _motionSleepThreshold * timeFactor ) {
3942 body . sleepCounter += 1 ;
4043
4144 if ( body . sleepCounter >= body . sleepThreshold )
@@ -47,11 +50,14 @@ var Sleeping = {};
4750 } ;
4851
4952 /**
50- * Description
53+ * Given a set of colliding pairs, wakes the sleeping bodies involved.
5154 * @method afterCollisions
5255 * @param {pair[] } pairs
56+ * @param {number } timeScale
5357 */
54- Sleeping . afterCollisions = function ( pairs ) {
58+ Sleeping . afterCollisions = function ( pairs , timeScale ) {
59+ var timeFactor = timeScale * timeScale * timeScale ;
60+
5561 // wake up bodies involved in collisions
5662 for ( var i = 0 ; i < pairs . length ; i ++ ) {
5763 var pair = pairs [ i ] ;
@@ -72,7 +78,7 @@ var Sleeping = {};
7278 var sleepingBody = ( bodyA . isSleeping && ! bodyA . isStatic ) ? bodyA : bodyB ,
7379 movingBody = sleepingBody === bodyA ? bodyB : bodyA ;
7480
75- if ( ! sleepingBody . isStatic && movingBody . motion > _motionWakeThreshold ) {
81+ if ( ! sleepingBody . isStatic && movingBody . motion > _motionWakeThreshold * timeFactor ) {
7682 Sleeping . set ( sleepingBody , false ) ;
7783 }
7884 }
0 commit comments