diff --git a/build/matter.js b/build/matter.js index 4716aa8..05e9a36 100644 --- a/build/matter.js +++ b/build/matter.js @@ -3099,7 +3099,7 @@ var Bounds = _dereq_('../geometry/Bounds'); bodyBtoAY, positionImpulse, timeScale = delta / Common._timeUnit, - impulseCoefficient = Resolver._positionDampen * timeScale; + damping = Common.clamp(Resolver._positionDampen * timeScale, 0, 1); for (i = 0; i < bodies.length; i++) { var body = bodies[i]; @@ -3133,7 +3133,7 @@ var Bounds = _dereq_('../geometry/Bounds'); separation = normalX * bodyBtoAX + normalY * bodyBtoAY; pair.separation = separation; - positionImpulse = (separation - pair.slop) * impulseCoefficient; + positionImpulse = (separation - pair.slop) * damping; if (bodyA.isStatic || bodyB.isStatic) positionImpulse *= 2; @@ -6255,8 +6255,8 @@ var Common = _dereq_('./Common'); var runner = Common.extend(defaults, options); runner.delta = runner.delta || 1000 / runner.fps; - runner.deltaMin = runner.deltaMin || 1000 / runner.fps; - runner.deltaMax = runner.deltaMax || 1000 / (runner.fps * 0.5); + runner.deltaMin = runner.deltaMin || 1000 / 60;//1000 / runner.fps; + runner.deltaMax = runner.deltaMax || 1000 / 30;//1000 / (runner.fps * 0.5); runner.fps = 1000 / runner.delta; return runner; @@ -6274,11 +6274,14 @@ var Common = _dereq_('./Common'); runner = Runner.create(); } + var count = 0; + (function run(time){ runner.frameRequestId = _requestAnimationFrame(run); - if (time && runner.enabled) { + if (time && runner.enabled && count < 100) { Runner.tick(runner, engine, time); + //count += 1; } })(); @@ -6316,6 +6319,8 @@ var Common = _dereq_('./Common'); delta = delta < runner.deltaMin ? runner.deltaMin : delta; delta = delta > runner.deltaMax ? runner.deltaMax : delta; + //console.log(delta) + // update engine timing object runner.delta = delta; } diff --git a/build/matter.min.js b/build/matter.min.js index 134e9a3..f0e49b1 100644 --- a/build/matter.min.js +++ b/build/matter.min.js @@ -25,35 +25,35 @@ var t,n,o=[];t=s.keys(e.pairs);for(var i=0;i0 }else!0===e.isActive&&o.setActive(e,!1,n)},o.setActive=function(e,t,n){t?(e.isActive=!0,e.timeUpdated=n):(e.isActive=!1,e.activeContacts.length=0)},o.id=function(e,t){return e.ido._pairMaxIdleLife&&c.push(s);for(s=0;sv.friction*v.frictionStatic*F*a&&(q=R*n,O=s.clamp(v.friction*E*a,-q,q));var W=r.cross(B,h),D=r.cross(M,h),U=S/(g.inverseMass+x.inverseMass+g.inverseInertia*W*W+x.inverseInertia*D*D);if(L*=U,O*=U,T<0&&T*T>o._restingThresh*i)A.normalImpulse=0;else{var N=A.normalImpulse;A.normalImpulse=Math.min(A.normalImpulse+L,0),L=A.normalImpulse-N}if(V*V>o._restingThreshTangent*i)A.tangentImpulse=0;else{var G=A.tangentImpulse;A.tangentImpulse=s.clamp(A.tangentImpulse+O,-q,q),O=A.tangentImpulse-G}l.x=h.x*L+b.x*O,l.y=h.y*L+b.y*O,g.isStatic||g.isSleeping||(g.positionPrev.x+=l.x*g.inverseMass,g.positionPrev.y+=l.y*g.inverseMass,g.anglePrev+=r.cross(B,l)*g.inverseInertia),x.isStatic||x.isSleeping||(x.positionPrev.x-=l.x*x.inverseMass,x.positionPrev.y-=l.y*x.inverseMass,x.anglePrev-=r.cross(M,l)*x.inverseInertia)}}}}}()},{"../core/Common":13,"../geometry/Bounds":25,"../geometry/Vector":27,"../geometry/Vertices":28}],10:[function(e,t,n){var o={};t.exports=o -;var i=e("../geometry/Vertices"),r=e("../geometry/Vector"),s=e("../core/Common");!function(){o._reuseMotionThresh=.2,o.collides=function(e,t,n,a){var l,c,u,d,p=!1,f=a/s._timeUnit;if(a=void 0!==a?a:0,n){var m=e.parent,v=t.parent,y=m.speed*m.speed+m.angularSpeed*m.angularSpeed+v.speed*v.speed+v.angularSpeed*v.angularSpeed;p=n&&n.collided&&yi?i=a:a=0?s.index-1:u.length-1],c.x=i.x-d.x,c.y=i.y-d.y,l=-r.dot(n,c),a=i,i=u[(s.index+1)%u.length],c.x=i.x-d.x,c.y=i.y-d.y,o=-r.dot(n,c),o0?1:.7),t.damping=t.damping||0,t.angularStiffness=t.angularStiffness||0,t.angleA=t.bodyA?t.bodyA.angle:t.angleA,t.angleB=t.bodyB?t.bodyB.angle:t.angleB,t.plugin={};var s={visible:!0,lineWidth:2,strokeStyle:"#ffffff",type:"line",anchors:!0};return 0===t.length&&t.stiffness>.1?(s.type="pin",s.anchors=!1):t.stiffness<.9&&(s.type="spring"),t.render=c.extend(s,t.render),t},o.preSolveAll=function(e){for(var t=0;t=1||0===e.length,h=x?e.stiffness:e.stiffness*t*t,b=e.damping*t,w=r.mult(u,g*h),S=(n?n.inverseMass:0)+(i?i.inverseMass:0),C=(n?n.inverseInertia:0)+(i?i.inverseInertia:0),A=S+C;if(b>0){var P=r.create();m=r.div(u,d),y=r.sub(i&&r.sub(i.position,i.positionPrev)||P,n&&r.sub(n.position,n.positionPrev)||P),v=r.dot(m,y)}n&&!n.isStatic&&(f=n.inverseMass/S,n.constraintImpulse.x-=w.x*f,n.constraintImpulse.y-=w.y*f,n.position.x-=w.x*f,n.position.y-=w.y*f,b>0&&(n.positionPrev.x-=b*m.x*v*f,n.positionPrev.y-=b*m.y*v*f),p=r.cross(s,w)/A*o._torqueDampen*n.inverseInertia*(1-e.angularStiffness), -n.constraintImpulse.angle-=p,n.angle-=p),i&&!i.isStatic&&(f=i.inverseMass/S,i.constraintImpulse.x+=w.x*f,i.constraintImpulse.y+=w.y*f,i.position.x+=w.x*f,i.position.y+=w.y*f,b>0&&(i.positionPrev.x+=b*m.x*v*f,i.positionPrev.y+=b*m.y*v*f),p=r.cross(a,w)/A*o._torqueDampen*i.inverseInertia*(1-e.angularStiffness),i.constraintImpulse.angle+=p,i.angle+=p)}}},o.postSolveAll=function(e){for(var t=0;t0&&(d.position.x+=c.x,d.position.y+=c.y),0!==c.angle&&(i.rotate(d.vertices,c.angle,n.position),l.rotate(d.axes,c.angle),u>0&&r.rotateAbout(d.position,c.angle,n.position,d.position)),a.update(d.bounds,d.vertices,n.velocity)}c.angle*=o._warming,c.x*=o._warming,c.y*=o._warming}}}}()},{"../core/Common":13,"../core/Sleeping":21,"../geometry/Axes":24,"../geometry/Bounds":25,"../geometry/Vector":27, -"../geometry/Vertices":28}],12:[function(e,t,n){var o={};t.exports=o;var i=e("../geometry/Vertices"),r=e("../core/Sleeping"),s=e("../core/Mouse"),a=e("../core/Events"),l=e("../collision/Detector"),c=e("./Constraint"),u=e("../body/Composite"),d=e("../core/Common"),p=e("../geometry/Bounds");!function(){o.create=function(e,t){var n=(e?e.mouse:null)||(t?t.mouse:null);n||(e&&e.render&&e.render.canvas?n=s.create(e.render.canvas):t&&t.element?n=s.create(t.element):(n=s.create(),d.warn("MouseConstraint.create: options.mouse was undefined, options.element was undefined, may not function as expected")));var i=c.create({label:"Mouse Constraint",pointA:n.position,pointB:{x:0,y:0},length:.01,stiffness:.1,angularStiffness:1,render:{strokeStyle:"#90EE90",lineWidth:3}}),r={type:"mouseConstraint",mouse:n,element:null,body:null,constraint:i,collisionFilter:{category:1,mask:4294967295,group:0}},l=d.extend(r,t);return a.on(e,"beforeUpdate",function(){var t=u.allBodies(e.world);o.update(l,t), -o._triggerEvents(l)}),l},o.update=function(e,t){var n=e.mouse,o=e.constraint,s=e.body;if(0===n.button){if(o.bodyB)r.set(o.bodyB,!1),o.pointA=n.position;else for(var c=0;c1?1:0;u0;t--){var n=Math.floor(o.random()*(t+1)),i=e[t];e[t]=e[n],e[n]=i}return e},o.choose=function(e){return e[Math.floor(o.random()*e.length)]},o.isElement=function(e){return"undefined"!=typeof HTMLElement?e instanceof HTMLElement:!!(e&&e.nodeType&&e.nodeName)},o.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},o.isFunction=function(e){return"function"==typeof e},o.isPlainObject=function(e){return"object"==typeof e&&e.constructor===Object},o.isString=function(e){return"[object String]"===toString.call(e)},o.clamp=function(e,t,n){return en?n:e},o.sign=function(e){return e<0?-1:1},o.now=function(){if(window.performance){if(window.performance.now)return window.performance.now();if(window.performance.webkitNow)return window.performance.webkitNow()}return new Date-o._nowStartTime},o.random=function(e,n){return e=void 0!==e?e:0,n=void 0!==n?n:1,e+t()*(n-e)};var t=function(){ -return o._seed=(9301*o._seed+49297)%233280,o._seed/233280};o.colorToNumber=function(e){return e=e.replace("#",""),3==e.length&&(e=e.charAt(0)+e.charAt(0)+e.charAt(1)+e.charAt(1)+e.charAt(2)+e.charAt(2)),parseInt(e,16)},o.logLevel=1,o.log=function(){console&&o.logLevel>0&&o.logLevel<=3&&console.log.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},o.info=function(){console&&o.logLevel>0&&o.logLevel<=2&&console.info.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},o.warn=function(){console&&o.logLevel>0&&o.logLevel<=3&&console.warn.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},o.nextId=function(){return o._nextId++},o.indexOf=function(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0;n0&&o._bodiesUpdate(y,t),p.preSolveAll(y),i=0;i0&&u.trigger(e,"collisionStart",{pairs:h.collisionStart}),s.preSolvePosition(h.list),i=0;i0&&u.trigger(e,"collisionActive",{pairs:h.collisionActive}),h.collisionEnd.length>0&&u.trigger(e,"collisionEnd",{pairs:h.collisionEnd}),o._bodiesClearForces(y),u.trigger(e,"afterUpdate",v),e},o.merge=function(e,t){if(f.extend(e,t),t.world){e.world=t.world,o.clear(e);for(var n=d.allBodies(e.world),i=0;i0){n||(n={}),o=t.split(" ");for(var c=0;cr?(i.warn("Plugin.register:",o.toString(t),"was upgraded to",o.toString(e)),o._registry[e.name]=e):n-1},o.isFor=function(e,t){var n=e.for&&o.dependencyParse(e.for);return!e.for||t.name===n.name&&o.versionSatisfies(t.version,n.range)},o.use=function(e,t){if(e.uses=(e.uses||[]).concat(t||[]), -0===e.uses.length)return void i.warn("Plugin.use:",o.toString(e),"does not specify any dependencies to install.");for(var n=o.dependencies(e),r=i.topologicalSort(n),s=[],a=0;a0&&i.info(s.join(" "))},o.dependencies=function(e,t){var n=o.dependencyParse(e),r=n.name;if(t=t||{},!(r in t)){e=o.resolve(e)||e,t[r]=i.map(e.uses||[],function(t){o.isPlugin(t)&&o.register(t);var r=o.dependencyParse(t),s=o.resolve(t) +n.collision.parentB.totalContacts+=o)},o.solvePosition=function(e,t,n){var i,r,a,l,c,u,d,p,f,m,v,y,g,x,h,b,w=n/s._timeUnit,S=s.clamp(o._positionDampen*w,0,1);for(i=0;iv.friction*v.frictionStatic*F*a&&(q=R*n,O=s.clamp(v.friction*E*a,-q,q));var W=r.cross(B,h),D=r.cross(M,h),U=S/(g.inverseMass+x.inverseMass+g.inverseInertia*W*W+x.inverseInertia*D*D);if(L*=U,O*=U,T<0&&T*T>o._restingThresh*i)A.normalImpulse=0;else{var N=A.normalImpulse;A.normalImpulse=Math.min(A.normalImpulse+L,0),L=A.normalImpulse-N}if(V*V>o._restingThreshTangent*i)A.tangentImpulse=0;else{var G=A.tangentImpulse;A.tangentImpulse=s.clamp(A.tangentImpulse+O,-q,q),O=A.tangentImpulse-G}l.x=h.x*L+b.x*O,l.y=h.y*L+b.y*O,g.isStatic||g.isSleeping||(g.positionPrev.x+=l.x*g.inverseMass,g.positionPrev.y+=l.y*g.inverseMass, +g.anglePrev+=r.cross(B,l)*g.inverseInertia),x.isStatic||x.isSleeping||(x.positionPrev.x-=l.x*x.inverseMass,x.positionPrev.y-=l.y*x.inverseMass,x.anglePrev-=r.cross(M,l)*x.inverseInertia)}}}}}()},{"../core/Common":13,"../geometry/Bounds":25,"../geometry/Vector":27,"../geometry/Vertices":28}],10:[function(e,t,n){var o={};t.exports=o;var i=e("../geometry/Vertices"),r=e("../geometry/Vector"),s=e("../core/Common");!function(){o._reuseMotionThresh=.2,o.collides=function(e,t,n,a){var l,c,u,d,p=!1,f=a/s._timeUnit;if(a=void 0!==a?a:0,n){var m=e.parent,v=t.parent,y=m.speed*m.speed+m.angularSpeed*m.angularSpeed+v.speed*v.speed+v.angularSpeed*v.angularSpeed;p=n&&n.collided&&yi?i=a:a=0?s.index-1:u.length-1],c.x=i.x-d.x,c.y=i.y-d.y,l=-r.dot(n,c),a=i,i=u[(s.index+1)%u.length],c.x=i.x-d.x,c.y=i.y-d.y,o=-r.dot(n,c),o0?1:.7),t.damping=t.damping||0,t.angularStiffness=t.angularStiffness||0,t.angleA=t.bodyA?t.bodyA.angle:t.angleA,t.angleB=t.bodyB?t.bodyB.angle:t.angleB,t.plugin={};var s={visible:!0,lineWidth:2,strokeStyle:"#ffffff",type:"line",anchors:!0};return 0===t.length&&t.stiffness>.1?(s.type="pin",s.anchors=!1):t.stiffness<.9&&(s.type="spring"),t.render=c.extend(s,t.render),t},o.preSolveAll=function(e){for(var t=0;t=1||0===e.length,h=x?e.stiffness:e.stiffness*t*t,b=e.damping*t,w=r.mult(u,g*h),S=(n?n.inverseMass:0)+(i?i.inverseMass:0),C=(n?n.inverseInertia:0)+(i?i.inverseInertia:0),A=S+C;if(b>0){var P=r.create();m=r.div(u,d), +y=r.sub(i&&r.sub(i.position,i.positionPrev)||P,n&&r.sub(n.position,n.positionPrev)||P),v=r.dot(m,y)}n&&!n.isStatic&&(f=n.inverseMass/S,n.constraintImpulse.x-=w.x*f,n.constraintImpulse.y-=w.y*f,n.position.x-=w.x*f,n.position.y-=w.y*f,b>0&&(n.positionPrev.x-=b*m.x*v*f,n.positionPrev.y-=b*m.y*v*f),p=r.cross(s,w)/A*o._torqueDampen*n.inverseInertia*(1-e.angularStiffness),n.constraintImpulse.angle-=p,n.angle-=p),i&&!i.isStatic&&(f=i.inverseMass/S,i.constraintImpulse.x+=w.x*f,i.constraintImpulse.y+=w.y*f,i.position.x+=w.x*f,i.position.y+=w.y*f,b>0&&(i.positionPrev.x+=b*m.x*v*f,i.positionPrev.y+=b*m.y*v*f),p=r.cross(a,w)/A*o._torqueDampen*i.inverseInertia*(1-e.angularStiffness),i.constraintImpulse.angle+=p,i.angle+=p)}}},o.postSolveAll=function(e){for(var t=0;t0&&(d.position.x+=c.x,d.position.y+=c.y), +0!==c.angle&&(i.rotate(d.vertices,c.angle,n.position),l.rotate(d.axes,c.angle),u>0&&r.rotateAbout(d.position,c.angle,n.position,d.position)),a.update(d.bounds,d.vertices,n.velocity)}c.angle*=o._warming,c.x*=o._warming,c.y*=o._warming}}}}()},{"../core/Common":13,"../core/Sleeping":21,"../geometry/Axes":24,"../geometry/Bounds":25,"../geometry/Vector":27,"../geometry/Vertices":28}],12:[function(e,t,n){var o={};t.exports=o;var i=e("../geometry/Vertices"),r=e("../core/Sleeping"),s=e("../core/Mouse"),a=e("../core/Events"),l=e("../collision/Detector"),c=e("./Constraint"),u=e("../body/Composite"),d=e("../core/Common"),p=e("../geometry/Bounds");!function(){o.create=function(e,t){var n=(e?e.mouse:null)||(t?t.mouse:null);n||(e&&e.render&&e.render.canvas?n=s.create(e.render.canvas):t&&t.element?n=s.create(t.element):(n=s.create(),d.warn("MouseConstraint.create: options.mouse was undefined, options.element was undefined, may not function as expected")));var i=c.create({label:"Mouse Constraint", +pointA:n.position,pointB:{x:0,y:0},length:.01,stiffness:.1,angularStiffness:1,render:{strokeStyle:"#90EE90",lineWidth:3}}),r={type:"mouseConstraint",mouse:n,element:null,body:null,constraint:i,collisionFilter:{category:1,mask:4294967295,group:0}},l=d.extend(r,t);return a.on(e,"beforeUpdate",function(){var t=u.allBodies(e.world);o.update(l,t),o._triggerEvents(l)}),l},o.update=function(e,t){var n=e.mouse,o=e.constraint,s=e.body;if(0===n.button){if(o.bodyB)r.set(o.bodyB,!1),o.pointA=n.position;else for(var c=0;c1?1:0;u0;t--){var n=Math.floor(o.random()*(t+1)),i=e[t];e[t]=e[n],e[n]=i}return e},o.choose=function(e){return e[Math.floor(o.random()*e.length)]},o.isElement=function(e){return"undefined"!=typeof HTMLElement?e instanceof HTMLElement:!!(e&&e.nodeType&&e.nodeName)},o.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)},o.isFunction=function(e){return"function"==typeof e},o.isPlainObject=function(e){return"object"==typeof e&&e.constructor===Object},o.isString=function(e){return"[object String]"===toString.call(e)},o.clamp=function(e,t,n){return en?n:e},o.sign=function(e){ +return e<0?-1:1},o.now=function(){if(window.performance){if(window.performance.now)return window.performance.now();if(window.performance.webkitNow)return window.performance.webkitNow()}return new Date-o._nowStartTime},o.random=function(e,n){return e=void 0!==e?e:0,n=void 0!==n?n:1,e+t()*(n-e)};var t=function(){return o._seed=(9301*o._seed+49297)%233280,o._seed/233280};o.colorToNumber=function(e){return e=e.replace("#",""),3==e.length&&(e=e.charAt(0)+e.charAt(0)+e.charAt(1)+e.charAt(1)+e.charAt(2)+e.charAt(2)),parseInt(e,16)},o.logLevel=1,o.log=function(){console&&o.logLevel>0&&o.logLevel<=3&&console.log.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},o.info=function(){console&&o.logLevel>0&&o.logLevel<=2&&console.info.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},o.warn=function(){console&&o.logLevel>0&&o.logLevel<=3&&console.warn.apply(console,["matter-js:"].concat(Array.prototype.slice.call(arguments)))},o.nextId=function(){ +return o._nextId++},o.indexOf=function(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0;n0&&o._bodiesUpdate(y,t),p.preSolveAll(y),i=0;i0&&u.trigger(e,"collisionStart",{pairs:h.collisionStart}),s.preSolvePosition(h.list),i=0;i0&&u.trigger(e,"collisionActive",{pairs:h.collisionActive}),h.collisionEnd.length>0&&u.trigger(e,"collisionEnd",{pairs:h.collisionEnd}),o._bodiesClearForces(y),u.trigger(e,"afterUpdate",v),e},o.merge=function(e,t){if(f.extend(e,t),t.world){e.world=t.world,o.clear(e);for(var n=d.allBodies(e.world),i=0;i0){n||(n={}),o=t.split(" ");for(var c=0;cr?(i.warn("Plugin.register:",o.toString(t),"was upgraded to",o.toString(e)),o._registry[e.name]=e):n-1},o.isFor=function(e,t){var n=e.for&&o.dependencyParse(e.for) +;return!e.for||t.name===n.name&&o.versionSatisfies(t.version,n.range)},o.use=function(e,t){if(e.uses=(e.uses||[]).concat(t||[]),0===e.uses.length)return void i.warn("Plugin.use:",o.toString(e),"does not specify any dependencies to install.");for(var n=o.dependencies(e),r=i.topologicalSort(n),s=[],a=0;a0&&i.info(s.join(" "))},o.dependencies=function(e,t){var n=o.dependencyParse(e),r=n.name;if(t=t||{},!(r in t)){e=o.resolve(e)||e,t[r]=i.map(e.uses||[],function(t){o.isPlugin(t)&&o.register(t);var r=o.dependencyParse(t),s=o.resolve(t) ;return s&&!o.versionSatisfies(s.version,r.range)?(i.warn("Plugin.dependencies:",o.toString(s),"does not satisfy",o.toString(r),"used by",o.toString(n)+"."),s._warned=!0,e._warned=!0):s||(i.warn("Plugin.dependencies:",o.toString(t),"used by",o.toString(n),"could not be resolved."),e._warned=!0),r.name});for(var s=0;s=i[2];if("^"===n.operator)return i[0]>0?s[0]===i[0]&&r.number>=n.number:i[1]>0?s[1]===i[1]&&s[2]>=i[2]:s[2]===i[2]}return e===t||"*"===e}}()},{"./Common":13}],20:[function(e,t,n){var o={};t.exports=o;var i=e("./Events"),r=e("./Engine"),s=e("./Common");!function(){var e,t;if("undefined"!=typeof window&&(e=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame,t=window.cancelAnimationFrame||window.mozCancelAnimationFrame||window.webkitCancelAnimationFrame||window.msCancelAnimationFrame),!e){var n;e=function(e){n=setTimeout(function(){e(s.now())},1e3/60)},t=function(){clearTimeout(n)}}o.create=function(e){var t={substeps:1,fps:60,deltaSampleSize:60, -counterTimestamp:0,frameCounter:0,deltaHistory:[],timePrev:null,frameRequestId:null,isFixed:!1,enabled:!0},n=s.extend(t,e);return n.delta=n.delta||1e3/n.fps,n.deltaMin=n.deltaMin||1e3/n.fps,n.deltaMax=n.deltaMax||1e3/(.5*n.fps),n.fps=1e3/n.delta,n},o.run=function(t,n){return void 0!==t.positionIterations&&(n=t,t=o.create()),function i(r){t.frameRequestId=e(i),r&&t.enabled&&o.tick(t,n,r)}(),t},o.tick=function(e,t,n){var o,s=t.timing;e.isFixed?o=e.delta:(o=n-e.timePrev||e.delta,e.timePrev=n,e.deltaHistory.push(o),e.deltaHistory=e.deltaHistory.slice(-e.deltaSampleSize),o=Math.min.apply(null,e.deltaHistory),o=oe.deltaMax?e.deltaMax:o,e.delta=o);var a={timestamp:s.timestamp};i.trigger(e,"beforeTick",a),i.trigger(t,"beforeTick",a),e.frameCounter+=1,n-e.counterTimestamp>=1e3&&(e.fps=e.frameCounter*((n-e.counterTimestamp)/1e3),e.counterTimestamp=n,e.frameCounter=0),i.trigger(e,"tick",a),i.trigger(t,"tick",a), +counterTimestamp:0,frameCounter:0,deltaHistory:[],timePrev:null,frameRequestId:null,isFixed:!1,enabled:!0},n=s.extend(t,e);return n.delta=n.delta||1e3/n.fps,n.deltaMin=n.deltaMin||1e3/60,n.deltaMax=n.deltaMax||1e3/30,n.fps=1e3/n.delta,n},o.run=function(t,n){void 0!==t.positionIterations&&(n=t,t=o.create());return function i(r){t.frameRequestId=e(i),r&&t.enabled&&o.tick(t,n,r)}(),t},o.tick=function(e,t,n){var o,s=t.timing;e.isFixed?o=e.delta:(o=n-e.timePrev||e.delta,e.timePrev=n,e.deltaHistory.push(o),e.deltaHistory=e.deltaHistory.slice(-e.deltaSampleSize),o=Math.min.apply(null,e.deltaHistory),o=oe.deltaMax?e.deltaMax:o,e.delta=o);var a={timestamp:s.timestamp};i.trigger(e,"beforeTick",a),i.trigger(t,"beforeTick",a),e.frameCounter+=1,n-e.counterTimestamp>=1e3&&(e.fps=e.frameCounter*((n-e.counterTimestamp)/1e3),e.counterTimestamp=n,e.frameCounter=0),i.trigger(e,"tick",a),i.trigger(t,"tick",a), t.world.isModified&&t.render&&t.render.controller&&t.render.controller.clear&&t.render.controller.clear(t.render),i.trigger(e,"beforeUpdate",a);for(var l=e.substeps,c=o/l,u=0;u0&&s.motion=s.sleepThreshold/n&&o.set(s,!0)):s.sleepCounter>0&&(s.sleepCounter-=1)}else o.set(s,!1)}},o.afterCollisions=function(e,t){for(var n=t/r._timeUnit,i=0;io._motionWakeThreshold*n*n&&o.set(u,!1)}}}},o.set=function(e,t){var n=e.isSleeping;t?(e.isSleeping=!0,e.sleepCounter=e.sleepThreshold,e.positionImpulse.x=0,e.positionImpulse.y=0,e.positionPrev.x=e.position.x,e.positionPrev.y=e.position.y,e.anglePrev=e.angle,e.speed=0,e.angularSpeed=0,e.motion=0,n||i.trigger(e,"sleepStart")):(e.isSleeping=!1,e.sleepCounter=0,n&&i.trigger(e,"sleepEnd"))}}()},{"./Common":13,"./Events":15}],22:[function(e,t,n){var o={};t.exports=o ;var i,r=e("../geometry/Vertices"),s=e("../core/Common"),a=e("../body/Body"),l=e("../geometry/Bounds"),c=e("../geometry/Vector");!function(){o.rectangle=function(e,t,n,o,i){i=i||{};var l={label:"Rectangle Body",position:{x:e,y:t},vertices:r.fromPath("L 0 0 L "+n+" 0 L "+n+" "+o+" L 0 "+o)};if(i.chamfer){var c=i.chamfer;l.vertices=r.chamfer(l.vertices,c.radius,c.quality,c.qualityMin,c.qualityMax),delete i.chamfer}return a.create(s.extend({},l,i))},o.trapezoid=function(e,t,n,o,i,l){l=l||{},i*=.5;var c,u=(1-2*i)*n,d=n*i,p=d+u,f=p+d;c=i<.5?"L 0 0 L "+d+" "+-o+" L "+p+" "+-o+" L "+f+" 0":"L 0 0 L "+p+" "+-o+" L "+f+" 0";var m={label:"Trapezoid Body",position:{x:e,y:t},vertices:r.fromPath(c)};if(l.chamfer){var v=l.chamfer;m.vertices=r.chamfer(m.vertices,v.radius,v.quality,v.qualityMin,v.qualityMax),delete l.chamfer}return a.create(s.extend({},m,l))},o.circle=function(e,t,n,i,r){i=i||{};var a={label:"Circle Body",circleRadius:n};r=r||25;var l=Math.ceil(Math.max(10,Math.min(r,n)))