mirror of
https://github.com/liabru/matter-js.git
synced 2024-11-27 09:50:52 -05:00
updated edge build
This commit is contained in:
parent
7c6cda00f8
commit
f5311a600c
2 changed files with 37 additions and 32 deletions
|
@ -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;
|
||||
}
|
||||
|
|
54
build/matter.min.js
vendored
54
build/matter.min.js
vendored
|
@ -25,35 +25,35 @@ var t,n,o=[];t=s.keys(e.pairs);for(var i=0;i<t.length;i++)n=e.pairs[t[i]],n[2]>0
|
|||
}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.id<t.id?"A"+e.id+"B"+t.id:"A"+t.id+"B"+e.id}}()},{}],7:[function(e,t,n){var o={};t.exports=o;var i=e("./Pair"),r=e("../core/Common");!function(){o._pairMaxIdleLife=1e3,o.create=function(e){return r.extend({table:{},list:[],collisionStart:[],collisionActive:[],collisionEnd:[]},e)},o.update=function(e,t,n){var o,r,s,a,l=e.list,c=e.table,u=e.collisionStart,d=e.collisionEnd,p=e.collisionActive;for(u.length=0,d.length=0,p.length=0,a=0;a<l.length;a++)l[a].confirmedActive=!1;for(a=0;a<t.length;a++)o=t[a],o.collided&&(r=i.id(o.bodyA,o.bodyB),s=c[r],s?(s.isActive?p.push(s):u.push(s),i.update(s,o,n),s.confirmedActive=!0):(s=i.create(o,n),c[r]=s,u.push(s),l.push(s)));for(a=0;a<l.length;a++)s=l[a],s.isActive&&!s.confirmedActive&&(i.setActive(s,!1,n),d.push(s))},o.removeOld=function(e,t){var n,i,r,s,a=e.list,l=e.table,c=[]
|
||||
;for(s=0;s<a.length;s++)n=a[s],i=n.collision,i.bodyA.isSleeping||i.bodyB.isSleeping?n.timeUpdated=t:t-n.timeUpdated>o._pairMaxIdleLife&&c.push(s);for(s=0;s<c.length;s++)r=c[s]-s,n=a[r],delete l[n.id],a.splice(r,1)},o.clear=function(e){return e.table={},e.list.length=0,e.collisionStart.length=0,e.collisionActive.length=0,e.collisionEnd.length=0,e}}()},{"../core/Common":13,"./Pair":6}],8:[function(e,t,n){var o={};t.exports=o;var i=e("../geometry/Vector"),r=e("./SAT"),s=e("../geometry/Bounds"),a=e("../factory/Bodies"),l=e("../geometry/Vertices");!function(){o.collides=function(e,t){for(var n=[],o=0;o<t.length;o++){var i=t[o];if(s.overlaps(i.bounds,e.bounds))for(var a=1===i.parts.length?0:1;a<i.parts.length;a++){var l=i.parts[a];if(s.overlaps(l.bounds,e.bounds)){var c=r.collides(l,e);if(c.collided){n.push(c);break}}}}return n},o.ray=function(e,t,n,r){r=r||1e-100;for(var s=i.angle(t,n),l=i.magnitude(i.sub(t,n)),c=.5*(n.x+t.x),u=.5*(n.y+t.y),d=a.rectangle(c,u,l,r,{angle:s
|
||||
}),p=o.collides(d,e),f=0;f<p.length;f+=1){var m=p[f];m.body=m.bodyB=m.bodyA}return p},o.region=function(e,t,n){for(var o=[],i=0;i<e.length;i++){var r=e[i],a=s.overlaps(r.bounds,t);(a&&!n||!a&&n)&&o.push(r)}return o},o.point=function(e,t){for(var n=[],o=0;o<e.length;o++){var i=e[o];if(s.contains(i.bounds,t))for(var r=1===i.parts.length?0:1;r<i.parts.length;r++){var a=i.parts[r];if(s.contains(a.bounds,t)&&l.contains(a.vertices,t)){n.push(i);break}}}return n}}()},{"../factory/Bodies":22,"../geometry/Bounds":25,"../geometry/Vector":27,"../geometry/Vertices":28,"./SAT":10}],9:[function(e,t,n){var o={};t.exports=o;var i=e("../geometry/Vertices"),r=e("../geometry/Vector"),s=e("../core/Common"),a=e("../geometry/Bounds");!function(){o._restingThresh=4,o._restingThreshTangent=6,o._positionDampen=.9,o._positionWarming=.8,o._frictionNormalMultiplier=5,o.preSolvePosition=function(e){var t,n,o;for(t=0;t<e.length;t++)n=e[t],n.isActive&&(o=n.activeContacts.length,n.collision.parentA.totalContacts+=o,
|
||||
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=o._positionDampen*w;for(i=0;i<t.length;i++){var C=t[i];C.previousPositionImpulse.x=C.positionImpulse.x,C.previousPositionImpulse.y=C.positionImpulse.y}for(i=0;i<e.length;i++)l=e[i],l.isActive&&!l.isSensor&&(c=l.collision,u=c.parentA,d=c.parentB,p=c.normal,v=u.previousPositionImpulse,y=d.previousPositionImpulse,m=c.penetration,x=y.x-v.x+m.x,h=y.y-v.y+m.y,r=p.x,a=p.y,f=r*x+a*h,l.separation=f,b=(f-l.slop)*S,(u.isStatic||d.isStatic)&&(b*=2),u.isStatic||u.isSleeping||(g=b/u.totalContacts,u.positionImpulse.x+=r*g,u.positionImpulse.y+=a*g),d.isStatic||d.isSleeping||(g=b/d.totalContacts,d.positionImpulse.x-=r*g,d.positionImpulse.y-=a*g))},o.postSolvePosition=function(e){for(var t=0;t<e.length;t++){var n=e[t];if(n.totalContacts=0,0!==n.positionImpulse.x||0!==n.positionImpulse.y){for(var s=0;s<n.parts.length;s++){var l=n.parts[s];i.translate(l.vertices,n.positionImpulse),
|
||||
a.update(l.bounds,l.vertices,n.velocity),l.position.x+=n.positionImpulse.x,l.position.y+=n.positionImpulse.y}n.positionPrev.x+=n.positionImpulse.x,n.positionPrev.y+=n.positionImpulse.y,r.dot(n.positionImpulse,n.velocity)<0?(n.positionImpulse.x=0,n.positionImpulse.y=0):(n.positionImpulse.x*=o._positionWarming,n.positionImpulse.y*=o._positionWarming)}}},o.preSolveVelocity=function(e){var t,n,o,i,s,a,l,c,u,d,p,f,m,v,y=r._temp[0],g=r._temp[1];for(t=0;t<e.length;t++)if(o=e[t],o.isActive&&!o.isSensor)for(i=o.activeContacts,s=o.collision,a=s.parentA,l=s.parentB,c=s.normal,u=s.tangent,n=0;n<i.length;n++)d=i[n],p=d.vertex,f=d.normalImpulse,m=d.tangentImpulse,0===f&&0===m||(y.x=c.x*f+u.x*m,y.y=c.y*f+u.y*m,a.isStatic||a.isSleeping||(v=r.sub(p,a.position,g),a.positionPrev.x+=y.x*a.inverseMass,a.positionPrev.y+=y.y*a.inverseMass,a.anglePrev+=r.cross(v,y)*a.inverseInertia),l.isStatic||l.isSleeping||(v=r.sub(p,l.position,g),l.positionPrev.x-=y.x*l.inverseMass,l.positionPrev.y-=y.y*l.inverseMass,
|
||||
l.anglePrev-=r.cross(v,y)*l.inverseInertia))},o.solveVelocity=function(e,t){for(var n=t/s._timeUnit,i=n*n,a=i*n,l=r._temp[0],c=r._temp[1],u=r._temp[2],d=r._temp[3],p=r._temp[4],f=r._temp[5],m=0;m<e.length;m++){var v=e[m];if(v.isActive&&!v.isSensor){var y=v.collision,g=y.parentA,x=y.parentB,h=y.normal,b=y.tangent,w=v.activeContacts,S=1/w.length;g.velocity.x=g.position.x-g.positionPrev.x,g.velocity.y=g.position.y-g.positionPrev.y,x.velocity.x=x.position.x-x.positionPrev.x,x.velocity.y=x.position.y-x.positionPrev.y,g.angularVelocity=g.angle-g.anglePrev,x.angularVelocity=x.angle-x.anglePrev;for(var C=0;C<w.length;C++){var A=w[C],P=A.vertex,B=r.sub(P,g.position,c),M=r.sub(P,x.position,u),k=r.add(g.velocity,r.mult(r.perp(B),g.angularVelocity),d),I=r.add(x.velocity,r.mult(r.perp(M),x.angularVelocity),p),_=r.sub(k,I,f),T=r.dot(h,_),V=r.dot(b,_),R=Math.abs(V),E=s.sign(V),L=(1+v.restitution)*T,F=s.clamp(v.separation+T,0,1)*o._frictionNormalMultiplier,O=V,q=1/0
|
||||
;R>v.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&&y<o._reuseMotionThresh*f*f,d=n}else d={collided:!1,bodyA:e,bodyB:t};if(n&&p){var g=d.axisBody,x=g===e?t:e,h=[g.axes[n.axisNumber]];if(u=o._overlapAxes(g.vertices,x.vertices,h),d.reused=!0,u.overlap<=0)return d.collided=!1,d}else{if(l=o._overlapAxes(e.vertices,t.vertices,e.axes),l.overlap<=0)return d.collided=!1,d;if(c=o._overlapAxes(t.vertices,e.vertices,t.axes),c.overlap<=0)return d.collided=!1,d;l.overlap<c.overlap?(u=l,d.axisBody=e):(u=c,d.axisBody=t),d.axisNumber=u.axisNumber}d.bodyA=e.id<t.id?e:t,d.bodyB=e.id<t.id?t:e,d.collided=!0,d.depth=u.overlap,d.parentA=d.bodyA.parent,d.parentB=d.bodyB.parent,e=d.bodyA,t=d.bodyB,
|
||||
r.dot(u.axis,r.sub(t.position,e.position))<0?d.normal={x:u.axis.x,y:u.axis.y}:d.normal={x:-u.axis.x,y:-u.axis.y},d.tangent=r.perp(d.normal),d.penetration=d.penetration||{},d.penetration.x=d.normal.x*d.depth,d.penetration.y=d.normal.y*d.depth;var b=o._findSupports(e,t,d.normal),w=[];if(i.contains(e.vertices,b[0])&&w.push(b[0]),i.contains(e.vertices,b[1])&&w.push(b[1]),w.length<2){var S=o._findSupports(t,e,r.neg(d.normal));i.contains(t.vertices,S[0])&&w.push(S[0]),w.length<2&&i.contains(t.vertices,S[1])&&w.push(S[1])}return w.length<1&&(w=[b[0]]),d.supports=w,d},o._overlapAxes=function(e,t,n){for(var i,s,a=r._temp[0],l=r._temp[1],c={overlap:Number.MAX_VALUE},u=0;u<n.length;u++){if(s=n[u],o._projectToAxis(a,e,s),o._projectToAxis(l,t,s),(i=Math.min(a.max-l.min,l.max-a.min))<=0)return c.overlap=i,c;i<c.overlap&&(c.overlap=i,c.axis=s,c.axisNumber=u)}return c},o._projectToAxis=function(e,t,n){for(var o=r.dot(t[0],n),i=o,s=1;s<t.length;s+=1){var a=r.dot(t[s],n);a>i?i=a:a<o&&(o=a)}e.min=o,
|
||||
e.max=i},o._findSupports=function(e,t,n){for(var o,i,s,a,l=Number.MAX_VALUE,c=r._temp[0],u=t.vertices,d=e.position,p=0;p<u.length;p++)i=u[p],c.x=i.x-d.x,c.y=i.y-d.y,(o=-r.dot(n,c))<l&&(l=o,s=i);return i=u[s.index-1>=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),o<l&&(a=i),[s,a]}}()},{"../core/Common":13,"../geometry/Vector":27,"../geometry/Vertices":28}],11:[function(e,t,n){var o={};t.exports=o;var i=e("../geometry/Vertices"),r=e("../geometry/Vector"),s=e("../core/Sleeping"),a=e("../geometry/Bounds"),l=e("../geometry/Axes"),c=e("../core/Common");!function(){o._warming=.4,o._torqueDampen=1,o._minLength=1e-6,o.create=function(e){var t=e;t.bodyA&&!t.pointA&&(t.pointA={x:0,y:0}),t.bodyB&&!t.pointB&&(t.pointB={x:0,y:0});var n=t.bodyA?r.add(t.bodyA.position,t.pointA):t.pointA,o=t.bodyB?r.add(t.bodyB.position,t.pointB):t.pointB,i=r.magnitude(r.sub(n,o));t.length=void 0!==t.length?t.length:i,
|
||||
t.id=t.id||c.nextId(),t.label=t.label||"Constraint",t.type="constraint",t.stiffness=t.stiffness||(t.length>0?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<e.length;t+=1){var n=e[t],o=n.constraintImpulse;n.isStatic||0===o.x&&0===o.y&&0===o.angle||(n.position.x+=o.x,n.position.y+=o.y,n.angle+=o.angle)}},o.solveAll=function(e,t){for(var n=c.clamp(t/c._timeUnit,0,1),i=0;i<e.length;i+=1){var r=e[i],s=!r.bodyA||r.bodyA&&r.bodyA.isStatic,a=!r.bodyB||r.bodyB&&r.bodyB.isStatic;(s||a)&&o.solve(e[i],n)}for(i=0;i<e.length;i+=1)r=e[i],s=!r.bodyA||r.bodyA&&r.bodyA.isStatic,a=!r.bodyB||r.bodyB&&r.bodyB.isStatic,s||a||o.solve(e[i],n)},
|
||||
o.solve=function(e,t){var n=e.bodyA,i=e.bodyB,s=e.pointA,a=e.pointB;if(n||i){n&&!n.isStatic&&(r.rotate(s,n.angle-e.angleA,s),e.angleA=n.angle),i&&!i.isStatic&&(r.rotate(a,i.angle-e.angleB,a),e.angleB=i.angle);var l=s,c=a;if(n&&(l=r.add(n.position,s)),i&&(c=r.add(i.position,a)),l&&c){var u=r.sub(l,c),d=r.magnitude(u);d<o._minLength&&(d=o._minLength);var p,f,m,v,y,g=(d-e.length)/d,x=e.stiffness>=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;t<e.length;t++){var n=e[t],c=n.constraintImpulse;if(!(n.isStatic||0===c.x&&0===c.y&&0===c.angle)){s.set(n,!1);for(var u=0;u<n.parts.length;u++){var d=n.parts[u];i.translate(d.vertices,c),u>0&&(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;c<t.length;c++)if(s=t[c],p.contains(s.bounds,n.position)&&l.canCollide(s.collisionFilter,e.collisionFilter))for(var u=s.parts.length>1?1:0;u<s.parts.length;u++){var d=s.parts[u];if(i.contains(d.vertices,n.position)){o.pointA=n.position,o.bodyB=e.body=s,o.pointB={x:n.position.x-s.position.x,y:n.position.y-s.position.y},o.angleB=s.angle,r.set(s,!1),a.trigger(e,"startdrag",{mouse:n,body:s});break}}}else o.bodyB=e.body=null,o.pointB=null,s&&a.trigger(e,"enddrag",{mouse:n,body:s})},o._triggerEvents=function(e){var t=e.mouse,n=t.sourceEvents;n.mousemove&&a.trigger(e,"mousemove",{mouse:t}),n.mousedown&&a.trigger(e,"mousedown",{mouse:t}),n.mouseup&&a.trigger(e,"mouseup",{mouse:t}),s.clearSourceEvents(t)}}()},{"../body/Composite":2,"../collision/Detector":4,"../core/Common":13,"../core/Events":15,"../core/Mouse":18,
|
||||
"../core/Sleeping":21,"../geometry/Bounds":25,"../geometry/Vertices":28,"./Constraint":11}],13:[function(e,t,n){(function(n){var o={};t.exports=o,function(){o._timeUnit=1e3/60,o._nextId=0,o._seed=0,o._nowStartTime=+new Date,o.extend=function(e,t){var n,i;"boolean"==typeof t?(n=2,i=t):(n=1,i=!0);for(var r=n;r<arguments.length;r++){var s=arguments[r];if(s)for(var a in s)i&&s[a]&&s[a].constructor===Object?e[a]&&e[a].constructor!==Object?e[a]=s[a]:(e[a]=e[a]||{},o.extend(e[a],i,s[a])):e[a]=s[a]}return e},o.clone=function(e,t){return o.extend({},t,e)},o.keys=function(e){if(Object.keys)return Object.keys(e);var t=[];for(var n in e)t.push(n);return t},o.values=function(e){var t=[];if(Object.keys){for(var n=Object.keys(e),o=0;o<n.length;o++)t.push(e[n[o]]);return t}for(var i in e)t.push(e[i]);return t},o.get=function(e,t,n,o){t=t.split(".").slice(n,o);for(var i=0;i<t.length;i+=1)e=e[t[i]];return e},o.set=function(e,t,n,i,r){var s=t.split(".").slice(i,r);return o.get(e,t,0,-1)[s[s.length-1]]=n,
|
||||
n},o.shuffle=function(e){for(var t=e.length-1;t>0;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 e<t?t:e>n?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;n<e.length;n++)if(e[n]===t)return n;return-1},o.map=function(e,t){if(e.map)return e.map(t);for(var n=[],o=0;o<e.length;o+=1)n.push(t(e[o]));return n},o.topologicalSort=function(e){var t=[],n=[],i=[]
|
||||
;for(var r in e)n[r]||i[r]||o._topologicalSort(r,n,i,e,t);return t},o._topologicalSort=function(e,t,n,i,r){var s=i[e]||[];n[e]=!0;for(var a=0;a<s.length;a+=1){var l=s[a];n[l]||(t[l]||o._topologicalSort(l,t,n,i,r))}n[e]=!1,t[e]=!0,r.push(e)},o.chain=function(){for(var e=[],t=0;t<arguments.length;t+=1){var n=arguments[t];n._chained?e.push.apply(e,n._chained):e.push(n)}var o=function(){for(var t,n=new Array(arguments.length),o=0,i=arguments.length;o<i;o++)n[o]=arguments[o];for(o=0;o<e.length;o+=1){var r=e[o].apply(t,n);void 0!==r&&(t=r)}return t};return o._chained=e,o},o.chainPathBefore=function(e,t,n){return o.set(e,t,o.chain(n,o.get(e,t)))},o.chainPathAfter=function(e,t,n){return o.set(e,t,o.chain(o.get(e,t),n))},o._requireGlobal=function(t,o){return("undefined"!=typeof window?window[t]:void 0!==n?n[t]:null)||e(o)}}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],14:[function(e,t,n){var o={};t.exports=o
|
||||
;var i=e("../body/World"),r=e("./Sleeping"),s=e("../collision/Resolver"),a=e("../render/Render"),l=e("../collision/Pairs"),c=(e("./Metrics"),e("../collision/Grid")),u=e("./Events"),d=e("../body/Composite"),p=e("../constraint/Constraint"),f=e("./Common"),m=e("../body/Body");!function(){o.create=function(e,t){t=f.isElement(e)?t:e,e=f.isElement(e)?e:null,t=t||{},(e||t.render)&&f.warn("Engine.create: engine.render is deprecated (see docs)");var n={positionIterations:6,velocityIterations:4,constraintIterations:2,enableSleeping:!1,events:[],plugin:{},timing:{timestamp:0,timeScale:1},broadphase:{controller:c}},o=f.extend(n,t);if(e||o.render){var r={element:e,controller:a};o.render=f.extend(r,o.render)}return o.render&&o.render.controller&&(o.render=o.render.controller.create(o.render)),o.render&&(o.render.engine=o),o.world=t.world||i.create(o.world),o.pairs=l.create(),o.broadphase=o.broadphase.controller.create(o.broadphase),o.metrics=o.metrics||{extended:!1},o},o.update=function(e,t){
|
||||
var n,i,a=e.world,c=e.timing,m=e.broadphase;t=void 0!==t?t:f._timeUnit,t*=c.timeScale,c.timestamp+=t;var v={timestamp:c.timestamp,delta:t};u.trigger(e,"beforeUpdate",v);var y=d.allBodies(a),g=d.allConstraints(a);for(e.enableSleeping&&r.update(y,t),o._bodiesApplyGravity(y,a.gravity),t>0&&o._bodiesUpdate(y,t),p.preSolveAll(y),i=0;i<e.constraintIterations;i++)p.solveAll(g,t);p.postSolveAll(y),m.controller?(a.isModified&&m.controller.clear(m),m.controller.update(m,y,e,a.isModified),n=m.pairsList):n=y,a.isModified&&d.setModified(a,!1,!1,!0);var x=m.detector(n,e,t),h=e.pairs,b=c.timestamp;for(l.update(h,x,b),l.removeOld(h,b),e.enableSleeping&&r.afterCollisions(h.list,t),h.collisionStart.length>0&&u.trigger(e,"collisionStart",{pairs:h.collisionStart}),s.preSolvePosition(h.list),i=0;i<e.positionIterations;i++)s.solvePosition(h.list,y,t);for(s.postSolvePosition(y),p.preSolveAll(y),i=0;i<e.constraintIterations;i++)p.solveAll(g,t);for(p.postSolveAll(y),s.preSolveVelocity(h.list),
|
||||
i=0;i<e.velocityIterations;i++)s.solveVelocity(h.list,t);return h.collisionActive.length>0&&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;i<n.length;i++){var s=n[i];r.set(s,!1),s.id=f.nextId()}}},o.clear=function(e){var t=e.world;l.clear(e.pairs);var n=e.broadphase;if(n.controller){var o=d.allBodies(t);n.controller.clear(n),n.controller.update(n,o,e,!0)}},o._bodiesClearForces=function(e){for(var t=0;t<e.length;t++){var n=e[t];n.force.x=0,n.force.y=0,n.torque=0}},o._bodiesApplyGravity=function(e,t){var n=void 0!==t.scale?t.scale:.001;if((0!==t.x||0!==t.y)&&0!==n)for(var o=0;o<e.length;o++){var i=e[o];i.isStatic||i.isSleeping||(i.force.y+=i.mass*t.y*n,i.force.x+=i.mass*t.x*n)}},o._bodiesUpdate=function(e,t){for(var n=0;n<e.length;n++){
|
||||
var o=e[n];o.isStatic||o.isSleeping||m.update(o,t)}}}()},{"../body/Body":1,"../body/Composite":2,"../body/World":3,"../collision/Grid":5,"../collision/Pairs":7,"../collision/Resolver":9,"../constraint/Constraint":11,"../render/Render":30,"./Common":13,"./Events":15,"./Metrics":17,"./Sleeping":21}],15:[function(e,t,n){var o={};t.exports=o;var i=e("./Common");!function(){o.on=function(e,t,n){for(var o,i=t.split(" "),r=0;r<i.length;r++)o=i[r],e.events=e.events||{},e.events[o]=e.events[o]||[],e.events[o].push(n);return n},o.off=function(e,t,n){if(!t)return void(e.events={});"function"==typeof t&&(n=t,t=i.keys(e.events).join(" "));for(var o=t.split(" "),r=0;r<o.length;r++){var s=e.events[o[r]],a=[];if(n&&s)for(var l=0;l<s.length;l++)s[l]!==n&&a.push(s[l]);e.events[o[r]]=a}},o.trigger=function(e,t,n){var o,r,s,a,l=e.events;if(l&&i.keys(l).length>0){n||(n={}),o=t.split(" ");for(var c=0;c<o.length;c++)if(r=o[c],s=l[r]){a=i.clone(n,!1),a.name=r,a.source=e
|
||||
;for(var u=0;u<s.length;u++)s[u].apply(e,[a])}}}}()},{"./Common":13}],16:[function(e,t,n){var o={};t.exports=o;var i=e("./Plugin"),r=e("./Common");!function(){o.name="matter-js",o.version="0.14.2-alpha",o.uses=[],o.used=[],o.use=function(){i.use(o,Array.prototype.slice.call(arguments))},o.before=function(e,t){return e=e.replace(/^Matter./,""),r.chainPathBefore(o,e,t)},o.after=function(e,t){return e=e.replace(/^Matter./,""),r.chainPathAfter(o,e,t)}}()},{"./Common":13,"./Plugin":19}],17:[function(e,t,n){},{"../body/Composite":2,"./Common":13}],18:[function(e,t,n){var o={};t.exports=o;var i=e("../core/Common");!function(){o.create=function(e){var t={};return e||i.log("Mouse.create: element was undefined, defaulting to document.body","warn"),t.element=e||document.body,t.absolute={x:0,y:0},t.position={x:0,y:0},t.mousedownPosition={x:0,y:0},t.mouseupPosition={x:0,y:0},t.offset={x:0,y:0},t.scale={x:1,y:1},t.wheelDelta=0,t.button=-1,
|
||||
t.pixelRatio=parseInt(t.element.getAttribute("data-pixel-ratio"),10)||1,t.sourceEvents={mousemove:null,mousedown:null,mouseup:null,mousewheel:null},t.mousemove=function(e){var n=o._getRelativeMousePosition(e,t.element,t.pixelRatio);e.changedTouches&&(t.button=0,e.preventDefault()),t.absolute.x=n.x,t.absolute.y=n.y,t.position.x=t.absolute.x*t.scale.x+t.offset.x,t.position.y=t.absolute.y*t.scale.y+t.offset.y,t.sourceEvents.mousemove=e},t.mousedown=function(e){var n=o._getRelativeMousePosition(e,t.element,t.pixelRatio);e.changedTouches?(t.button=0,e.preventDefault()):t.button=e.button,t.absolute.x=n.x,t.absolute.y=n.y,t.position.x=t.absolute.x*t.scale.x+t.offset.x,t.position.y=t.absolute.y*t.scale.y+t.offset.y,t.mousedownPosition.x=t.position.x,t.mousedownPosition.y=t.position.y,t.sourceEvents.mousedown=e},t.mouseup=function(e){var n=o._getRelativeMousePosition(e,t.element,t.pixelRatio);e.changedTouches&&e.preventDefault(),t.button=-1,t.absolute.x=n.x,t.absolute.y=n.y,
|
||||
t.position.x=t.absolute.x*t.scale.x+t.offset.x,t.position.y=t.absolute.y*t.scale.y+t.offset.y,t.mouseupPosition.x=t.position.x,t.mouseupPosition.y=t.position.y,t.sourceEvents.mouseup=e},t.mousewheel=function(e){t.wheelDelta=Math.max(-1,Math.min(1,e.wheelDelta||-e.detail)),e.preventDefault()},o.setElement(t,t.element),t},o.setElement=function(e,t){e.element=t,t.addEventListener("mousemove",e.mousemove),t.addEventListener("mousedown",e.mousedown),t.addEventListener("mouseup",e.mouseup),t.addEventListener("mousewheel",e.mousewheel),t.addEventListener("DOMMouseScroll",e.mousewheel),t.addEventListener("touchmove",e.mousemove),t.addEventListener("touchstart",e.mousedown),t.addEventListener("touchend",e.mouseup)},o.clearSourceEvents=function(e){e.sourceEvents.mousemove=null,e.sourceEvents.mousedown=null,e.sourceEvents.mouseup=null,e.sourceEvents.mousewheel=null,e.wheelDelta=0},o.setOffset=function(e,t){e.offset.x=t.x,e.offset.y=t.y,e.position.x=e.absolute.x*e.scale.x+e.offset.x,
|
||||
e.position.y=e.absolute.y*e.scale.y+e.offset.y},o.setScale=function(e,t){e.scale.x=t.x,e.scale.y=t.y,e.position.x=e.absolute.x*e.scale.x+e.offset.x,e.position.y=e.absolute.y*e.scale.y+e.offset.y},o._getRelativeMousePosition=function(e,t,n){var o,i,r=t.getBoundingClientRect(),s=document.documentElement||document.body.parentNode||document.body,a=void 0!==window.pageXOffset?window.pageXOffset:s.scrollLeft,l=void 0!==window.pageYOffset?window.pageYOffset:s.scrollTop,c=e.changedTouches;return c?(o=c[0].pageX-r.left-a,i=c[0].pageY-r.top-l):(o=e.pageX-r.left-a,i=e.pageY-r.top-l),{x:o/(t.clientWidth/(t.width||t.clientWidth)*n),y:i/(t.clientHeight/(t.height||t.clientHeight)*n)}}}()},{"../core/Common":13}],19:[function(e,t,n){var o={};t.exports=o;var i=e("./Common");!function(){o._registry={},o.register=function(e){if(o.isPlugin(e)||i.warn("Plugin.register:",o.toString(e),"does not implement all required fields."),e.name in o._registry){
|
||||
var t=o._registry[e.name],n=o.versionParse(e.version).number,r=o.versionParse(t.version).number;n>r?(i.warn("Plugin.register:",o.toString(t),"was upgraded to",o.toString(e)),o._registry[e.name]=e):n<r?i.warn("Plugin.register:",o.toString(t),"can not be downgraded to",o.toString(e)):e!==t&&i.warn("Plugin.register:",o.toString(e),"is already registered to different plugin object")}else o._registry[e.name]=e;return e},o.resolve=function(e){return o._registry[o.dependencyParse(e).name]},o.toString=function(e){return"string"==typeof e?e:(e.name||"anonymous")+"@"+(e.version||e.range||"0.0.0")},o.isPlugin=function(e){return e&&e.name&&e.version&&e.install},o.isUsed=function(e,t){return e.used.indexOf(t)>-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;a<r.length;a+=1)if(r[a]!==e.name){var l=o.resolve(r[a]);l?o.isUsed(e,l.name)||(o.isFor(l,e)||(i.warn("Plugin.use:",o.toString(l),"is for",l.for,"but installed on",o.toString(e)+"."),l._warned=!0),l.install?l.install(e):(i.warn("Plugin.use:",o.toString(l),"does not specify an install function."),l._warned=!0),l._warned?(s.push("🔶 "+o.toString(l)),delete l._warned):s.push("✅ "+o.toString(l)),e.used.push(l.name)):s.push("❌ "+r[a])}s.length>0&&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;i<t.length;i++){var C=t[i];C.previousPositionImpulse.x=C.positionImpulse.x,C.previousPositionImpulse.y=C.positionImpulse.y}for(i=0;i<e.length;i++)l=e[i],l.isActive&&!l.isSensor&&(c=l.collision,u=c.parentA,d=c.parentB,p=c.normal,v=u.previousPositionImpulse,y=d.previousPositionImpulse,m=c.penetration,x=y.x-v.x+m.x,h=y.y-v.y+m.y,r=p.x,a=p.y,f=r*x+a*h,l.separation=f,b=(f-l.slop)*S,(u.isStatic||d.isStatic)&&(b*=2),u.isStatic||u.isSleeping||(g=b/u.totalContacts,u.positionImpulse.x+=r*g,u.positionImpulse.y+=a*g),d.isStatic||d.isSleeping||(g=b/d.totalContacts,d.positionImpulse.x-=r*g,d.positionImpulse.y-=a*g))},o.postSolvePosition=function(e){for(var t=0;t<e.length;t++){var n=e[t];if(n.totalContacts=0,0!==n.positionImpulse.x||0!==n.positionImpulse.y){for(var s=0;s<n.parts.length;s++){var l=n.parts[s]
|
||||
;i.translate(l.vertices,n.positionImpulse),a.update(l.bounds,l.vertices,n.velocity),l.position.x+=n.positionImpulse.x,l.position.y+=n.positionImpulse.y}n.positionPrev.x+=n.positionImpulse.x,n.positionPrev.y+=n.positionImpulse.y,r.dot(n.positionImpulse,n.velocity)<0?(n.positionImpulse.x=0,n.positionImpulse.y=0):(n.positionImpulse.x*=o._positionWarming,n.positionImpulse.y*=o._positionWarming)}}},o.preSolveVelocity=function(e){var t,n,o,i,s,a,l,c,u,d,p,f,m,v,y=r._temp[0],g=r._temp[1];for(t=0;t<e.length;t++)if(o=e[t],o.isActive&&!o.isSensor)for(i=o.activeContacts,s=o.collision,a=s.parentA,l=s.parentB,c=s.normal,u=s.tangent,n=0;n<i.length;n++)d=i[n],p=d.vertex,f=d.normalImpulse,m=d.tangentImpulse,0===f&&0===m||(y.x=c.x*f+u.x*m,y.y=c.y*f+u.y*m,a.isStatic||a.isSleeping||(v=r.sub(p,a.position,g),a.positionPrev.x+=y.x*a.inverseMass,a.positionPrev.y+=y.y*a.inverseMass,a.anglePrev+=r.cross(v,y)*a.inverseInertia),l.isStatic||l.isSleeping||(v=r.sub(p,l.position,g),
|
||||
l.positionPrev.x-=y.x*l.inverseMass,l.positionPrev.y-=y.y*l.inverseMass,l.anglePrev-=r.cross(v,y)*l.inverseInertia))},o.solveVelocity=function(e,t){for(var n=t/s._timeUnit,i=n*n,a=i*n,l=r._temp[0],c=r._temp[1],u=r._temp[2],d=r._temp[3],p=r._temp[4],f=r._temp[5],m=0;m<e.length;m++){var v=e[m];if(v.isActive&&!v.isSensor){var y=v.collision,g=y.parentA,x=y.parentB,h=y.normal,b=y.tangent,w=v.activeContacts,S=1/w.length;g.velocity.x=g.position.x-g.positionPrev.x,g.velocity.y=g.position.y-g.positionPrev.y,x.velocity.x=x.position.x-x.positionPrev.x,x.velocity.y=x.position.y-x.positionPrev.y,g.angularVelocity=g.angle-g.anglePrev,x.angularVelocity=x.angle-x.anglePrev;for(var C=0;C<w.length;C++){
|
||||
var A=w[C],P=A.vertex,B=r.sub(P,g.position,c),M=r.sub(P,x.position,u),k=r.add(g.velocity,r.mult(r.perp(B),g.angularVelocity),d),I=r.add(x.velocity,r.mult(r.perp(M),x.angularVelocity),p),_=r.sub(k,I,f),T=r.dot(h,_),V=r.dot(b,_),R=Math.abs(V),E=s.sign(V),L=(1+v.restitution)*T,F=s.clamp(v.separation+T,0,1)*o._frictionNormalMultiplier,O=V,q=1/0;R>v.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&&y<o._reuseMotionThresh*f*f,d=n}else d={collided:!1,bodyA:e,bodyB:t};if(n&&p){var g=d.axisBody,x=g===e?t:e,h=[g.axes[n.axisNumber]];if(u=o._overlapAxes(g.vertices,x.vertices,h),d.reused=!0,u.overlap<=0)return d.collided=!1,d}else{if(l=o._overlapAxes(e.vertices,t.vertices,e.axes),l.overlap<=0)return d.collided=!1,d
|
||||
;if(c=o._overlapAxes(t.vertices,e.vertices,t.axes),c.overlap<=0)return d.collided=!1,d;l.overlap<c.overlap?(u=l,d.axisBody=e):(u=c,d.axisBody=t),d.axisNumber=u.axisNumber}d.bodyA=e.id<t.id?e:t,d.bodyB=e.id<t.id?t:e,d.collided=!0,d.depth=u.overlap,d.parentA=d.bodyA.parent,d.parentB=d.bodyB.parent,e=d.bodyA,t=d.bodyB,r.dot(u.axis,r.sub(t.position,e.position))<0?d.normal={x:u.axis.x,y:u.axis.y}:d.normal={x:-u.axis.x,y:-u.axis.y},d.tangent=r.perp(d.normal),d.penetration=d.penetration||{},d.penetration.x=d.normal.x*d.depth,d.penetration.y=d.normal.y*d.depth;var b=o._findSupports(e,t,d.normal),w=[];if(i.contains(e.vertices,b[0])&&w.push(b[0]),i.contains(e.vertices,b[1])&&w.push(b[1]),w.length<2){var S=o._findSupports(t,e,r.neg(d.normal));i.contains(t.vertices,S[0])&&w.push(S[0]),w.length<2&&i.contains(t.vertices,S[1])&&w.push(S[1])}return w.length<1&&(w=[b[0]]),d.supports=w,d},o._overlapAxes=function(e,t,n){for(var i,s,a=r._temp[0],l=r._temp[1],c={overlap:Number.MAX_VALUE
|
||||
},u=0;u<n.length;u++){if(s=n[u],o._projectToAxis(a,e,s),o._projectToAxis(l,t,s),(i=Math.min(a.max-l.min,l.max-a.min))<=0)return c.overlap=i,c;i<c.overlap&&(c.overlap=i,c.axis=s,c.axisNumber=u)}return c},o._projectToAxis=function(e,t,n){for(var o=r.dot(t[0],n),i=o,s=1;s<t.length;s+=1){var a=r.dot(t[s],n);a>i?i=a:a<o&&(o=a)}e.min=o,e.max=i},o._findSupports=function(e,t,n){for(var o,i,s,a,l=Number.MAX_VALUE,c=r._temp[0],u=t.vertices,d=e.position,p=0;p<u.length;p++)i=u[p],c.x=i.x-d.x,c.y=i.y-d.y,(o=-r.dot(n,c))<l&&(l=o,s=i);return i=u[s.index-1>=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),o<l&&(a=i),[s,a]}}()},{"../core/Common":13,"../geometry/Vector":27,"../geometry/Vertices":28}],11:[function(e,t,n){var o={};t.exports=o;var i=e("../geometry/Vertices"),r=e("../geometry/Vector"),s=e("../core/Sleeping"),a=e("../geometry/Bounds"),l=e("../geometry/Axes"),c=e("../core/Common");!function(){o._warming=.4,
|
||||
o._torqueDampen=1,o._minLength=1e-6,o.create=function(e){var t=e;t.bodyA&&!t.pointA&&(t.pointA={x:0,y:0}),t.bodyB&&!t.pointB&&(t.pointB={x:0,y:0});var n=t.bodyA?r.add(t.bodyA.position,t.pointA):t.pointA,o=t.bodyB?r.add(t.bodyB.position,t.pointB):t.pointB,i=r.magnitude(r.sub(n,o));t.length=void 0!==t.length?t.length:i,t.id=t.id||c.nextId(),t.label=t.label||"Constraint",t.type="constraint",t.stiffness=t.stiffness||(t.length>0?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<e.length;t+=1){var n=e[t],o=n.constraintImpulse;n.isStatic||0===o.x&&0===o.y&&0===o.angle||(n.position.x+=o.x,n.position.y+=o.y,n.angle+=o.angle)}},
|
||||
o.solveAll=function(e,t){for(var n=c.clamp(t/c._timeUnit,0,1),i=0;i<e.length;i+=1){var r=e[i],s=!r.bodyA||r.bodyA&&r.bodyA.isStatic,a=!r.bodyB||r.bodyB&&r.bodyB.isStatic;(s||a)&&o.solve(e[i],n)}for(i=0;i<e.length;i+=1)r=e[i],s=!r.bodyA||r.bodyA&&r.bodyA.isStatic,a=!r.bodyB||r.bodyB&&r.bodyB.isStatic,s||a||o.solve(e[i],n)},o.solve=function(e,t){var n=e.bodyA,i=e.bodyB,s=e.pointA,a=e.pointB;if(n||i){n&&!n.isStatic&&(r.rotate(s,n.angle-e.angleA,s),e.angleA=n.angle),i&&!i.isStatic&&(r.rotate(a,i.angle-e.angleB,a),e.angleB=i.angle);var l=s,c=a;if(n&&(l=r.add(n.position,s)),i&&(c=r.add(i.position,a)),l&&c){var u=r.sub(l,c),d=r.magnitude(u);d<o._minLength&&(d=o._minLength);var p,f,m,v,y,g=(d-e.length)/d,x=e.stiffness>=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;t<e.length;t++){var n=e[t],c=n.constraintImpulse;if(!(n.isStatic||0===c.x&&0===c.y&&0===c.angle)){s.set(n,!1);for(var u=0;u<n.parts.length;u++){var d=n.parts[u];i.translate(d.vertices,c),u>0&&(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;c<t.length;c++)if(s=t[c],p.contains(s.bounds,n.position)&&l.canCollide(s.collisionFilter,e.collisionFilter))for(var u=s.parts.length>1?1:0;u<s.parts.length;u++){var d=s.parts[u];if(i.contains(d.vertices,n.position)){o.pointA=n.position,o.bodyB=e.body=s,o.pointB={x:n.position.x-s.position.x,y:n.position.y-s.position.y},o.angleB=s.angle,r.set(s,!1),a.trigger(e,"startdrag",{mouse:n,body:s});break}}}else o.bodyB=e.body=null,o.pointB=null,s&&a.trigger(e,"enddrag",{mouse:n,body:s})},
|
||||
o._triggerEvents=function(e){var t=e.mouse,n=t.sourceEvents;n.mousemove&&a.trigger(e,"mousemove",{mouse:t}),n.mousedown&&a.trigger(e,"mousedown",{mouse:t}),n.mouseup&&a.trigger(e,"mouseup",{mouse:t}),s.clearSourceEvents(t)}}()},{"../body/Composite":2,"../collision/Detector":4,"../core/Common":13,"../core/Events":15,"../core/Mouse":18,"../core/Sleeping":21,"../geometry/Bounds":25,"../geometry/Vertices":28,"./Constraint":11}],13:[function(e,t,n){(function(n){var o={};t.exports=o,function(){o._timeUnit=1e3/60,o._nextId=0,o._seed=0,o._nowStartTime=+new Date,o.extend=function(e,t){var n,i;"boolean"==typeof t?(n=2,i=t):(n=1,i=!0);for(var r=n;r<arguments.length;r++){var s=arguments[r];if(s)for(var a in s)i&&s[a]&&s[a].constructor===Object?e[a]&&e[a].constructor!==Object?e[a]=s[a]:(e[a]=e[a]||{},o.extend(e[a],i,s[a])):e[a]=s[a]}return e},o.clone=function(e,t){return o.extend({},t,e)},o.keys=function(e){if(Object.keys)return Object.keys(e);var t=[];for(var n in e)t.push(n);return t},
|
||||
o.values=function(e){var t=[];if(Object.keys){for(var n=Object.keys(e),o=0;o<n.length;o++)t.push(e[n[o]]);return t}for(var i in e)t.push(e[i]);return t},o.get=function(e,t,n,o){t=t.split(".").slice(n,o);for(var i=0;i<t.length;i+=1)e=e[t[i]];return e},o.set=function(e,t,n,i,r){var s=t.split(".").slice(i,r);return o.get(e,t,0,-1)[s[s.length-1]]=n,n},o.shuffle=function(e){for(var t=e.length-1;t>0;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 e<t?t:e>n?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;n<e.length;n++)if(e[n]===t)return n;return-1},o.map=function(e,t){if(e.map)return e.map(t);for(var n=[],o=0;o<e.length;o+=1)n.push(t(e[o]));return n},o.topologicalSort=function(e){var t=[],n=[],i=[];for(var r in e)n[r]||i[r]||o._topologicalSort(r,n,i,e,t);return t},o._topologicalSort=function(e,t,n,i,r){var s=i[e]||[];n[e]=!0;for(var a=0;a<s.length;a+=1){var l=s[a];n[l]||(t[l]||o._topologicalSort(l,t,n,i,r))}n[e]=!1,t[e]=!0,r.push(e)},o.chain=function(){for(var e=[],t=0;t<arguments.length;t+=1){var n=arguments[t];n._chained?e.push.apply(e,n._chained):e.push(n)}var o=function(){for(var t,n=new Array(arguments.length),o=0,i=arguments.length;o<i;o++)n[o]=arguments[o];for(o=0;o<e.length;o+=1){var r=e[o].apply(t,n);void 0!==r&&(t=r)}return t};return o._chained=e,o},o.chainPathBefore=function(e,t,n){return o.set(e,t,o.chain(n,o.get(e,t)))},o.chainPathAfter=function(e,t,n){
|
||||
return o.set(e,t,o.chain(o.get(e,t),n))},o._requireGlobal=function(t,o){return("undefined"!=typeof window?window[t]:void 0!==n?n[t]:null)||e(o)}}()}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],14:[function(e,t,n){var o={};t.exports=o;var i=e("../body/World"),r=e("./Sleeping"),s=e("../collision/Resolver"),a=e("../render/Render"),l=e("../collision/Pairs"),c=(e("./Metrics"),e("../collision/Grid")),u=e("./Events"),d=e("../body/Composite"),p=e("../constraint/Constraint"),f=e("./Common"),m=e("../body/Body");!function(){o.create=function(e,t){t=f.isElement(e)?t:e,e=f.isElement(e)?e:null,t=t||{},(e||t.render)&&f.warn("Engine.create: engine.render is deprecated (see docs)");var n={positionIterations:6,velocityIterations:4,constraintIterations:2,enableSleeping:!1,events:[],plugin:{},timing:{timestamp:0,timeScale:1},broadphase:{controller:c}},o=f.extend(n,t);if(e||o.render){var r={element:e,controller:a}
|
||||
;o.render=f.extend(r,o.render)}return o.render&&o.render.controller&&(o.render=o.render.controller.create(o.render)),o.render&&(o.render.engine=o),o.world=t.world||i.create(o.world),o.pairs=l.create(),o.broadphase=o.broadphase.controller.create(o.broadphase),o.metrics=o.metrics||{extended:!1},o},o.update=function(e,t){var n,i,a=e.world,c=e.timing,m=e.broadphase;t=void 0!==t?t:f._timeUnit,t*=c.timeScale,c.timestamp+=t;var v={timestamp:c.timestamp,delta:t};u.trigger(e,"beforeUpdate",v);var y=d.allBodies(a),g=d.allConstraints(a);for(e.enableSleeping&&r.update(y,t),o._bodiesApplyGravity(y,a.gravity),t>0&&o._bodiesUpdate(y,t),p.preSolveAll(y),i=0;i<e.constraintIterations;i++)p.solveAll(g,t);p.postSolveAll(y),m.controller?(a.isModified&&m.controller.clear(m),m.controller.update(m,y,e,a.isModified),n=m.pairsList):n=y,a.isModified&&d.setModified(a,!1,!1,!0);var x=m.detector(n,e,t),h=e.pairs,b=c.timestamp;for(l.update(h,x,b),l.removeOld(h,b),e.enableSleeping&&r.afterCollisions(h.list,t),
|
||||
h.collisionStart.length>0&&u.trigger(e,"collisionStart",{pairs:h.collisionStart}),s.preSolvePosition(h.list),i=0;i<e.positionIterations;i++)s.solvePosition(h.list,y,t);for(s.postSolvePosition(y),p.preSolveAll(y),i=0;i<e.constraintIterations;i++)p.solveAll(g,t);for(p.postSolveAll(y),s.preSolveVelocity(h.list),i=0;i<e.velocityIterations;i++)s.solveVelocity(h.list,t);return h.collisionActive.length>0&&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;i<n.length;i++){var s=n[i];r.set(s,!1),s.id=f.nextId()}}},o.clear=function(e){var t=e.world;l.clear(e.pairs);var n=e.broadphase;if(n.controller){var o=d.allBodies(t);n.controller.clear(n),n.controller.update(n,o,e,!0)}},o._bodiesClearForces=function(e){for(var t=0;t<e.length;t++){var n=e[t]
|
||||
;n.force.x=0,n.force.y=0,n.torque=0}},o._bodiesApplyGravity=function(e,t){var n=void 0!==t.scale?t.scale:.001;if((0!==t.x||0!==t.y)&&0!==n)for(var o=0;o<e.length;o++){var i=e[o];i.isStatic||i.isSleeping||(i.force.y+=i.mass*t.y*n,i.force.x+=i.mass*t.x*n)}},o._bodiesUpdate=function(e,t){for(var n=0;n<e.length;n++){var o=e[n];o.isStatic||o.isSleeping||m.update(o,t)}}}()},{"../body/Body":1,"../body/Composite":2,"../body/World":3,"../collision/Grid":5,"../collision/Pairs":7,"../collision/Resolver":9,"../constraint/Constraint":11,"../render/Render":30,"./Common":13,"./Events":15,"./Metrics":17,"./Sleeping":21}],15:[function(e,t,n){var o={};t.exports=o;var i=e("./Common");!function(){o.on=function(e,t,n){for(var o,i=t.split(" "),r=0;r<i.length;r++)o=i[r],e.events=e.events||{},e.events[o]=e.events[o]||[],e.events[o].push(n);return n},o.off=function(e,t,n){if(!t)return void(e.events={});"function"==typeof t&&(n=t,t=i.keys(e.events).join(" "));for(var o=t.split(" "),r=0;r<o.length;r++){
|
||||
var s=e.events[o[r]],a=[];if(n&&s)for(var l=0;l<s.length;l++)s[l]!==n&&a.push(s[l]);e.events[o[r]]=a}},o.trigger=function(e,t,n){var o,r,s,a,l=e.events;if(l&&i.keys(l).length>0){n||(n={}),o=t.split(" ");for(var c=0;c<o.length;c++)if(r=o[c],s=l[r]){a=i.clone(n,!1),a.name=r,a.source=e;for(var u=0;u<s.length;u++)s[u].apply(e,[a])}}}}()},{"./Common":13}],16:[function(e,t,n){var o={};t.exports=o;var i=e("./Plugin"),r=e("./Common");!function(){o.name="matter-js",o.version="0.14.2-alpha",o.uses=[],o.used=[],o.use=function(){i.use(o,Array.prototype.slice.call(arguments))},o.before=function(e,t){return e=e.replace(/^Matter./,""),r.chainPathBefore(o,e,t)},o.after=function(e,t){return e=e.replace(/^Matter./,""),r.chainPathAfter(o,e,t)}}()},{"./Common":13,"./Plugin":19}],17:[function(e,t,n){},{"../body/Composite":2,"./Common":13}],18:[function(e,t,n){var o={};t.exports=o;var i=e("../core/Common");!function(){o.create=function(e){var t={}
|
||||
;return e||i.log("Mouse.create: element was undefined, defaulting to document.body","warn"),t.element=e||document.body,t.absolute={x:0,y:0},t.position={x:0,y:0},t.mousedownPosition={x:0,y:0},t.mouseupPosition={x:0,y:0},t.offset={x:0,y:0},t.scale={x:1,y:1},t.wheelDelta=0,t.button=-1,t.pixelRatio=parseInt(t.element.getAttribute("data-pixel-ratio"),10)||1,t.sourceEvents={mousemove:null,mousedown:null,mouseup:null,mousewheel:null},t.mousemove=function(e){var n=o._getRelativeMousePosition(e,t.element,t.pixelRatio);e.changedTouches&&(t.button=0,e.preventDefault()),t.absolute.x=n.x,t.absolute.y=n.y,t.position.x=t.absolute.x*t.scale.x+t.offset.x,t.position.y=t.absolute.y*t.scale.y+t.offset.y,t.sourceEvents.mousemove=e},t.mousedown=function(e){var n=o._getRelativeMousePosition(e,t.element,t.pixelRatio);e.changedTouches?(t.button=0,e.preventDefault()):t.button=e.button,t.absolute.x=n.x,t.absolute.y=n.y,t.position.x=t.absolute.x*t.scale.x+t.offset.x,t.position.y=t.absolute.y*t.scale.y+t.offset.y,
|
||||
t.mousedownPosition.x=t.position.x,t.mousedownPosition.y=t.position.y,t.sourceEvents.mousedown=e},t.mouseup=function(e){var n=o._getRelativeMousePosition(e,t.element,t.pixelRatio);e.changedTouches&&e.preventDefault(),t.button=-1,t.absolute.x=n.x,t.absolute.y=n.y,t.position.x=t.absolute.x*t.scale.x+t.offset.x,t.position.y=t.absolute.y*t.scale.y+t.offset.y,t.mouseupPosition.x=t.position.x,t.mouseupPosition.y=t.position.y,t.sourceEvents.mouseup=e},t.mousewheel=function(e){t.wheelDelta=Math.max(-1,Math.min(1,e.wheelDelta||-e.detail)),e.preventDefault()},o.setElement(t,t.element),t},o.setElement=function(e,t){e.element=t,t.addEventListener("mousemove",e.mousemove),t.addEventListener("mousedown",e.mousedown),t.addEventListener("mouseup",e.mouseup),t.addEventListener("mousewheel",e.mousewheel),t.addEventListener("DOMMouseScroll",e.mousewheel),t.addEventListener("touchmove",e.mousemove),t.addEventListener("touchstart",e.mousedown),t.addEventListener("touchend",e.mouseup)},
|
||||
o.clearSourceEvents=function(e){e.sourceEvents.mousemove=null,e.sourceEvents.mousedown=null,e.sourceEvents.mouseup=null,e.sourceEvents.mousewheel=null,e.wheelDelta=0},o.setOffset=function(e,t){e.offset.x=t.x,e.offset.y=t.y,e.position.x=e.absolute.x*e.scale.x+e.offset.x,e.position.y=e.absolute.y*e.scale.y+e.offset.y},o.setScale=function(e,t){e.scale.x=t.x,e.scale.y=t.y,e.position.x=e.absolute.x*e.scale.x+e.offset.x,e.position.y=e.absolute.y*e.scale.y+e.offset.y},o._getRelativeMousePosition=function(e,t,n){var o,i,r=t.getBoundingClientRect(),s=document.documentElement||document.body.parentNode||document.body,a=void 0!==window.pageXOffset?window.pageXOffset:s.scrollLeft,l=void 0!==window.pageYOffset?window.pageYOffset:s.scrollTop,c=e.changedTouches;return c?(o=c[0].pageX-r.left-a,i=c[0].pageY-r.top-l):(o=e.pageX-r.left-a,i=e.pageY-r.top-l),{x:o/(t.clientWidth/(t.width||t.clientWidth)*n),y:i/(t.clientHeight/(t.height||t.clientHeight)*n)}}}()},{"../core/Common":13}],19:[function(e,t,n){
|
||||
var o={};t.exports=o;var i=e("./Common");!function(){o._registry={},o.register=function(e){if(o.isPlugin(e)||i.warn("Plugin.register:",o.toString(e),"does not implement all required fields."),e.name in o._registry){var t=o._registry[e.name],n=o.versionParse(e.version).number,r=o.versionParse(t.version).number;n>r?(i.warn("Plugin.register:",o.toString(t),"was upgraded to",o.toString(e)),o._registry[e.name]=e):n<r?i.warn("Plugin.register:",o.toString(t),"can not be downgraded to",o.toString(e)):e!==t&&i.warn("Plugin.register:",o.toString(e),"is already registered to different plugin object")}else o._registry[e.name]=e;return e},o.resolve=function(e){return o._registry[o.dependencyParse(e).name]},o.toString=function(e){return"string"==typeof e?e:(e.name||"anonymous")+"@"+(e.version||e.range||"0.0.0")},o.isPlugin=function(e){return e&&e.name&&e.version&&e.install},o.isUsed=function(e,t){return e.used.indexOf(t)>-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;a<r.length;a+=1)if(r[a]!==e.name){var l=o.resolve(r[a]);l?o.isUsed(e,l.name)||(o.isFor(l,e)||(i.warn("Plugin.use:",o.toString(l),"is for",l.for,"but installed on",o.toString(e)+"."),l._warned=!0),l.install?l.install(e):(i.warn("Plugin.use:",o.toString(l),"does not specify an install function."),l._warned=!0),l._warned?(s.push("🔶 "+o.toString(l)),delete l._warned):s.push("✅ "+o.toString(l)),e.used.push(l.name)):s.push("❌ "+r[a])}s.length>0&&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<t[r].length;s+=1)o.dependencies(t[r][s],t);return t}},o.dependencyParse=function(e){if(i.isString(e)){return/^[\w-]+(@(\*|[\^~]?\d+\.\d+\.\d+(-[0-9A-Za-z-]+)?))?$/.test(e)||i.warn("Plugin.dependencyParse:",e,"is not a valid dependency string."),{name:e.split("@")[0],range:e.split("@")[1]||"*"}}return{name:e.name,range:e.range||e.version}},o.versionParse=function(e){/^\*|[\^~]?\d+\.\d+\.\d+(-[0-9A-Za-z-]+)?$/.test(e)||i.warn("Plugin.versionParse:",e,"is not a valid version or range.");var t=e.split("-");e=t[0];var n=isNaN(Number(e[0])),o=n?e.substr(1):e,r=i.map(o.split("."),function(e){return Number(e)});return{isRange:n,version:o,range:e,operator:n?e[0]:"",parts:r,
|
||||
prerelease:t[1],number:1e8*r[0]+1e4*r[1]+r[2]}},o.versionSatisfies=function(e,t){t=t||"*";var n=o.versionParse(t),i=n.parts,r=o.versionParse(e),s=r.parts;if(n.isRange){if("*"===n.operator||"*"===e)return!0;if("~"===n.operator)return s[0]===i[0]&&s[1]===i[1]&&s[2]>=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=o<e.deltaMin?e.deltaMin:o,o=o>e.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=o<e.deltaMin?e.deltaMin:o,o=o>e.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;u<l;u+=1)r.update(t,c);i.trigger(e,"afterUpdate",a),t.render&&t.render.controller&&(i.trigger(e,"beforeRender",a),i.trigger(t,"beforeRender",a),t.render.controller.world(t.render),i.trigger(e,"afterRender",a),i.trigger(t,"afterRender",a)),i.trigger(e,"afterTick",a),i.trigger(t,"afterTick",a)},o.stop=function(e){t(e.frameRequestId)},o.start=function(e,t){o.run(e,t)}}()},{"./Common":13,"./Engine":14,"./Events":15}],21:[function(e,t,n){var o={};t.exports=o;var i=e("./Events"),r=e("./Common");!function(){o._motionWakeThreshold=.18,o._motionSleepThreshold=.08,o._minBias=.9,o.update=function(e,t){for(var n=t/r._timeUnit,i=0;i<e.length;i++){var s=e[i],a=s.speed*s.speed+s.angularSpeed*s.angularSpeed;if(0===s.force.x&&0===s.force.y){var l=Math.min(s.motion,a),c=Math.max(s.motion,a);s.motion=o._minBias*l+(1-o._minBias)*c,
|
||||
s.sleepThreshold>0&&s.motion<o._motionSleepThreshold*n*n?(s.sleepCounter+=1,s.sleepCounter>=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;i<e.length;i++){var s=e[i];if(s.isActive){var a=s.collision,l=a.bodyA.parent,c=a.bodyB.parent;if(!(l.isSleeping&&c.isSleeping||l.isStatic||c.isStatic)&&(l.isSleeping||c.isSleeping)){var u=l.isSleeping&&!l.isStatic?l:c,d=u===l?c:l;!u.isStatic&&d.motion>o._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)))
|
||||
|
|
Loading…
Reference in a new issue