/** * The MIT License (MIT) * * Copyright (c) 2013 p2.js authors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ !function(a){"object"==typeof exports?module.exports=a():"function"==typeof define&&define.amd?define(a):"undefined"!=typeof window?window.p2=a():"undefined"!=typeof global?self.p2=a():"undefined"!=typeof self&&(self.p2=a())}(function(){return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g0&&(e=1/Math.sqrt(e),a[0]=b[0]*e,a[1]=b[1]*e),a},d.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]},d.cross=function(a,b,c){var d=b[0]*c[1]-b[1]*c[0];return a[0]=a[1]=0,a[2]=d,a},d.lerp=function(a,b,c,d){var e=b[0],f=b[1];return a[0]=e+d*(c[0]-e),a[1]=f+d*(c[1]-f),a},d.transformMat2=function(a,b,c){var d=b[0],e=b[1];return a[0]=d*c[0]+e*c[1],a[1]=d*c[2]+e*c[3],a},d.forEach=function(){var a=new Float32Array(2);return function(b,c,d,e,f,g){var h,i;for(c||(c=2),d||(d=0),i=e?Math.min(e*c+d,b.length):b.length,h=d;i>h;h+=c)a[0]=b[h],a[1]=b[h+1],f(a,a,g),b[h]=a[0],b[h+1]=a[1];return b}}(),d.str=function(a){return"vec2("+a[0]+", "+a[1]+")"},"undefined"!=typeof c&&(c.vec2=d)},{}],3:[function(a,b){function c(){}var d=a("./Scalar");b.exports=c,c.lineInt=function(a,b,c){c=c||0;var e,f,g,h,i,j,k,l=[0,0];return e=a[1][1]-a[0][1],f=a[0][0]-a[1][0],g=e*a[0][0]+f*a[0][1],h=b[1][1]-b[0][1],i=b[0][0]-b[1][0],j=h*b[0][0]+i*b[0][1],k=e*i-h*f,d.eq(k,0,c)||(l[0]=(i*g-f*j)/k,l[1]=(e*j-h*g)/k),l},c.segmentsIntersect=function(a,b,c,d){var e=b[0]-a[0],f=b[1]-a[1],g=d[0]-c[0],h=d[1]-c[1];if(g*f-h*e==0)return!1;var i=(e*(c[1]-a[1])+f*(a[0]-c[0]))/(g*f-h*e),j=(g*(a[1]-c[1])+h*(c[0]-a[0]))/(h*e-g*f);return i>=0&&1>=i&&j>=0&&1>=j}},{"./Scalar":6}],4:[function(a,b){function c(){}b.exports=c,c.area=function(a,b,c){return(b[0]-a[0])*(c[1]-a[1])-(c[0]-a[0])*(b[1]-a[1])},c.left=function(a,b,d){return c.area(a,b,d)>0},c.leftOn=function(a,b,d){return c.area(a,b,d)>=0},c.right=function(a,b,d){return c.area(a,b,d)<0},c.rightOn=function(a,b,d){return c.area(a,b,d)<=0};var d=[],e=[];c.collinear=function(a,b,f,g){if(g){var h=d,i=e;h[0]=b[0]-a[0],h[1]=b[1]-a[1],i[0]=f[0]-b[0],i[1]=f[1]-b[1];var j=h[0]*i[0]+h[1]*i[1],k=Math.sqrt(h[0]*h[0]+h[1]*h[1]),l=Math.sqrt(i[0]*i[0]+i[1]*i[1]),m=Math.acos(j/(k*l));return g>m}return 0==c.area(a,b,f)},c.sqdist=function(a,b){var c=b[0]-a[0],d=b[1]-a[1];return c*c+d*d}},{}],5:[function(a,b){function c(){this.vertices=[]}function d(a,b,c,d,e){e=e||0;var f=b[1]-a[1],h=a[0]-b[0],i=f*a[0]+h*a[1],j=d[1]-c[1],k=c[0]-d[0],l=j*c[0]+k*c[1],m=f*k-j*h;return g.eq(m,0,e)?[0,0]:[(k*i-h*l)/m,(f*l-j*i)/m]}var e=a("./Line"),f=a("./Point"),g=a("./Scalar");b.exports=c,c.prototype.at=function(a){var b=this.vertices,c=b.length;return b[0>a?a%c+c:a%c]},c.prototype.first=function(){return this.vertices[0]},c.prototype.last=function(){return this.vertices[this.vertices.length-1]},c.prototype.clear=function(){this.vertices.length=0},c.prototype.append=function(a,b,c){if("undefined"==typeof b)throw new Error("From is not given!");if("undefined"==typeof c)throw new Error("To is not given!");if(b>c-1)throw new Error("lol1");if(c>a.vertices.length)throw new Error("lol2");if(0>b)throw new Error("lol3");for(var d=b;c>d;d++)this.vertices.push(a.vertices[d])},c.prototype.makeCCW=function(){for(var a=0,b=this.vertices,c=1;cb[a][0])&&(a=c);f.left(this.at(a-1),this.at(a),this.at(a+1))||this.reverse()},c.prototype.reverse=function(){for(var a=[],b=0,c=this.vertices.length;b!==c;b++)a.push(this.vertices.pop());this.vertices=a},c.prototype.isReflex=function(a){return f.right(this.at(a-1),this.at(a),this.at(a+1))};var h=[],i=[];c.prototype.canSee=function(a,b){var c,d,g=h,j=i;if(f.leftOn(this.at(a+1),this.at(a),this.at(b))&&f.rightOn(this.at(a-1),this.at(a),this.at(b)))return!1;d=f.sqdist(this.at(a),this.at(b));for(var k=0;k!==this.vertices.length;++k)if((k+1)%this.vertices.length!==a&&k!==a&&f.leftOn(this.at(a),this.at(b),this.at(k+1))&&f.rightOn(this.at(a),this.at(b),this.at(k))&&(g[0]=this.at(a),g[1]=this.at(b),j[0]=this.at(k),j[1]=this.at(k+1),c=e.lineInt(g,j),f.sqdist(this.at(a),c)a)for(var f=a;b>=f;f++)e.vertices.push(this.vertices[f]);else{for(var f=0;b>=f;f++)e.vertices.push(this.vertices[f]);for(var f=a;f0?this.slice(a):[this]},c.prototype.slice=function(a){if(0==a.length)return[this];if(a instanceof Array&&a.length&&a[0]instanceof Array&&2==a[0].length&&a[0][0]instanceof Array){for(var b=[this],c=0;cc;c++)if(e.segmentsIntersect(a[b],a[b+1],a[c],a[c+1]))return!1;for(var b=1;bh)return console.warn("quickDecomp: max level ("+h+") reached."),a;for(var x=0;xo&&(n=o,k=l,r=y))),f.left(v.at(x+1),v.at(x),v.at(y+1))&&f.rightOn(v.at(x+1),v.at(x),v.at(y))&&(l=d(v.at(x+1),v.at(x),v.at(y),v.at(y+1)),f.left(v.at(x-1),v.at(x),l)&&(o=f.sqdist(v.vertices[x],l),m>o&&(m=o,j=l,q=y)));if(r==(q+1)%this.vertices.length)l[0]=(k[0]+j[0])/2,l[1]=(k[1]+j[1])/2,e.push(l),q>x?(t.append(v,x,q+1),t.vertices.push(l),u.vertices.push(l),0!=r&&u.append(v,r,v.vertices.length),u.append(v,0,x+1)):(0!=x&&t.append(v,x,v.vertices.length),t.append(v,0,q+1),t.vertices.push(l),u.vertices.push(l),u.append(v,r,x+1));else{if(r>q&&(q+=this.vertices.length),p=Number.MAX_VALUE,r>q)return a;for(var y=r;q>=y;++y)f.leftOn(v.at(x-1),v.at(x),v.at(y))&&f.rightOn(v.at(x+1),v.at(x),v.at(y))&&(o=f.sqdist(v.at(x),v.at(y)),p>o&&(p=o,s=y%this.vertices.length));s>x?(t.append(v,x,s+1),0!=s&&u.append(v,s,w.length),u.append(v,0,x+1)):(0!=x&&t.append(v,x,w.length),t.append(v,0,s+1),u.append(v,s,x+1))}return t.vertices.length3&&c>=0;--c)f.collinear(this.at(c-1),this.at(c),this.at(c+1),a)&&(this.vertices.splice(c%this.vertices.length,1),c--,b++);return b}},{"./Line":3,"./Point":4,"./Scalar":6}],6:[function(a,b){function c(){}b.exports=c,c.eq=function(a,b,c){return c=c||0,Math.abs(a-b) (http://steffe.se)",keywords:["p2.js","p2","physics","engine","2d"],main:"./src/p2.js",engines:{node:"*"},repository:{type:"git",url:"https://github.com/schteppe/p2.js.git"},bugs:{url:"https://github.com/schteppe/p2.js/issues"},licenses:[{type:"MIT"}],devDependencies:{jshint:"latest",nodeunit:"latest",grunt:"~0.4.0","grunt-contrib-jshint":"~0.1.1","grunt-contrib-nodeunit":"~0.1.2","grunt-contrib-concat":"~0.1.3","grunt-contrib-uglify":"*","grunt-browserify":"*",browserify:"*"},dependencies:{underscore:"*","poly-decomp":"git://github.com/schteppe/poly-decomp.js","gl-matrix":"2.0.0",jsonschema:"*"}}},{}],9:[function(a,b){function c(){this.result=[]}var d=a("../math/vec2");b.exports=c,c.prototype.getCollisionPairs=function(){throw new Error("getCollisionPairs must be implemented in a subclass!")};var e=d.create();c.boundingRadiusCheck=function(a,b){d.sub(e,a.position,b.position);var c=d.squaredLength(e),f=a.boundingRadius+b.boundingRadius;return f*f>=c}},{"../math/vec2":30}],10:[function(a,b){function d(a,b,c,d,e,f){h.apply(this),e=e||10,f=f||10,this.binsizeX=(b-a)/e,this.binsizeY=(d-c)/f,this.nx=e,this.ny=f,this.xmin=a,this.ymin=c,this.xmax=b,this.ymax=d}{var e=a("../shapes/Circle"),f=a("../shapes/Plane"),g=a("../shapes/Particle"),h=a("../collision/Broadphase");a("../math/vec2")}b.exports=d,d.prototype=new h,d.prototype.getBinIndex=function(a,b){var c=this.nx,d=this.ny,e=this.xmin,f=this.ymin,g=this.xmax,h=this.ymax,i=Math.floor(c*(a-e)/(g-e)),j=Math.floor(d*(b-f)/(h-f));return i*d+j},d.prototype.getCollisionPairs=function(a){for(var b=[],d=a.bodies,i=i=d.length,j=this.binsizeX,k=this.binsizeY,l=[],m=nx*ny,n=0;m>n;n++)l.push([]);for(var o=nx/(xmax-xmin),p=ny/(ymax-ymin),n=0;n!==i;n++){var q=d[n],r=q.shape;if(void 0!==r)if(r instanceof e)for(var s=q.position[0],t=q.position[1],u=r.radius,v=Math.floor(o*(s-u-xmin)),w=Math.floor(p*(t-u-ymin)),x=Math.floor(o*(s+u-xmin)),y=Math.floor(p*(t+u-ymin)),z=v;x>=z;z++)for(var A=w;y>=A;A++){var B=z,C=A;B*(ny-1)+C>=0&&m>B*(ny-1)+C&&l[B*(ny-1)+C].push(q)}else{if(!(r instanceof f))throw new Error("Shape not supported in GridBroadphase!");if(0==q.angle)for(var t=q.position[1],z=0;z!==m&&t>ymin+k*(z-1);z++)for(var A=0;nx>A;A++){var B=A,C=Math.floor(p*(k*z-ymin));l[B*(ny-1)+C].push(q)}else if(q.angle==.5*Math.PI)for(var s=q.position[0],z=0;z!==m&&s>xmin+j*(z-1);z++)for(var A=0;ny>A;A++){var C=A,B=Math.floor(o*(j*z-xmin));l[B*(ny-1)+C].push(q)}else for(var z=0;z!==m;z++)l[z].push(q)}}for(var n=0;n!==m;n++)for(var D=l[n],z=0,E=D.length;z!==E;z++)for(var q=D[z],r=q.shape,A=0;A!==z;A++){var F=D[A],G=F.shape;r instanceof e?G instanceof e?c=h.circleCircle(q,F):G instanceof g?c=h.circleParticle(q,F):G instanceof f&&(c=h.circlePlane(q,F)):r instanceof g?G instanceof e&&(c=h.circleParticle(F,q)):r instanceof f&&G instanceof e&&(c=h.circlePlane(F,q))}return b}},{"../collision/Broadphase":9,"../math/vec2":30,"../shapes/Circle":35,"../shapes/Particle":38,"../shapes/Plane":39}],11:[function(a,b){function c(){d.apply(this)}{var d=(a("../shapes/Circle"),a("../shapes/Plane"),a("../shapes/Shape"),a("../shapes/Particle"),a("../collision/Broadphase"));a("../math/vec2")}b.exports=c,c.prototype=new d,c.prototype.getCollisionPairs=function(a){var b,c,e,f,g=a.bodies,h=this.result;for(h.length=0,b=0,Ncolliding=g.length;b!==Ncolliding;b++)for(e=g[b],c=0;b>c;c++)f=g[c],d.boundingRadiusCheck(e,f)&&h.push(e,f);return h}},{"../collision/Broadphase":9,"../math/vec2":30,"../shapes/Circle":35,"../shapes/Particle":38,"../shapes/Plane":39,"../shapes/Shape":41}],12:[function(a,b){function c(){this.contactEquations=[],this.frictionEquations=[],this.enableFriction=!0,this.slipForce=10,this.frictionCoefficient=.3,this.reuseObjects=!0,this.reusableContactEquations=[],this.reusableFrictionEquations=[],this.restitution=0,this.collidingBodiesLastStep={}}function d(a,b,c,d){for(var h=G,i=H,j=I,k=J,l=a,m=b.vertices,n=null,o=0;o!==m.length+1;o++){var p=m[o%m.length],q=m[(o+1)%m.length];e.rotate(h,p,d),e.rotate(i,q,d),g(h,h,c),g(i,i,c),f(j,h,l),f(k,i,l);var r=e.crossLength(j,k);if(null===n&&(n=r),0>=r*n)return!1;n=r}return!0}var e=a("../math/vec2"),f=e.sub,g=e.add,h=e.dot,i=a("../utils/Utils"),j=a("../constraints/ContactEquation"),k=a("../constraints/FrictionEquation"),l=a("../shapes/Circle"),m=a("../shapes/Shape");b.exports=c;var n=e.fromValues(0,1),o=e.fromValues(0,0),p=e.fromValues(0,0),q=e.fromValues(0,0),r=e.fromValues(0,0),s=e.fromValues(0,0),t=e.fromValues(0,0),u=e.fromValues(0,0),v=e.fromValues(0,0),w=e.fromValues(0,0),x=e.fromValues(0,0),y=e.fromValues(0,0),z=e.fromValues(0,0),A=e.fromValues(0,0),B=e.fromValues(0,0),C=e.fromValues(0,0),D=e.fromValues(0,0),E=e.fromValues(0,0),F=e.fromValues(0,0);c.prototype.collidedLastStep=function(a,b){var c=a.id,d=b.id;if(c>d){var e=c;c=d,d=e}return!!this.collidingBodiesLastStep[c+" "+d]},c.prototype.reset=function(){for(var a in this.collidingBodiesLastStep)delete this.collidingBodiesLastStep[a];for(var b=0;b!==this.contactEquations.length;b++){var c=this.contactEquations[b],d=c.bi.id,e=c.bj.id;if(d>e){var f=d;d=e,e=f}this.collidingBodiesLastStep[d+" "+e]=!0}if(this.reuseObjects){var g=this.contactEquations,h=this.frictionEquations,j=this.reusableFrictionEquations,k=this.reusableContactEquations;i.appendArray(k,g),i.appendArray(j,h)}this.contactEquations.length=this.frictionEquations.length=0},c.prototype.createContactEquation=function(a,b,c,d){var e=this.reusableContactEquations.length?this.reusableContactEquations.pop():new j(a,b);return e.bi=a,e.bj=b,e.shapeA=c,e.shapeB=d,e.restitution=this.restitution,e.firstImpact=!this.collidedLastStep(a,b),e},c.prototype.createFrictionEquation=function(a,b,c,d){var e=this.reusableFrictionEquations.length?this.reusableFrictionEquations.pop():new k(a,b);return e.bi=a,e.bj=b,e.shapeA=c,e.shapeB=d,e.setSlipForce(this.slipForce),e.frictionCoefficient=this.frictionCoefficient,e},c.prototype.createFrictionFromContact=function(a){var b=this.createFrictionEquation(a.bi,a.bj);return e.copy(b.ri,a.ri),e.copy(b.rj,a.rj),e.rotate(b.t,a.ni,-Math.PI/2),b.contactEquation=a,b},c.prototype[m.PLANE|m.LINE]=c.prototype.planeLine=function(a,b,c,d,i,j,k,l){var m=j,x=l,y=i,z=k,A=c,B=d,C=a,D=o,E=p,F=q,G=r,H=s,I=t,J=u,K=v,L=w;e.set(D,-m.length/2,0),e.set(E,m.length/2,0),e.rotate(F,D,x),e.rotate(G,E,x),g(F,F,z),g(G,G,z),e.copy(D,F),e.copy(E,G),f(H,E,D),e.normalize(I,H),e.rotate(L,I,-Math.PI/2),e.rotate(K,n,B);for(var M=[D,E],N=0;NP){var Q=this.createContactEquation(C,y,b,j);e.copy(Q.ni,K),e.normalize(Q.ni,Q.ni),e.scale(J,K,P),f(Q.ri,O,J),f(Q.ri,Q.ri,C.position),f(Q.rj,O,z),g(Q.rj,Q.rj,z),f(Q.rj,Q.rj,y.position),this.contactEquations.push(Q),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(Q))}}},c.prototype[m.PARTICLE|m.CAPSULE]=c.prototype.particleCapsule=function(a,b,c,d,e,f,g,h,i){return this.circleLine(a,b,c,d,e,f,g,h,i,f.radius,0)},c.prototype[m.CIRCLE|m.LINE]=c.prototype.circleLine=function(a,b,c,d,i,j,k,l,m,n,C){var D=j,E=l,F=i,G=k,H=c,I=a,J=b,n=n||0,C="undefined"!=typeof C?C:J.radius,K=o,L=p,M=q,N=r,O=s,P=t,Q=u,R=v,S=w,T=x,U=y,V=z,W=A,X=B;e.set(R,-D.length/2,0),e.set(S,D.length/2,0),e.rotate(T,R,E),e.rotate(U,S,E),g(T,T,G),g(U,U,G),e.copy(R,T),e.copy(S,U),f(P,S,R),e.normalize(Q,P),e.rotate(O,Q,-Math.PI/2),f(V,H,R);var Y=h(V,O);if(f(N,R,G),f(W,H,G),Math.abs(Y)$&&_>Z){if(m)return!0;var ab=this.createContactEquation(I,F,b,j);return e.scale(ab.ni,K,-1),e.normalize(ab.ni,ab.ni),e.scale(ab.ri,ab.ni,C),g(ab.ri,ab.ri,H),f(ab.ri,ab.ri,I.position),f(ab.rj,M,G),g(ab.rj,ab.rj,G),f(ab.rj,ab.rj,F.position),this.contactEquations.push(ab),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(ab)),!0}}for(var bb=[R,S],cb=0;cbW&&(e.copy(Q,O),S=W,e.scale(N,K,W),e.add(N,N,O),R=!0)}}if(R){var X=this.createContactEquation(E,v,b,j);return e.sub(X.ni,Q,z),e.normalize(X.ni,X.ni),e.scale(X.ri,X.ni,n),g(X.ri,X.ri,z),f(X.ri,X.ri,E.position),f(X.rj,N,w),g(X.rj,X.rj,w),f(X.rj,X.rj,v.position),this.contactEquations.push(X),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(X)),!0}if(n>0)for(var T=0;TV&&(P=V,e.scale(M,I,V),e.add(M,M,z),e.copy(O,I),Q=!0)}if(Q){var W=this.createContactEquation(B,w,b,k);return e.scale(W.ni,O,-1),e.normalize(W.ni,W.ni),e.set(W.ri,0,0),g(W.ri,W.ri,z),f(W.ri,W.ri,B.position),f(W.rj,M,y),g(W.rj,W.rj,y),f(W.rj,W.rj,w.position),this.contactEquations.push(W),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(W)),!0}return!1},c.prototype[m.CIRCLE]=c.prototype.circleCircle=function(a,b,c,d,h,i,j,k,l){var m=a,n=b,p=c,q=h,r=i,s=j,t=o;f(t,c,j);var u=b.radius+i.radius;if(e.squaredLength(t)>u*u)return!1;if(l)return!0;var v=this.createContactEquation(m,q,b,i);return f(v.ni,s,p),e.normalize(v.ni,v.ni),e.scale(v.ri,v.ni,n.radius),e.scale(v.rj,v.ni,-r.radius),g(v.ri,v.ri,p),f(v.ri,v.ri,m.position),g(v.rj,v.rj,s),f(v.rj,v.rj,q.position),this.contactEquations.push(v),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(v)),!0},c.prototype[m.PLANE|m.CONVEX]=c.prototype.planeConvex=function(a,b,c,d,i,j,k,l){var m=i,r=k,s=j,t=l,u=a,v=b,w=c,x=d,y=o,z=p,A=q,B=0;e.rotate(z,n,x);for(var C=0;C=2)break}}return B>0},c.prototype.convexPlane=function(a,b,c,d,e,f,g,h){return console.warn("Narrowphase.prototype.convexPlane is deprecated. Use planeConvex instead!"),this.planeConvex(e,f,g,h,a,b,c,d)},c.prototype[m.PARTICLE|m.PLANE]=c.prototype.particlePlane=function(a,b,c,d,g,i,j,k,l){var m=a,q=c,r=g,s=j,t=k,u=o,v=p;t=t||0,f(u,q,s),e.rotate(v,n,t);var w=h(u,v);if(w>0)return!1;if(l)return!0;var x=this.createContactEquation(r,m,i,b);return e.copy(x.ni,v),e.scale(u,x.ni,w),f(x.ri,q,u),f(x.ri,x.ri,r.position),f(x.rj,q,m.position),this.contactEquations.push(x),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(x)),!0},c.prototype[m.CIRCLE|m.PARTICLE]=c.prototype.circleParticle=function(a,b,c,d,h,i,j,k,l){var m=a,n=b,p=c,q=h,r=j,s=o;if(f(s,r,p),e.squaredLength(s)>n.radius*n.radius)return!1;if(l)return!0;var t=this.createContactEquation(m,q,b,i);return e.copy(t.ni,s),e.normalize(t.ni,t.ni),e.scale(t.ri,t.ni,n.radius),g(t.ri,t.ri,p),f(t.ri,t.ri,m.position),f(t.rj,r,q.position),this.contactEquations.push(t),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(t)),!0};{var K=new l(1),L=e.create(),M=e.create();e.create()}c.prototype[m.PLANE|m.CAPSULE]=c.prototype.planeCapsule=function(a,b,c,d,f,h,i,j){var k=L,l=M,m=K;e.set(k,-h.length/2,0),e.rotate(k,k,j),g(k,k,i),e.set(l,h.length/2,0),e.rotate(l,l,j),g(l,l,i),m.radius=h.radius,this.circlePlane(f,m,k,0,a,b,c,d),this.circlePlane(f,m,l,0,a,b,c,d)},c.prototype.capsulePlane=function(a,b,c,d,e,f,g,h){return console.warn("Narrowphase.prototype.capsulePlane() is deprecated. Use .planeCapsule() instead!"),this.planeCapsule(e,f,g,h,a,b,c,d)},c.prototype[m.CIRCLE|m.PLANE]=c.prototype.circlePlane=function(a,b,c,d,i,j,k,l){var m=a,r=b,s=c,t=i,u=k,v=l;v=v||0;var w=o,x=p,y=q;f(w,s,u),e.rotate(x,n,v);var z=h(x,w);if(z>r.radius)return!1;var A=this.createContactEquation(t,m,j,b);return e.copy(A.ni,x),e.scale(A.rj,A.ni,-r.radius),g(A.rj,A.rj,s),f(A.rj,A.rj,m.position),e.scale(y,A.ni,z),f(A.ri,w,y),g(A.ri,A.ri,u),f(A.ri,A.ri,t.position),this.contactEquations.push(A),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(A)),!0},c.prototype[m.CONVEX]=c.prototype.convexConvex=function(a,b,d,i,j,k,l,m){var n=o,t=p,x=q,y=r,z=s,A=u,B=v,C=w,D=c.findSeparatingAxis(b,d,i,k,l,m,n);if(!D)return!1;f(B,l,d),h(n,B)>0&&e.scale(n,n,-1);var E=c.getClosestEdge(b,i,n,!0),F=c.getClosestEdge(k,m,n);if(-1==E||-1==F)return!1;for(var G=0;2>G;G++){var H=E,I=F,J=b,K=k,L=d,M=l,N=i,O=m,P=a,Q=j;if(0==G){var R;R=H,H=I,I=R,R=J,J=K,K=R,R=L,L=M,M=R,R=N,N=O,O=R,R=P,P=Q,Q=R}for(var S=I;I+2>S;S++){var T=K.vertices[(S+K.vertices.length)%K.vertices.length];e.rotate(t,T,O),g(t,t,M);for(var U=0,V=H-1;H+2>V;V++){var W=J.vertices[(V+J.vertices.length)%J.vertices.length],X=J.vertices[(V+1+J.vertices.length)%J.vertices.length];e.rotate(x,W,N),e.rotate(y,X,N),g(x,x,L),g(y,y,L),f(z,y,x),e.rotate(C,z,-Math.PI/2),e.normalize(C,C),f(B,t,x);var Y=h(C,B);0>Y&&U++}if(3==U){var Z=this.createContactEquation(P,Q,b,k),W=J.vertices[H%J.vertices.length],X=J.vertices[(H+1)%J.vertices.length];e.rotate(x,W,N),e.rotate(y,X,N),g(x,x,L),g(y,y,L),f(z,y,x),e.rotate(Z.ni,z,-Math.PI/2),e.normalize(Z.ni,Z.ni),f(B,t,x);var Y=h(Z.ni,B);e.scale(A,Z.ni,Y),f(Z.ri,t,L),f(Z.ri,Z.ri,A),g(Z.ri,Z.ri,L),f(Z.ri,Z.ri,P.position),f(Z.rj,t,M),g(Z.rj,Z.rj,M),f(Z.rj,Z.rj,Q.position),this.contactEquations.push(Z),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(Z))}}}};var N=e.fromValues(0,0);c.projectConvexOntoAxis=function(a,b,c,d,f){var g,i,j=null,k=null,l=N;e.rotate(l,d,-c);for(var m=0;mj)&&(j=i),(null===k||k>i)&&(k=i);if(k>j){var n=k;k=j,j=n}var o=h(b,d);e.set(f,k+o,j+o)};var O=e.fromValues(0,0),P=e.fromValues(0,0),Q=e.fromValues(0,0),R=e.fromValues(0,0),S=e.fromValues(0,0),T=e.fromValues(0,0);c.findSeparatingAxis=function(a,b,d,g,h,i,j){for(var k=null,l=!1,m=!1,n=O,o=P,p=Q,q=R,r=S,s=T,t=0;2!==t;t++){var u=a,v=d;1===t&&(u=g,v=i);for(var w=0;w!==u.vertices.length;w++){e.rotate(o,u.vertices[w],v),e.rotate(p,u.vertices[(w+1)%u.vertices.length],v),f(n,p,o),e.rotate(q,n,-Math.PI/2),e.normalize(q,q),c.projectConvexOntoAxis(a,b,d,q,r),c.projectConvexOntoAxis(g,h,i,q,s);var x=r,y=s,z=!1;r[0]>s[0]&&(y=r,x=s,z=!0);var A=y[0]-x[1];l=0>A,(null===k||A>k)&&(e.copy(j,q),k=A,m=l)}}return m};var U=e.fromValues(0,0),V=e.fromValues(0,0),W=e.fromValues(0,0);c.getClosestEdge=function(a,b,c,d){var g=U,i=V,j=W;e.rotate(g,c,-b),d&&e.scale(g,g,-1);for(var k=-1,l=a.vertices.length,m=Math.PI/2,n=0;n!==l;n++){f(i,a.vertices[(n+1)%l],a.vertices[n%l]),e.rotate(j,i,-m),e.normalize(j,j);var o=h(j,g);(-1==k||o>maxDot)&&(k=n%l,maxDot=o)}return k}},{"../constraints/ContactEquation":16,"../constraints/FrictionEquation":19,"../math/vec2":30,"../shapes/Circle":35,"../shapes/Shape":41,"../utils/Utils":46}],13:[function(a,b){function c(a,b,c,f){var g;g=b?new d(a,0,c,f):new e(a,0,c,f),this.root=g}function d(a,b,c,d){this.bounds=a,this.children=[],this.nodes=[],d&&(this.maxChildren=d),c&&(this.maxDepth=c),b&&(this.depth=b)}function e(a,b,c,e){d.call(this,a,b,c,e),this.stuckChildren=[]}var f=a("../shapes/Plane"),g=a("../collision/Broadphase");b.exports={QuadTree:c,Node:d,BoundsNode:e},c.prototype.insert=function(a){if(a instanceof Array)for(var b=a.length,c=0;b>c;c++)this.root.insert(a[c]);else this.root.insert(a)},c.prototype.clear=function(){this.root.clear()},c.prototype.retrieve=function(a){var b=this.root.retrieve(a).slice(0);return b},c.prototype.getCollisionPairs=function(a){var b=[];this.insert(a.bodies);for(var c=0;c!==a.bodies.length;c++)for(var d=a.bodies[c],e=this.retrieve(d),f=0,h=e.length;f!==h;f++){var i=e[f];if(d!==i){for(var j=!1,k=0,l=b.length;l>k;k+=2){var m=b[k],n=b[k+1];if(m==i&&n==d||n==i&&m==d){j=!0;break}}!j&&g.boundingRadiusCheck(d,i)&&b.push(d,i)}}return this.clear(),b},d.prototype.classConstructor=d,d.prototype.children=null,d.prototype.depth=0,d.prototype.maxChildren=4,d.prototype.maxDepth=4,d.TOP_LEFT=0,d.TOP_RIGHT=1,d.BOTTOM_LEFT=2,d.BOTTOM_RIGHT=3,d.prototype.insert=function(a){if(this.nodes.length){var b=this.findIndex(a);return this.nodes[b].insert(a),void 0}this.children.push(a);var c=this.children.length;if(!(this.depth>=this.maxDepth)&&c>this.maxChildren){this.subdivide();for(var d=0;c>d;d++)this.insert(this.children[d]);this.children.length=0}},d.prototype.retrieve=function(a){if(this.nodes.length){var b=this.findIndex(a);return this.nodes[b].retrieve(a)}return this.children},d.prototype.findIndex=function(a){var b=this.bounds,c=a.position[0]-a.boundingRadius>b.x+b.width/2?!1:!0,e=a.position[1]-a.boundingRadius>b.y+b.height/2?!1:!0;a instanceof f&&(c=e=!1);var g=d.TOP_LEFT;return c?e||(g=d.BOTTOM_LEFT):g=e?d.TOP_RIGHT:d.BOTTOM_RIGHT,g},d.prototype.subdivide=function(){var a=this.depth+1,b=this.bounds.x,c=this.bounds.y,e=this.bounds.width/2,f=this.bounds.height/2,g=b+e,h=c+f;this.nodes[d.TOP_LEFT]=new this.classConstructor({x:b,y:c,width:e,height:f},a),this.nodes[d.TOP_RIGHT]=new this.classConstructor({x:g,y:c,width:e,height:f},a),this.nodes[d.BOTTOM_LEFT]=new this.classConstructor({x:b,y:h,width:e,height:f},a),this.nodes[d.BOTTOM_RIGHT]=new this.classConstructor({x:g,y:h,width:e,height:f},a)},d.prototype.clear=function(){this.children.length=0;for(var a=this.nodes.length,b=0;a>b;b++)this.nodes[b].clear();this.nodes.length=0},e.prototype=new d,e.prototype.classConstructor=e,e.prototype.stuckChildren=null,e.prototype.out=[],e.prototype.insert=function(a){if(this.nodes.length){var b=this.findIndex(a),c=this.nodes[b];return!(a instanceof f)&&a.position[0]-a.boundingRadius>=c.bounds.x&&a.position[0]+a.boundingRadius<=c.bounds.x+c.bounds.width&&a.position[1]-a.boundingRadius>=c.bounds.y&&a.position[1]+a.boundingRadius<=c.bounds.y+c.bounds.height?this.nodes[b].insert(a):this.stuckChildren.push(a),void 0}this.children.push(a);var d=this.children.length;if(this.depththis.maxChildren){this.subdivide();for(var e=0;d>e;e++)this.insert(this.children[e]);this.children.length=0}},e.prototype.getChildren=function(){return this.children.concat(this.stuckChildren)},e.prototype.retrieve=function(a){var b=this.out;if(b.length=0,this.nodes.length){var c=this.findIndex(a);b.push.apply(b,this.nodes[c].retrieve(a))}return b.push.apply(b,this.stuckChildren),b.push.apply(b,this.children),b},e.prototype.clear=function(){this.stuckChildren.length=0,this.children.length=0;var a=this.nodes.length;if(a){for(var b=0;a>b;b++)this.nodes[b].clear();this.nodes.length=0}}},{"../collision/Broadphase":9,"../shapes/Plane":39}],14:[function(a,b){function c(a){d.apply(this),this.axisList=a.bodies.slice(0),this.world=a,this.axisIndex=0;var b=this.axisList;a.on("addBody",function(a){b.push(a.body)}).on("removeBody",function(a){var c=b.indexOf(a.body);-1!==c&&b.splice(c,1)})}{var d=(a("../shapes/Circle"),a("../shapes/Plane"),a("../shapes/Shape"),a("../shapes/Particle"),a("../collision/Broadphase"));a("../math/vec2")}b.exports=c,c.prototype=new d,c.sortAxisListX=function(a,b){return a.position[0]-a.boundingRadius-(b.position[0]-b.boundingRadius)},c.sortAxisListY=function(a,b){return a.position[1]-a.boundingRadius-(b.position[1]-b.boundingRadius)},c.prototype.getCollisionPairs=function(){var a,b,e=this.axisList,f=this.result,g=this.axisIndex;for(f.length=0,e.sort(0===g?c.sortAxisListX:c.sortAxisListY),a=0,N=e.length;a!==N;a++){var h=e[a];for(b=a+1;N>b;b++){var i=e[b];if(!c.checkBounds(h,i,g))break;d.boundingRadiusCheck(h,i)&&f.push(h,i)}}return f},c.checkBounds=function(a,b,c){var d=a.position[c],e=a.boundingRadius,f=b.position[c],g=b.boundingRadius,h=d+e,i=f-g; return h>i}},{"../collision/Broadphase":9,"../math/vec2":30,"../shapes/Circle":35,"../shapes/Particle":38,"../shapes/Plane":39,"../shapes/Shape":41}],15:[function(a,b){function c(a,b){this.equations=[],this.bodyA=a,this.bodyB=b}b.exports=c},{}],16:[function(a,b){function c(a,b){d.call(this,a,b,0,Number.MAX_VALUE),this.ri=e.create(),this.penetrationVec=e.create(),this.rj=e.create(),this.ni=e.create(),this.restitution=0,this.firstImpact=!1,this.shapeA=null,this.shapeB=null}{var d=a("./Equation"),e=a("../math/vec2");a("../math/mat2")}b.exports=c,c.prototype=new d,c.prototype.constructor=c,c.prototype.computeB=function(a,b,c){var d=this.bi,f=this.bj,g=this.ri,h=this.rj,i=d.position,j=f.position,k=this.penetrationVec,l=this.ni,m=this.G,n=e.crossLength(g,l),o=e.crossLength(h,l);m[0]=-l[0],m[1]=-l[1],m[2]=-n,m[3]=l[0],m[4]=l[1],m[5]=o,e.add(k,j,h),e.sub(k,k,i),e.sub(k,k,g);var p,q;this.firstImpact&&0!==this.restitution?(q=0,p=1/b*(1+this.restitution)*this.computeGW()):(p=this.computeGW(),q=e.dot(l,k));var r=this.computeGiMf(),s=-q*a-p*b-c*r;return s}},{"../math/mat2":28,"../math/vec2":30,"./Equation":18}],17:[function(a,b){function c(a,b,c,g){d.call(this,a,b),this.distance=c,"undefined"==typeof g&&(g=Number.MAX_VALUE);var h=new e(a,b,-g,g);this.equations=[h];var i=f.create();h.computeGq=function(){return f.sub(i,b.position,a.position),f.length(i)-c},this.setMaxForce(g)}var d=a("./Constraint"),e=a("./Equation"),f=a("../math/vec2");b.exports=c,c.prototype=new d;var g=f.create();c.prototype.update=function(){var a=this.equations[0],b=this.bodyA,c=this.bodyB,d=(this.distance,a.G);f.sub(g,c.position,b.position),f.normalize(g,g),d[0]=-g[0],d[1]=-g[1],d[3]=g[0],d[4]=g[1]},c.prototype.setMaxForce=function(a){var b=this.equations[0];b.minForce=-a,b.maxForce=a},c.prototype.getMaxForce=function(){var a=this.equations[0];return a.maxForce}},{"../math/vec2":30,"./Constraint":15,"./Equation":18}],18:[function(a,b){function c(a,b,c,d){this.minForce="undefined"==typeof c?-1e6:c,this.maxForce="undefined"==typeof d?1e6:d,this.bi=a,this.bj=b,this.stiffness=1e6,this.relaxation=4,this.G=new g.ARRAY_TYPE(6),this.offset=0,this.a=0,this.b=0,this.eps=0,this.h=0,this.updateSpookParams(1/60),this.multiplier=0}function d(a,b,c,d,e){return a[0]*b[0]+a[1]*b[1]+a[2]*c+a[3]*d[0]+a[4]*d[1]+a[5]*e}b.exports=c;var e=a("../math/vec2"),f=a("../math/mat2"),g=a("../utils/Utils");c.prototype.constructor=c,c.prototype.updateSpookParams=function(a){var b=this.stiffness,c=this.relaxation,d=a;this.a=4/(d*(1+4*c)),this.b=4*c/(1+4*c),this.eps=4/(d*d*b*(1+4*c)),this.h=a},c.prototype.computeB=function(a,b,c){var d=this.computeGW(),e=this.computeGq(),f=this.computeGiMf();return-e*a-d*b-f*c};var h=e.create(),i=e.create();c.prototype.computeGq=function(){var a=this.G,b=this.bi,c=this.bj,e=(b.position,c.position,b.angle),f=c.angle;return d(a,h,e,i,f)+this.offset};e.create(),e.create();c.prototype.transformedGmult=function(a,b,c,e,f){return d(a,b,c,e,f)},c.prototype.computeGW=function(){var a=this.G,b=this.bi,c=this.bj,d=b.velocity,e=c.velocity,f=b.angularVelocity,g=c.angularVelocity;return this.transformedGmult(a,d,f,e,g)},c.prototype.computeGWlambda=function(){var a=this.G,b=this.bi,c=this.bj,d=b.vlambda,e=c.vlambda,f=b.wlambda,g=c.wlambda;return this.transformedGmult(a,d,f,e,g)};var j=e.create(),k=e.create();c.prototype.computeGiMf=function(){var a=this.bi,b=this.bj,c=a.force,d=a.angularForce,f=b.force,g=b.angularForce,h=a.invMass,i=b.invMass,l=a.invInertia,m=b.invInertia,n=this.G;return e.scale(j,c,h),e.scale(k,f,i),this.transformedGmult(n,j,d*l,k,g*m)},c.prototype.computeGiMGt=function(){var a=this.bi,b=this.bj,c=a.invMass,d=b.invMass,e=a.invInertia,f=b.invInertia,g=this.G;return g[0]*g[0]*c+g[1]*g[1]*c+g[2]*g[2]*e+g[3]*g[3]*d+g[4]*g[4]*d+g[5]*g[5]*f};var l=e.create(),m=e.create(),n=e.create(),o=(e.create(),e.create(),f.create()),p=f.create();c.prototype.addToWlambda=function(a){var b=this.bi,c=this.bj,d=l,g=o,h=p,i=m,j=n,k=this.G;i[0]=k[0],i[1]=k[1],j[0]=k[3],j[1]=k[4],f.identity(g),f.identity(h),g[0]=g[3]=b.invMass,h[0]=h[3]=c.invMass,e.scale(d,e.transformMat2(d,i,g),a),e.add(b.vlambda,b.vlambda,d),e.scale(d,e.transformMat2(d,j,h),a),e.add(c.vlambda,c.vlambda,d),b.wlambda+=b.invInertia*k[2]*a,c.wlambda+=c.invInertia*k[5]*a},c.prototype.computeC=function(a){return this.computeGiMGt()+a}},{"../math/mat2":28,"../math/vec2":30,"../utils/Utils":46}],19:[function(a,b){function c(a,b,c){e.call(this,a,b,-c,c),this.ri=d.create(),this.rj=d.create(),this.t=d.create(),this.contactEquation=null,this.shapeA=null,this.shapeB=null,this.frictionCoefficient=.3}{var d=(a("../math/mat2"),a("../math/vec2")),e=a("./Equation");a("../utils/Utils")}b.exports=c,c.prototype=new e,c.prototype.constructor=c,c.prototype.setSlipForce=function(a){this.maxForce=a,this.minForce=-a},c.prototype.computeB=function(a,b,c){var e=(this.bi,this.bj,this.ri),f=this.rj,g=this.t,h=this.G;h[0]=-g[0],h[1]=-g[1],h[2]=-d.crossLength(e,g),h[3]=g[0],h[4]=g[1],h[5]=d.crossLength(f,g);var i=this.computeGW(),j=this.computeGiMf(),k=-i*b-c*j;return k}},{"../math/mat2":28,"../math/vec2":30,"../utils/Utils":46,"./Equation":18}],20:[function(a,b){function c(a,b,c){d.call(this,a,b);var g="undefined"==typeof c.maxForce?Number.MAX_VALUE:c.maxForce,h=c.localOffsetB||e.fromValues(0,0);h=e.fromValues(h[0],h[1]);var i=c.localAngleB||0,j=new f(a,b,-g,g),k=new f(a,b,-g,g),l=new f(a,b,-g,g),m=e.create(),n=e.create();j.computeGq=function(){return e.rotate(m,h,a.angle),e.sub(n,b.position,a.position),e.sub(n,n,m),n[0]},k.computeGq=function(){return e.rotate(m,h,a.angle),e.sub(n,b.position,a.position),e.sub(n,n,m),n[1]};var o=e.create(),p=e.create();l.computeGq=function(){return e.rotate(o,h,b.angle-i),e.scale(o,o,-1),e.sub(n,a.position,b.position),e.add(n,n,o),e.rotate(p,o,-Math.PI/2),e.normalize(p,p),e.dot(n,p)},this.localOffsetB=h,this.localAngleB=i,this.maxForce=g;this.equations=[j,k,l]}var d=a("./Constraint"),e=a("../math/vec2"),f=a("./Equation");b.exports=c,c.prototype=new d;var g=e.create(),h=e.create(),i=e.create(),j=e.fromValues(1,0),k=e.fromValues(0,1);c.prototype.update=function(){var a=this.equations[0],b=this.equations[1],c=this.equations[2],d=this.bodyA,f=this.bodyB;e.rotate(g,this.localOffsetB,d.angle),e.rotate(h,this.localOffsetB,f.angle-this.localAngleB),e.scale(h,h,-1),e.rotate(i,h,Math.PI/2),e.normalize(i,i),a.G[0]=-1,a.G[1]=0,a.G[2]=-e.crossLength(g,j),a.G[3]=1,b.G[0]=0,b.G[1]=-1,b.G[2]=-e.crossLength(g,k),b.G[4]=1,c.G[0]=-i[0],c.G[1]=-i[1],c.G[3]=i[0],c.G[4]=i[1],c.G[5]=e.crossLength(h,i)}},{"../math/vec2":30,"./Constraint":15,"./Equation":18}],21:[function(a,b){function c(a,b,c){c=c||{},d.call(this,a,b);var h=f.fromValues(0,0),i=f.fromValues(1,0),j=f.fromValues(0,0);c.localAnchorA&&f.copy(h,c.localAnchorA),c.localAxisA&&f.copy(i,c.localAxisA),c.localAnchorB&&f.copy(j,c.localAnchorB),this.localAnchorA=h,this.localAnchorB=j,this.localAxisA=i;var k=this.maxForce="undefined"==typeof c.maxForce?c.maxForce:Number.MAX_VALUE,l=new e(a,b,-k,k),m=new f.create,n=new f.create,o=new f.create,p=new f.create;l.computeGq=function(){return f.dot(o,p)},l.update=function(){var c=this.G,d=a.position,e=b.position;f.rotate(m,h,a.angle),f.rotate(n,j,b.angle),f.add(o,e,n),f.sub(o,o,d),f.sub(o,o,m),f.rotate(p,i,a.angle+Math.PI/2),c[0]=-p[0],c[1]=-p[1],c[2]=-f.crossLength(m,p)+f.crossLength(p,o),c[3]=p[0],c[4]=p[1],c[5]=f.crossLength(n,p)};var q=new g(a,b,-k,k);this.equations.push(l,q)}var d=a("./Constraint"),e=(a("./ContactEquation"),a("./Equation")),f=a("../math/vec2"),g=a("./RotationalLockEquation");b.exports=c,c.prototype=new d,c.prototype.update=function(){var a=this.equations,b=a[0];b.update()}},{"../math/vec2":30,"./Constraint":15,"./ContactEquation":16,"./Equation":18,"./RotationalLockEquation":23}],22:[function(a,b){function c(a,b,c,n,o){d.call(this,a,c),o="undefined"!=typeof o?o:Number.MAX_VALUE,this.pivotA=b,this.pivotB=n;var p=this.equations=[new e(a,c,-o,o),new e(a,c,-o,o)],q=p[0],r=p[1];q.computeGq=function(){return h.rotate(i,b,a.angle),h.rotate(j,n,c.angle),h.add(m,c.position,j),h.sub(m,m,a.position),h.sub(m,m,i),h.dot(m,k)},r.computeGq=function(){return h.rotate(i,b,a.angle),h.rotate(j,n,c.angle),h.add(m,c.position,j),h.sub(m,m,a.position),h.sub(m,m,i),h.dot(m,l)},r.minForce=q.minForce=-o,r.maxForce=q.maxForce=o,this.motorEquation=new f(a,c),this.motorEnabled=!1,this.lowerLimitEnabled=!1,this.upperLimitEnabled=!1,this.lowerLimit=0,this.upperLimit=0,this.upperLimitEquation=new g(a,c),this.lowerLimitEquation=new g(a,c),this.upperLimitEquation.minForce=0,this.lowerLimitEquation.maxForce=0}var d=a("./Constraint"),e=a("./Equation"),f=a("./RotationalVelocityEquation"),g=a("./RotationalLockEquation"),h=a("../math/vec2");b.exports=c;var i=h.create(),j=h.create(),k=h.fromValues(1,0),l=h.fromValues(0,1),m=h.create();c.prototype=new d,c.prototype.update=function(){var a=this.bodyA,b=this.bodyB,c=this.pivotA,d=this.pivotB,e=this.equations,f=(e[0],e[1],e[0]),g=e[1],m=this.upperLimit,n=this.lowerLimit,o=this.upperLimitEquation,p=this.lowerLimitEquation,q=this.angle=b.angle-a.angle;if(this.upperLimitEnabled&&q>m)o.angle=m,-1==e.indexOf(o)&&e.push(o);else{var r=e.indexOf(o);-1!=r&&e.splice(r,1)}if(this.lowerLimitEnabled&&n>q)p.angle=n,-1==e.indexOf(p)&&e.push(p);else{var r=e.indexOf(p);-1!=r&&e.splice(r,1)}h.rotate(i,c,a.angle),h.rotate(j,d,b.angle),f.G[0]=-1,f.G[1]=0,f.G[2]=-h.crossLength(i,k),f.G[3]=1,f.G[4]=0,f.G[5]=h.crossLength(j,k),g.G[0]=0,g.G[1]=-1,g.G[2]=-h.crossLength(i,l),g.G[3]=0,g.G[4]=1,g.G[5]=h.crossLength(j,l)},c.prototype.enableMotor=function(){this.motorEnabled||(this.equations.push(this.motorEquation),this.motorEnabled=!0)},c.prototype.disableMotor=function(){if(this.motorEnabled){var a=this.equations.indexOf(this.motorEquation);this.equations.splice(a,1),this.motorEnabled=!1}},c.prototype.motorIsEnabled=function(){return!!this.motorEnabled},c.prototype.setMotorSpeed=function(a){if(this.motorEnabled){var b=this.equations.indexOf(this.motorEquation);this.equations[b].relativeVelocity=a}},c.prototype.getMotorSpeed=function(){return this.motorEnabled?this.motorEquation.relativeVelocity:!1}},{"../math/vec2":30,"./Constraint":15,"./Equation":18,"./RotationalLockEquation":23,"./RotationalVelocityEquation":24}],23:[function(a,b){function c(a,b,c){c=c||{},d.call(this,a,b,-Number.MAX_VALUE,Number.MAX_VALUE),this.angle=c.angle||0;var e=this.G;e[2]=1,e[5]=-1}var d=a("./Equation"),e=a("../math/vec2");b.exports=c,c.prototype=new d,c.prototype.constructor=c;var f=e.create(),g=e.create(),h=e.fromValues(1,0),i=e.fromValues(0,1);c.prototype.computeGq=function(){return e.rotate(f,h,this.bi.angle+this.angle),e.rotate(g,i,this.bj.angle),e.dot(f,g)}},{"../math/vec2":30,"./Equation":18}],24:[function(a,b){function c(a,b){d.call(this,a,b,-Number.MAX_VALUE,Number.MAX_VALUE),this.relativeVelocity=1,this.ratio=1}{var d=a("./Equation");a("../math/vec2")}b.exports=c,c.prototype=new d,c.prototype.constructor=c,c.prototype.computeB=function(a,b,c){var d=this.G;d[2]=-1,d[5]=this.ratio;var e=this.computeGiMf(),f=this.computeGW()+this.relativeVelocity,g=-f*b-c*e;return g}},{"../math/vec2":30,"./Equation":18}],25:[function(a,b){var c=function(){};b.exports=c,c.prototype={constructor:c,on:function(a,b){void 0===this._listeners&&(this._listeners={});var c=this._listeners;return void 0===c[a]&&(c[a]=[]),-1===c[a].indexOf(b)&&c[a].push(b),this},has:function(a,b){if(void 0===this._listeners)return!1;var c=this._listeners;return void 0!==c[a]&&-1!==c[a].indexOf(b)?!0:!1},off:function(a,b){if(void 0!==this._listeners){var c=this._listeners,d=c[a].indexOf(b);return-1!==d&&c[a].splice(d,1),this}},emit:function(a){if(void 0!==this._listeners){var b=this._listeners,c=b[a.type];if(void 0!==c){a.target=this;for(var d=0,e=c.length;e>d;d++)c[d].call(this,a)}return this}}}},{}],26:[function(a,b){function c(a,b,c){c=c||{},this.id=d++,this.materialA=a,this.materialB=b,this.friction="undefined"!=typeof c.friction?Number(c.friction):.3,this.restitution="undefined"!=typeof c.restitution?Number(c.restitution):0,this.stiffness="undefined"!=typeof c.stiffness?Number(c.stiffness):1e7,this.relaxation="undefined"!=typeof c.relaxation?Number(c.relaxation):3,this.frictionStiffness="undefined"!=typeof c.frictionStiffness?Number(c.frictionStiffness):1e7,this.frictionRelaxation="undefined"!=typeof c.frictionRelaxation?Number(c.frictionRelaxation):3}b.exports=c;var d=0},{}],27:[function(a,b){function c(){this.id=d++}b.exports=c;var d=0},{}],28:[function(a,b){var c=a("../../node_modules/gl-matrix/src/gl-matrix/mat2").mat2;b.exports=c},{"../../node_modules/gl-matrix/src/gl-matrix/mat2":1}],29:[function(a,b){var c={};c.GetArea=function(a){if(a.length<6)return 0;for(var b=a.length-2,c=0,d=0;b>d;d+=2)c+=(a[d+2]-a[d])*(a[d+1]+a[d+3]);return c+=(a[0]-a[b])*(a[b+1]+a[1]),.5*-c},c.Triangulate=function(a){var b=a.length>>1;if(3>b)return[];for(var d=[],e=[],f=0;b>f;f++)e.push(f);for(var f=0,g=b;g>3;){var h=e[(f+0)%g],i=e[(f+1)%g],j=e[(f+2)%g],k=a[2*h],l=a[2*h+1],m=a[2*i],n=a[2*i+1],o=a[2*j],p=a[2*j+1],q=!1;if(c._convex(k,l,m,n,o,p)){q=!0;for(var r=0;g>r;r++){var s=e[r];if(s!=h&&s!=i&&s!=j&&c._PointInTriangle(a[2*s],a[2*s+1],k,l,m,n,o,p)){q=!1;break}}}if(q)d.push(h,i,j),e.splice((f+1)%g,1),g--,f=0;else if(f++>3*g)break}return d.push(e[0],e[1],e[2]),d},c._PointInTriangle=function(a,b,c,d,e,f,g,h){var i=g-c,j=h-d,k=e-c,l=f-d,m=a-c,n=b-d,o=i*i+j*j,p=i*k+j*l,q=i*m+j*n,r=k*k+l*l,s=k*m+l*n,t=1/(o*r-p*p),u=(r*q-p*s)*t,v=(o*s-p*q)*t;return u>=0&&v>=0&&1>u+v},c._convex=function(a,b,c,d,e,f){return(b-d)*(e-c)+(c-a)*(f-d)>=0},b.exports=c},{}],30:[function(a,b){var c=a("../../node_modules/gl-matrix/src/gl-matrix/vec2").vec2;c.getX=function(a){return a[0]},c.getY=function(a){return a[1]},c.crossLength=function(a,b){return a[0]*b[1]-a[1]*b[0]},c.crossVZ=function(a,b,d){return c.rotate(a,b,-Math.PI/2),c.scale(a,a,d),a},c.crossZV=function(a,b,d){return c.rotate(a,d,Math.PI/2),c.scale(a,a,b),a},c.rotate=function(a,b,c){var d=Math.cos(c),e=Math.sin(c),f=b[0],g=b[1];a[0]=d*f-e*g,a[1]=e*f+d*g},c.toLocalFrame=function(a,b,d,e){c.copy(a,b),c.sub(a,a,d),c.rotate(a,a,-e)},c.toGlobalFrame=function(a,b,d,e){c.copy(a,b),c.rotate(a,a,e),c.add(a,a,d)},c.centroid=function(a,b,d,e){return c.add(a,b,d),c.add(a,a,e),c.scale(a,a,1/3),a},b.exports=c},{"../../node_modules/gl-matrix/src/gl-matrix/vec2":2}],31:[function(a,b){function c(a){a=a||{},this.id=++c._idCounter,this.shapes=[],this.shapeOffsets=[],this.shapeAngles=[],this.mass=a.mass||0,this.invMass=0,this.inertia=0,this.invInertia=0,this.fixedRotation=!!a.fixedRotation||!1,this.updateMassProperties(),this.position=d.fromValues(0,0),a.position&&d.copy(this.position,a.position),this.velocity=d.fromValues(0,0),a.velocity&&d.copy(this.velocity,a.velocity),this.vlambda=d.fromValues(0,0),this.wlambda=0,this.angle=a.angle||0,this.angularVelocity=a.angularVelocity||0,this.force=d.create(),a.force&&d.copy(this.force,a.force),this.angularForce=a.angularForce||0,this.damping="number"==typeof a.damping?a.damping:.1,this.angularDamping="number"==typeof a.angularDamping?a.angularDamping:.1,this.motionState=0==this.mass?c.STATIC:c.DYNAMIC,this.boundingRadius=0,this.concavePath=null,this.lastDampingScale=1,this.lastAngularDampingScale=1,this.lastDampingTimeStep=-1}var d=a("../math/vec2"),e=a("poly-decomp"),f=a("../shapes/Convex");b.exports=c;var g=d.fromValues(0,0);c._idCounter=0,c.prototype.updateBoundingRadius=function(){for(var a=this.shapes,b=this.shapeOffsets,c=a.length,e=0,f=0;f!==c;f++){var h=a[f],i=d.length(b[f]||g),j=h.boundingRadius;i+j>e&&(e=i+j)}this.boundingRadius=e},c.prototype.addShape=function(a,b,c){c=c||0,b=b?d.fromValues(b[0],b[1]):d.fromValues(0,0),this.shapes.push(a),this.shapeOffsets.push(b),this.shapeAngles.push(c),this.updateMassProperties(),this.updateBoundingRadius()},c.prototype.removeShape=function(a){var b=this.shapes.indexOf(a);return-1!=b?(this.shapes.splice(b,1),this.shapeOffsets.splice(b,1),this.shapeAngles.splice(b,1),!0):!1},c.prototype.updateMassProperties=function(){var a=this.shapes,b=a.length,c=this.mass/b,e=0;if(!this.fixedRotation)for(var f=0;b>f;f++){var h=a[f],i=d.squaredLength(this.shapeOffsets[f]||g),j=h.computeMomentOfInertia(c);e+=j+c*i}this.inertia=e,this.invMass=this.mass>0?1/this.mass:0,this.invInertia=e>0?1/e:0};var h=d.create();c.prototype.applyForce=function(a,b){var c=h;d.sub(c,b,this.position),d.add(this.force,this.force,a);var e=d.crossLength(c,a);this.angularForce+=e},c.prototype.toLocalFrame=function(a,b){d.toLocalFrame(a,b,this.position,this.angle)},c.prototype.toWorldFrame=function(a,b){d.toGlobalFrame(a,b,this.position,this.angle)},c.prototype.fromPolygon=function(a,b){b=b||{};for(var c=this.shapes.length;c>=0;--c)this.removeShape(this.shapes[c]);var g=new e.Polygon;if(g.vertices=a,g.makeCCW(),"number"==typeof b.removeCollinearPoints&&g.removeCollinearPoints(b.removeCollinearPoints),"undefined"==typeof b.skipSimpleCheck&&!g.isSimple())return!1;this.concavePath=g.vertices.slice(0);for(var c=0;cb&&(b=d)}this.boundingRadius=Math.sqrt(b)},c.prototype.updateArea=function(){this.updateTriangles(),this.area=0;for(var a=this.triangles,b=this.vertices,c=0;c!==a.length;c++){var d=a[c],e=b[d[0]],f=b[d[1]],h=b[d[2]],i=g.Point.area(e,f,h);this.area+=i}}},{"../math/polyk":29,"../math/vec2":30,"./Shape":41,"poly-decomp":7}],37:[function(a,b){function c(a){this.length=a,d.call(this,d.LINE)}var d=a("./Shape");b.exports=c,c.prototype=new d,c.prototype.computeMomentOfInertia=function(a){return a*Math.pow(this.length,2)/12},c.prototype.updateBoundingRadius=function(){this.boundingRadius=this.length/2}},{"./Shape":41}],38:[function(a,b){function c(){d.call(this,d.PARTICLE)}var d=a("./Shape");b.exports=c,c.prototype=new d,c.prototype.computeMomentOfInertia=function(){return 0},c.prototype.updateBoundingRadius=function(){this.boundingRadius=0}},{"./Shape":41}],39:[function(a,b){function c(){d.call(this,d.PLANE)}var d=a("./Shape");b.exports=c,c.prototype=new d,c.prototype.computeMomentOfInertia=function(){return 0},c.prototype.updateBoundingRadius=function(){this.boundingRadius=Number.MAX_VALUE}},{"./Shape":41}],40:[function(a,b){function c(a,b){var c=[d.fromValues(-a/2,-b/2),d.fromValues(a/2,-b/2),d.fromValues(a/2,b/2),d.fromValues(-a/2,b/2)];this.width=a,this.height=b,e.call(this,c)}var d=a("../math/vec2"),e=(a("./Shape"),a("./Convex"));b.exports=c,c.prototype=new e,c.prototype.computeMomentOfInertia=function(a){var b=this.width,c=this.height;return a*(c*c+b*b)/12},c.prototype.updateBoundingRadius=function(){var a=this.width,b=this.height;this.boundingRadius=Math.sqrt(a*a+b*b)/2}},{"../math/vec2":30,"./Convex":36,"./Shape":41}],41:[function(a,b){function c(a){this.type=a,this.boundingRadius=0,this.collisionGroup=1,this.collisionMask=1,a&&this.updateBoundingRadius(),this.material=null,this.area=0,this.updateArea()}b.exports=c,c.CIRCLE=1,c.PARTICLE=2,c.PLANE=4,c.CONVEX=8,c.LINE=16,c.RECTANGLE=32,c.CAPSULE=64,c.prototype.computeMomentOfInertia=function(){throw new Error("Shape.computeMomentOfInertia is not implemented in this Shape...")},c.prototype.updateBoundingRadius=function(){throw new Error("Shape.updateBoundingRadius is not implemented in this Shape...")},c.prototype.updateArea=function(){},c.prototype.computeAABB=function(){}},{}],42:[function(a,b){function c(a){e.call(this,a),a=a||{},this.iterations=a.iterations||10,this.tolerance=a.tolerance||0,this.debug=a.debug||!1,this.arrayStep=30,this.lambda=new f.ARRAY_TYPE(this.arrayStep),this.Bs=new f.ARRAY_TYPE(this.arrayStep),this.invCs=new f.ARRAY_TYPE(this.arrayStep),this.useGlobalEquationParameters=!0,this.stiffness=1e6,this.relaxation=4,this.useZeroRHS=!1,this.skipFrictionIterations=2}var d=a("../math/vec2"),e=a("./Solver"),f=a("../utils/Utils"),g=a("../constraints/FrictionEquation");b.exports=c,c.prototype=new e,c.prototype.solve=function(a,b){this.sortEquations();var e=0,h=this.iterations,i=this.skipFrictionIterations,j=this.tolerance*this.tolerance,k=this.equations,l=k.length,m=b.bodies,n=b.bodies.length,o=a,p=this.relaxation,q=this.stiffness,r=4/(o*o*q*(1+4*p)),s=4/(o*(1+4*p)),t=4*p/(1+4*p),u=this.useGlobalEquationParameters,v=(d.add,d.set,this.useZeroRHS);this.lambda.lengthe)){var D=u?r:A.eps,E=c.iterateEquation(G,A,D,x,w,y,v,a);0!==j&&(F+=Math.abs(E))}if(0!==j&&j>=F*F)break}for(z=0;z!==n;z++)m[z].addConstraintVelocity()}errorTot=F},c.iterateEquation=function(a,b,c,d,e,f,h,i){var j=d[a],k=e[a],l=f[a],m=b.computeGWlambda(c);b instanceof g&&(b.maxForce=b.contactEquation.multiplier*b.frictionCoefficient*i,b.minForce=-b.contactEquation.multiplier*b.frictionCoefficient*i);var n=b.maxForce,o=b.minForce;h&&(j=0);var p=k*(j-m-c*l),q=l+p;return o>q?p=o-l:q>n&&(p=n-l),f[a]+=p,b.multiplier=f[a]/i,b.addToWlambda(p),p}},{"../constraints/FrictionEquation":19,"../math/vec2":30,"../utils/Utils":46,"./Solver":45}],43:[function(a,b){function c(){this.equations=[],this.bodies=[]}b.exports=c,c.prototype.reset=function(){this.equations.length=this.bodies.length=0},c.prototype.getBodies=function(){for(var a=[],b=[],c=this.equations,d=0;d!==c.length;d++){var e=c[d];-1===b.indexOf(e.bi.id)&&(a.push(e.bi),b.push(e.bi.id)),-1===b.indexOf(e.bj.id)&&(a.push(e.bj),b.push(e.bj.id))}return a},c.prototype.solve=function(a,b){var c=[];b.removeAllEquations();for(var d=this.equations.length,e=0;e!==d;e++)b.addEquation(this.equations[e]);for(var f=this.getBodies(),g=f.length,e=0;e!==g;e++)c.push(f[e]);b.solve(a,{bodies:c})}},{}],44:[function(a,b){function c(a,b){f.call(this,b);this.subsolver=a,this.numIslands=0,this._nodePool=[],this.beforeSolveIslandEvent={type:"beforeSolveIsland",island:null}}function d(a){for(var b=a.length,c=0;c!==b;c++){var d=a[c];if(!(d.visited||d.body.motionState&i))return d}return!1}function e(a,b){var c=[];for(c.push(a),a.visited=!0,b(a);c.length;)for(var e,f=c.pop();e=d(f.children);)e.visited=!0,b(e),c.push(e)}var f=a("./Solver"),g=(a("../math/vec2"),a("../solver/Island")),h=a("../objects/Body"),i=h.STATIC;b.exports=c,c.prototype=new f,c.prototype.solve=function(a,b){function c(a){v.push(a.body);for(var b=a.eqs.length,c=0;c!==b;c++){var d=a.eqs[c];-1===u.indexOf(d)&&u.push(d)}}for(var f=[],h=b.bodies,i=this.equations,j=i.length,k=h.length,l=(this.subsolver,this._workers,this._workerData,this._workerIslandGroups,0);l!==k;l++)this._nodePool.length?f.push(this._nodePool.pop()):f.push({body:h[l],children:[],eqs:[],visited:!1});for(var l=0;l!==k;l++){var m=f[l];m.body=h[l],m.children.length=0,m.eqs.length=0,m.visited=!1}for(var n=0;n!==j;n++){var o=i[n],l=h.indexOf(o.bi),p=h.indexOf(o.bj),q=f[l],r=f[p];q.children.push(r),q.eqs.push(o),r.children.push(q),r.eqs.push(o)}for(var s,t=0,u=[],v=[],w=[];s=d(f);){var x=new g;u.length=0,v.length=0,e(s,c);for(var y=u.length,l=0;l!==y;l++){var o=u[l];x.equations.push(o)}t++,w.push(x)}this.numIslands=t;for(var z=this.beforeSolveIslandEvent,l=0;l0&&d.integrateBody(R,a)}for(var u=0;u!==n;u++)k[u].setZeroForce();if(h&&(e=c(),f.lastStepTime=e-b),this.emitImpactEvent)for(var S=this.impactEvent,u=0;u!==p.contactEquations.length;u++){var T=p.contactEquations[u];T.firstImpact&&(S.bodyA=T.bi,S.bodyB=T.bj,this.emit(S))}this.time+=a,this.emit(this.postStepEvent)};var E=g.create(),F=g.create();d.integrateBody=function(a,b){var c=a.invMass,d=a.force,e=a.position,f=a.velocity;a.fixedRotation||(a.angularVelocity+=a.angularForce*a.invInertia*b,a.angle+=a.angularVelocity*b),g.scale(E,d,b*c),g.add(f,E,f),g.scale(F,f,b),g.add(e,e,F)},d.runNarrowphase=function(a,b,c,d,e,f,h,i,j,k,l,m){if(0!==(c.collisionGroup&h.collisionMask)&&0!==(h.collisionGroup&c.collisionMask)){var n=b.invMass+f.invMass;n>0&&(n=1/n);var o=k*l*n;g.rotate(B,d,b.angle),g.rotate(C,i,f.angle),g.add(B,B,b.position),g.add(C,C,f.position);var p=e+b.angle,q=j+f.angle;a.enableFriction=k>0,a.slipForce=o,a.frictionCoefficient=k,a.restitution=m;var r=a[c.type|h.type];r&&(c.type=0;b--)this.removeConstraint(a[b]);for(var c=this.bodies,b=c.length-1;b>=0;b--)this.removeBody(c[b]);for(var d=this.springs,b=d.length-1;b>=0;b--)this.removeSpring(d[b]);for(var e=this.contactMaterials,b=e.length-1;b>=0;b--)this.removeContactMaterial(e[b])},d.prototype.clone=function(){var a=new d;return a.fromJSON(this.toJSON()),a};var G=g.create(),H=g.fromValues(0,0),I=g.fromValues(0,0);d.prototype.hitTest=function(a,b,c){c=c||0;var d=new p({position:a}),e=new n,f=a,i=0,k=G,o=H,q=I;d.addShape(e);for(var r=this.narrowphase,s=[],t=0,u=b.length;t!==u;t++)for(var v=b[t],w=0,x=v.shapes.length;w!==x;w++){var y=v.shapes[w],z=v.shapeOffsets[w]||o,A=v.shapeAngles[w]||0;g.rotate(k,z,v.angle),g.add(k,k,v.position);var B=A+v.angle;(y instanceof h&&r.circleParticle(v,y,k,B,d,e,f,i,!0)||y instanceof j&&r.particleConvex(d,e,f,i,v,y,k,B,!0)||y instanceof l&&r.particlePlane(d,e,f,i,v,y,k,B,!0)||y instanceof m&&r.particleCapsule(d,e,f,i,v,y,k,B,!0)||y instanceof n&&g.squaredLength(g.sub(q,k,a))