mirror of
https://github.com/photonstorm/phaser
synced 2024-11-27 07:01:20 +00:00
26 lines
No EOL
77 KiB
JavaScript
26 lines
No EOL
77 KiB
JavaScript
/**
|
|
* 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;g<d.length;g++)e(d[g]);return e}({1:[function(a,b,c){var d={},e=new Float32Array([1,0,0,1]);if(!f)var f=1e-6;d.create=function(){return new Float32Array(e)},d.clone=function(a){var b=new Float32Array(4);return b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b},d.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a[2]=b[2],a[3]=b[3],a},d.identity=function(a){return a[0]=1,a[1]=0,a[2]=0,a[3]=1,a},d.transpose=function(a,b){if(a===b){var c=b[1];a[1]=b[2],a[2]=c}else a[0]=b[0],a[1]=b[2],a[2]=b[1],a[3]=b[3];return a},d.invert=function(a,b){var c=b[0],d=b[1],e=b[2],f=b[3],g=c*f-e*d;return g?(g=1/g,a[0]=f*g,a[1]=-d*g,a[2]=-e*g,a[3]=c*g,a):null},d.adjoint=function(a,b){var c=b[0];return a[0]=b[3],a[1]=-b[1],a[2]=-b[2],a[3]=c,a},d.determinant=function(a){return a[0]*a[3]-a[2]*a[1]},d.multiply=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=c[0],i=c[1],j=c[2],k=c[3];return a[0]=d*h+e*j,a[1]=d*i+e*k,a[2]=f*h+g*j,a[3]=f*i+g*k,a},d.mul=d.multiply,d.rotate=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=Math.sin(c),i=Math.cos(c);return a[0]=d*i+e*h,a[1]=d*-h+e*i,a[2]=f*i+g*h,a[3]=f*-h+g*i,a},d.scale=function(a,b,c){var d=b[0],e=b[1],f=b[2],g=b[3],h=c[0],i=c[1];return a[0]=d*h,a[1]=e*i,a[2]=f*h,a[3]=g*i,a},d.str=function(a){return"mat2("+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+")"},"undefined"!=typeof c&&(c.mat2=d)},{}],2:[function(a,b,c){var d={};if(!e)var e=1e-6;d.create=function(){return new Float32Array(2)},d.clone=function(a){var b=new Float32Array(2);return b[0]=a[0],b[1]=a[1],b},d.fromValues=function(a,b){var c=new Float32Array(2);return c[0]=a,c[1]=b,c},d.copy=function(a,b){return a[0]=b[0],a[1]=b[1],a},d.set=function(a,b,c){return a[0]=b,a[1]=c,a},d.add=function(a,b,c){return a[0]=b[0]+c[0],a[1]=b[1]+c[1],a},d.subtract=function(a,b,c){return a[0]=b[0]-c[0],a[1]=b[1]-c[1],a},d.sub=d.subtract,d.multiply=function(a,b,c){return a[0]=b[0]*c[0],a[1]=b[1]*c[1],a},d.mul=d.multiply,d.divide=function(a,b,c){return a[0]=b[0]/c[0],a[1]=b[1]/c[1],a},d.div=d.divide,d.min=function(a,b,c){return a[0]=Math.min(b[0],c[0]),a[1]=Math.min(b[1],c[1]),a},d.max=function(a,b,c){return a[0]=Math.max(b[0],c[0]),a[1]=Math.max(b[1],c[1]),a},d.scale=function(a,b,c){return a[0]=b[0]*c,a[1]=b[1]*c,a},d.distance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1];return Math.sqrt(c*c+d*d)},d.dist=d.distance,d.squaredDistance=function(a,b){var c=b[0]-a[0],d=b[1]-a[1];return c*c+d*d},d.sqrDist=d.squaredDistance,d.length=function(a){var b=a[0],c=a[1];return Math.sqrt(b*b+c*c)},d.len=d.length,d.squaredLength=function(a){var b=a[0],c=a[1];return b*b+c*c},d.sqrLen=d.squaredLength,d.negate=function(a,b){return a[0]=-b[0],a[1]=-b[1],a},d.normalize=function(a,b){var c=b[0],d=b[1],e=c*c+d*d;return e>0&&(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;c<this.vertices.length;++c)(b[c][1]<b[a][1]||b[c][1]==b[a][1]&&b[c][0]>b[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)<d))return!1;return!0},c.prototype.copy=function(a,b,d){var e=d||new c;if(e.clear(),b>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;f<this.vertices.length;f++)e.vertices.push(this.vertices[f])}return e},c.prototype.getCutEdges=function(){for(var a=[],b=[],d=[],e=new c,f=Number.MAX_VALUE,g=0;g<this.vertices.length;++g)if(this.isReflex(g))for(var h=0;h<this.vertices.length;++h)if(this.canSee(g,h)){b=this.copy(g,h,e).getCutEdges(),d=this.copy(h,g,e).getCutEdges();for(var i=0;i<d.length;i++)b.push(d[i]);b.length<f&&(a=b,f=b.length,a.push([this.at(g),this.at(h)]))}return a},c.prototype.decomp=function(){var a=this.getCutEdges();return a.length>0?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;c<a.length;c++)for(var d=a[c],e=0;e<b.length;e++){var f=b[e],g=f.slice(d);if(g){b.splice(e,1),b.push(g[0],g[1]);break}}return b}var d=a,c=this.vertices.indexOf(d[0]),e=this.vertices.indexOf(d[1]);return-1!=c&&-1!=e?[this.copy(c,e),this.copy(e,c)]:!1},c.prototype.isSimple=function(){for(var a=this.vertices,b=0;b<a.length-1;b++)for(var c=0;b-1>c;c++)if(e.segmentsIntersect(a[b],a[b+1],a[c],a[c+1]))return!1;for(var b=1;b<a.length-2;b++)if(e.segmentsIntersect(a[0],a[a.length-1],a[b],a[b+1]))return!1;return!0},c.prototype.quickDecomp=function(a,b,e,g,h,i){h=h||100,i=i||0,g=g||25,a="undefined"!=typeof a?a:[],b=b||[],e=e||[];var j=[0,0],k=[0,0],l=[0,0],m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=new c,u=new c,v=this,w=this.vertices;if(w.length<3)return a;if(i++,i>h)return console.warn("quickDecomp: max level ("+h+") reached."),a;for(var x=0;x<this.vertices.length;++x)if(v.isReflex(x)){b.push(v.vertices[x]),m=n=Number.MAX_VALUE;for(var y=0;y<this.vertices.length;++y)f.left(v.at(x-1),v.at(x),v.at(y))&&f.rightOn(v.at(x-1),v.at(x),v.at(y-1))&&(l=d(v.at(x-1),v.at(x),v.at(y),v.at(y-1)),f.right(v.at(x+1),v.at(x),l)&&(o=f.sqdist(v.vertices[x],l),n>o&&(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.length<u.vertices.length?(t.quickDecomp(a,b,e,g,h,i),u.quickDecomp(a,b,e,g,h,i)):(u.quickDecomp(a,b,e,g,h,i),t.quickDecomp(a,b,e,g,h,i)),a}return a.push(this),a},c.prototype.removeCollinearPoints=function(a){for(var b=0,c=this.vertices.length-1;this.vertices.length>3&&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)<c}},{}],7:[function(a,b){b.exports={Polygon:a("./Polygon"),Point:a("./Point")}},{"./Point":4,"./Polygon":5}],8:[function(a,b){b.exports={name:"p2",version:"0.4.0",description:"A JavaScript 2D physics engine.",author:"Stefan Hedman <schteppe@gmail.com> (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;N<M.length;N++){var O=M[N];f(J,O,A);var P=h(J,K);if(0>P){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)<C+n){e.scale(K,O,Y),f(M,H,K),e.scale(L,O,h(O,W)),e.normalize(L,L),e.scale(L,L,n),g(M,M,L);var Z=h(Q,M),$=h(Q,R),_=h(Q,S);if(Z>$&&_>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;cb<bb.length;cb++){var db=bb[cb];if(f(V,db,H),e.squaredLength(V)<(C+n)*(C+n)){if(m)return!0;var ab=this.createContactEquation(I,F,b,j);return e.copy(ab.ni,V),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,db,G),e.scale(X,ab.ni,-n),g(ab.rj,ab.rj,X),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}}return!1},c.prototype[m.CIRCLE|m.CAPSULE]=c.prototype.circleCapsule=function(a,b,c,d,e,f,g,h,i){return this.circleLine(a,b,c,d,e,f,g,h,i,f.radius)},c.prototype[m.CIRCLE|m.CONVEX]=c.prototype.circleConvex=function(a,b,c,h,i,j,k,l,m,n){var t=j,u=l,v=i,w=k,z=c,E=a,F=b,n="number"==typeof n?n:F.radius,G=o,H=p,I=q,J=r,K=s,L=x,M=y,N=A,O=B,P=C,Q=D,R=!1,S=Number.MAX_VALUE;verts=t.vertices;for(var T=0;T!==verts.length;T++){var U=verts[T],V=verts[(T+1)%verts.length];if(e.rotate(G,U,u),e.rotate(H,V,u),g(G,G,w),g(H,H,w),f(I,H,G),e.normalize(J,I),e.rotate(K,J,-Math.PI/2),e.scale(O,K,-F.radius),g(O,O,z),d(O,t,w,u)){e.sub(P,G,O);var W=Math.abs(e.dot(P,K));S>W&&(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;T<verts.length;T++){var Y=verts[T];if(e.rotate(M,Y,u),g(M,M,w),f(L,M,z),e.squaredLength(L)<n*n){if(m)return!0;var X=this.createContactEquation(E,v,b,j);return e.copy(X.ni,L),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,M,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}}return!1};var G=e.create(),H=e.create(),I=e.create(),J=e.create();c.prototype[m.PARTICLE|m.CONVEX]=c.prototype.particleConvex=function(a,b,c,i,j,k,l,m){var n=k,v=m,w=j,y=l,z=c,B=a,C=o,D=p,G=q,H=r,I=s,J=t,K=u,L=x,M=A,N=E,O=F,P=Number.MAX_VALUE,Q=!1,R=n.vertices;if(!d(z,n,y,v))return!1;for(var S=0;S!==R.length+1;S++){var T=R[S%R.length],U=R[(S+1)%R.length];e.rotate(C,T,v),e.rotate(D,U,v),g(C,C,y),g(D,D,y),f(G,D,C),e.normalize(H,G),e.rotate(I,H,-Math.PI/2),f(L,z,C);{h(L,I)}f(J,C,y),f(K,z,y),e.sub(N,C,z);var V=Math.abs(e.dot(N,I));P>V&&(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<s.vertices.length;C++){var D=s.vertices[C];if(e.rotate(y,D,t),g(y,y,r),f(A,y,w),h(A,z)<0){B++;var E=this.createContactEquation(u,m,v,s);f(A,y,w),e.copy(E.ni,z);var F=h(A,E.ni);if(e.scale(A,E.ni,F),f(E.rj,y,m.position),f(E.ri,y,A),f(E.ri,E.ri,u.position),this.contactEquations.push(E),this.enableFriction&&this.frictionEquations.push(this.createFrictionFromContact(E)),B>=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;m<a.vertices.length;m++)g=a.vertices[m],i=h(g,l),(null===j||i>j)&&(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.depth<this.maxDepth&&d>this.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;c<this.concavePath.length;c++){var h=[0,0];d.copy(h,this.concavePath[c]),this.concavePath[c]=h}var i;i=b.optimalDecomp?g.decomp():g.quickDecomp();for(var j=d.create(),c=0;c!==i.length;c++){for(var k=new f(i[c].vertices),l=0;l!==k.vertices.length;l++){var h=k.vertices[l];d.sub(h,h,k.centerOfMass)}d.scale(j,k.centerOfMass,1),k.updateTriangles(),k.updateCenterOfMass(),k.updateBoundingRadius(),this.addShape(k,j)}return this.adjustCenterOfMass(),!0};var i=d.fromValues(0,0),j=d.fromValues(0,0),k=d.fromValues(0,0),l=d.fromValues(0,0);c.prototype.adjustCenterOfMass=function(){var a=i,b=j,c=k,e=l,f=0;d.set(c,0,0),d.set(a,0,0);for(var g=0;g!==this.shapes.length;g++){var h=this.shapes[g],m=this.shapeOffsets[g]||a;d.scale(b,m,h.area),d.add(c,c,b),f+=h.area}d.scale(e,c,1/f);for(var g=0;g!==this.shapes.length;g++){var h=this.shapes[g],m=this.shapeOffsets[g];m||(m=this.shapeOffsets[g]=d.create()),d.sub(m,m,e)}d.add(this.position,this.position,e);for(var g=0;this.concavePath&&g<this.concavePath.length;g++)d.sub(this.concavePath[g],this.concavePath[g],e);this.updateMassProperties(),this.updateBoundingRadius()},c.prototype.setZeroForce=function(){d.set(this.force,0,0),this.angularForce=0},c.prototype.resetConstraintVelocity=function(){var a=this,b=a.vlambda;d.set(b,0,0),a.wlambda=0},c.prototype.addConstraintVelocity=function(){var a=this,b=a.velocity;d.add(b,b,a.vlambda),a.angularVelocity+=a.wlambda},c.prototype.applyDamping=function(a){if(this.motionState&c.DYNAMIC){a!=this.lastDampingTimeStep&&(this.lastDampingScale=Math.pow(1-this.damping,a),this.lastAngularDampingScale=Math.pow(1-this.angularDamping,a),this.lastDampingTimeStep=a);var b=this.velocity;d.scale(b,b,this.lastDampingScale),this.angularVelocity*=this.lastAngularDampingScale}},c.DYNAMIC=1,c.STATIC=2,c.KINEMATIC=4},{"../math/vec2":30,"../shapes/Convex":36,"poly-decomp":7}],32:[function(a,b){function c(a,b,c){c=c||{},this.restLength="number"==typeof c.restLength?c.restLength:1,this.stiffness=c.stiffness||100,this.damping=c.damping||1,this.bodyA=a,this.bodyB=b,this.localAnchorA=d.fromValues(0,0),this.localAnchorB=d.fromValues(0,0),c.localAnchorA&&d.copy(this.localAnchorA,c.localAnchorA),c.localAnchorB&&d.copy(this.localAnchorB,c.localAnchorB),c.worldAnchorA&&this.setWorldAnchorA(c.worldAnchorA),c.worldAnchorB&&this.setWorldAnchorB(c.worldAnchorB)}var d=a("../math/vec2");b.exports=c,c.prototype.setWorldAnchorA=function(a){this.bodyA.toLocalFrame(this.localAnchorA,a)},c.prototype.setWorldAnchorB=function(a){this.bodyB.toLocalFrame(this.localAnchorB,a)},c.prototype.getWorldAnchorA=function(a){this.bodyA.toWorldFrame(a,this.localAnchorA)},c.prototype.getWorldAnchorB=function(a){this.bodyB.toWorldFrame(a,this.localAnchorB)};var e=d.create(),f=d.create(),g=d.create(),h=d.create(),i=d.create(),j=d.create(),k=d.create(),l=d.create(),m=d.create();c.prototype.applyForce=function(){var a=this.stiffness,b=this.damping,c=this.restLength,n=this.bodyA,o=this.bodyB,p=e,q=f,r=g,s=h,t=m,u=i,v=j,w=k,x=l;this.getWorldAnchorA(u),this.getWorldAnchorB(v),d.sub(w,u,n.position),d.sub(x,v,o.position),d.sub(p,v,u);var y=d.len(p);d.normalize(q,p),d.sub(r,o.velocity,n.velocity),d.crossZV(t,o.angularVelocity,x),d.add(r,r,t),d.crossZV(t,n.angularVelocity,w),d.sub(r,r,t),d.scale(s,q,-a*(y-c)-b*d.dot(r,q)),d.sub(n.force,n.force,s),d.add(o.force,o.force,s);var z=d.crossLength(w,s),A=d.crossLength(x,s);n.angularForce-=z,o.angularForce+=A}},{"../math/vec2":30}],33:[function(a,b){b.exports={Body:a("./objects/Body"),Broadphase:a("./collision/Broadphase"),Capsule:a("./shapes/Capsule"),Circle:a("./shapes/Circle"),Constraint:a("./constraints/Constraint"),ContactEquation:a("./constraints/ContactEquation"),ContactMaterial:a("./material/ContactMaterial"),Convex:a("./shapes/Convex"),DistanceConstraint:a("./constraints/DistanceConstraint"),Equation:a("./constraints/Equation"),EventEmitter:a("./events/EventEmitter"),FrictionEquation:a("./constraints/FrictionEquation"),GridBroadphase:a("./collision/GridBroadphase"),GSSolver:a("./solver/GSSolver"),Island:a("./solver/IslandSolver"),IslandSolver:a("./solver/IslandSolver"),Line:a("./shapes/Line"),LockConstraint:a("./constraints/LockConstraint"),Material:a("./material/Material"),NaiveBroadphase:a("./collision/NaiveBroadphase"),Particle:a("./shapes/Particle"),Plane:a("./shapes/Plane"),RevoluteConstraint:a("./constraints/RevoluteConstraint"),PrismaticConstraint:a("./constraints/PrismaticConstraint"),Rectangle:a("./shapes/Rectangle"),RotationalVelocityEquation:a("./constraints/RotationalVelocityEquation"),SAP1DBroadphase:a("./collision/SAP1DBroadphase"),Shape:a("./shapes/Shape"),Solver:a("./solver/Solver"),Spring:a("./objects/Spring"),Utils:a("./utils/Utils"),World:a("./world/World"),QuadTree:a("./collision/QuadTree").QuadTree,vec2:a("./math/vec2"),version:a("../package.json").version}},{"../package.json":8,"./collision/Broadphase":9,"./collision/GridBroadphase":10,"./collision/NaiveBroadphase":11,"./collision/QuadTree":13,"./collision/SAP1DBroadphase":14,"./constraints/Constraint":15,"./constraints/ContactEquation":16,"./constraints/DistanceConstraint":17,"./constraints/Equation":18,"./constraints/FrictionEquation":19,"./constraints/LockConstraint":20,"./constraints/PrismaticConstraint":21,"./constraints/RevoluteConstraint":22,"./constraints/RotationalVelocityEquation":24,"./events/EventEmitter":25,"./material/ContactMaterial":26,"./material/Material":27,"./math/vec2":30,"./objects/Body":31,"./objects/Spring":32,"./shapes/Capsule":34,"./shapes/Circle":35,"./shapes/Convex":36,"./shapes/Line":37,"./shapes/Particle":38,"./shapes/Plane":39,"./shapes/Rectangle":40,"./shapes/Shape":41,"./solver/GSSolver":42,"./solver/IslandSolver":44,"./solver/Solver":45,"./utils/Utils":46,"./world/World":47}],34:[function(a,b){function c(a,b){this.length=a||1,this.radius=b||1,d.call(this,d.CAPSULE)}{var d=a("./Shape");a("../math/vec2")}b.exports=c,c.prototype=new d,c.prototype.computeMomentOfInertia=function(a){var b=this.radius,c=this.length+b,d=2*b;return a*(d*d+c*c)/12},c.prototype.updateBoundingRadius=function(){this.boundingRadius=this.radius+this.length/2}},{"../math/vec2":30,"./Shape":41}],35:[function(a,b){function c(a){this.radius=a||1,d.call(this,d.CIRCLE)}var d=a("./Shape");b.exports=c,c.prototype=new d,c.prototype.computeMomentOfInertia=function(a){var b=this.radius;return a*b*b/2},c.prototype.updateBoundingRadius=function(){this.boundingRadius=this.radius}},{"./Shape":41}],36:[function(a,b){function c(a){this.vertices=a||[];for(var b=0;b<this.vertices.length;b++){var c=e.fromValues();e.copy(c,this.vertices[b]),this.vertices[b]=c}this.centerOfMass=e.fromValues(0,0),this.triangles=[],this.vertices.length&&(this.updateTriangles(),this.updateCenterOfMass()),this.boundingRadius=0,this.updateBoundingRadius(),d.call(this,d.CONVEX)}var d=a("./Shape"),e=a("../math/vec2"),f=a("../math/polyk"),g=a("poly-decomp");b.exports=c,c.prototype=new d,c.prototype.updateTriangles=function(){this.triangles.length=0;for(var a=[],b=0;b<this.vertices.length;b++){var c=this.vertices[b];a.push(c[0],c[1])}for(var d=f.Triangulate(a),b=0;b<d.length;b+=3){var e=d[b],g=d[b+1],h=d[b+2];this.triangles.push([e,g,h])}};{var h=e.create(),i=e.create(),j=e.create(),k=e.create(),l=e.create();e.create(),e.create(),e.create(),e.create()}c.prototype.updateCenterOfMass=function(){var a=this.triangles,b=this.vertices,c=this.centerOfMass,d=h,f=j,m=k,n=l,o=i;e.set(c,0,0);for(var p=0,q=0;q!==a.length;q++){var r=a[q],f=b[r[0]],m=b[r[1]],n=b[r[2]];e.centroid(d,f,m,n);var s=g.Point.area(f,m,n);p+=s,e.scale(o,d,s),e.add(c,c,o)}e.scale(c,c,1/p)},c.prototype.computeMomentOfInertia=function(a){for(var b=0,c=[],d=0;d<this.vertices.length;d++){var h=this.vertices[d];c.push(h[0],h[1])}{var i=f.Triangulate(c);f.GetArea(c)}this.updateArea();for(var j=a/this.area,k=e.create(),l=e.create(),m=e.create(),n=e.create(),o=(e.create(),e.create(),e.create()),p=e.create(),d=(e.create(),0);d<i.length;d+=3){var q=i[d],r=i[d+1],s=i[d+2];e.set(k,c[2*q],c[2*q+1]),e.set(l,c[2*r],c[2*r+1]),e.set(m,c[2*s],c[2*s+1]),e.centroid(n,k,l,m),e.sub(o,m,k),e.sub(p,m,l);var t=g.Point.area(k,l,m),u=e.length(o),v=2*t/u,w=t*j,x=w*u*Math.pow(v,3)/36,y=e.squaredLength(n);b+=x+w*y}return b},c.prototype.updateBoundingRadius=function(){for(var a=this.vertices,b=0,c=0;c!==a.length;c++){var d=e.squaredLength(a[c]);d>b&&(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.length<l&&(this.lambda=new f.ARRAY_TYPE(l+this.arrayStep),this.Bs=new f.ARRAY_TYPE(l+this.arrayStep),this.invCs=new f.ARRAY_TYPE(l+this.arrayStep));for(var w=this.invCs,x=this.Bs,y=this.lambda,z=0;z!==l;z++){var A=k[z];y[z]=0;var B=s,C=t,D=r;u||(o!==A.h&&A.updateSpookParams(o),B=A.a,C=A.b,D=A.eps),x[z]=A.computeB(B,C,o),w[z]=1/A.computeC(D)}var A,E,F;if(0!==l){var z,G;for(z=0;z!==n;z++)m[z].resetConstraintVelocity();for(e=0;e!==h;e++){for(F=0,G=0;G!==l;G++)if(A=k[G],!(A instanceof g&&i>e)){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;l<w.length;l++){var x=w[l];z.island=x,this.emit(z),x.solve(a,this.subsolver)}}},{"../math/vec2":30,"../objects/Body":31,"../solver/Island":43,"./Solver":45}],45:[function(a,b){function c(a){a=a||{},e.call(this),this.equations=[],this.equationSortFunction=a.equationSortFunction||!1}var d=a("../utils/Utils"),e=a("../events/EventEmitter");b.exports=c,c.prototype=new e,c.prototype.solve=function(){throw new Error("Solver.solve should be implemented by subclasses!")},c.prototype.sortEquations=function(){this.equationSortFunction&&this.equations.sort(this.equationSortFunction)
|
|
},c.prototype.addEquation=function(a){this.equations.push(a)},c.prototype.addEquations=function(a){d.appendArray(this.equations,a)},c.prototype.removeEquation=function(a){var b=this.equations.indexOf(a);-1!=b&&this.equations.splice(b,1)},c.prototype.removeAllEquations=function(){this.equations.length=0}},{"../events/EventEmitter":25,"../utils/Utils":46}],46:[function(a,b){function c(){}b.exports=c,c.appendArray=function(a,b){if(b.length<15e4)a.push.apply(a,b);else for(var c=0,d=b.length;c!==d;++c)a.push(b[c])},c.ARRAY_TYPE=Float32Array||Array},{}],47:[function(a,b){function c(){return"undefined"==typeof performance?(new Date).getTime():performance.now?performance.now():performance.webkitNow?performance.webkitNow():void 0}function d(a){o.apply(this),a=a||{},this.springs=[],this.bodies=[],this.solver=a.solver||new e,this.narrowphase=new y,this.gravity=a.gravity||g.fromValues(0,-9.78),this.doProfiling=a.doProfiling||!1,this.lastStepTime=0,this.broadphase=a.broadphase||new f,this.constraints=[],this.defaultFriction=.3,this.lastTimeStep=1/60,this.applySpringForces=!0,this.applyDamping=!0,this.solveConstraints=!0,this.contactMaterials=[],this.time=0,this.emitImpactEvent=!0,this._constraintIdCounter=0,this._bodyIdCounter=0,this.postStepEvent={type:"postStep"},this.addBodyEvent={type:"addBody",body:null},this.removeBodyEvent={type:"removeBody",body:null},this.addSpringEvent={type:"addSpring",spring:null},this.impactEvent={type:"impact",bodyA:null,bodyB:null}}var e=a("../solver/GSSolver"),f=a("../collision/NaiveBroadphase"),g=a("../math/vec2"),h=a("../shapes/Circle"),i=a("../shapes/Rectangle"),j=a("../shapes/Convex"),k=a("../shapes/Line"),l=a("../shapes/Plane"),m=a("../shapes/Capsule"),n=a("../shapes/Particle"),o=a("../events/EventEmitter"),p=a("../objects/Body"),q=a("../objects/Spring"),r=a("../material/Material"),s=a("../material/ContactMaterial"),t=a("../constraints/DistanceConstraint"),u=a("../constraints/LockConstraint"),v=a("../constraints/RevoluteConstraint"),w=a("../constraints/PrismaticConstraint"),x=a("../../package.json"),y=(a("../collision/Broadphase"),a("../collision/Narrowphase"));b.exports=d;var z=x.version.split(".").slice(0,2).join(".");d.prototype=new Object(o.prototype),d.prototype.addConstraint=function(a){this.constraints.push(a)},d.prototype.addContactMaterial=function(a){this.contactMaterials.push(a)},d.prototype.removeContactMaterial=function(a){var b=this.contactMaterials.indexOf(a);-1!==b&&this.contactMaterials.splice(b,1)},d.prototype.getContactMaterial=function(a,b){for(var c=this.contactMaterials,d=0,e=c.length;d!==e;d++){var f=c[d];if(f.materialA===a&&f.materialB===b||f.materialA===b&&f.materialB===a)return f}return!1},d.prototype.removeConstraint=function(a){var b=this.constraints.indexOf(a);-1!==b&&this.constraints.splice(b,1)};var A=(g.create(),g.create(),g.create(),g.create(),g.create(),g.create(),g.create()),B=g.fromValues(0,0),C=g.fromValues(0,0),D=g.fromValues(0,0);d.prototype.step=function(a){{var b,e,f=this,h=this.doProfiling,i=this.springs.length,j=this.springs,k=this.bodies,l=this.gravity,m=this.solver,n=this.bodies.length,o=this.broadphase,p=this.narrowphase,q=this.constraints,r=A,s=(g.scale,g.add);g.rotate}this.lastTimeStep=a,h&&(b=c());var t=g.length(l);if(0!==t)for(var u=0;u!==n;u++){var v=k[u],w=v.force;g.scale(r,l,v.mass),s(w,w,r)}if(this.applySpringForces)for(var u=0;u!==i;u++){var x=j[u];x.applyForce()}if(this.applyDamping)for(var u=0;u!==n;u++){var v=k[u];v.applyDamping(a)}var y=o.getCollisionPairs(this);p.reset();for(var u=0,z=y.length;u!==z;u+=2)for(var B=y[u],C=y[u+1],E=0;E!==B.shapes.length;E++)for(var F=B.shapes[E],G=B.shapeOffsets[E]||D,H=B.shapeAngles[E]||0,I=0;I!==C.shapes.length;I++){var J=C.shapes[I],K=C.shapeOffsets[I]||D,L=C.shapeAngles[I]||0,M=this.defaultFriction,N=0;if(F.material&&J.material){var O=this.getContactMaterial(F.material,J.material);O&&(M=O.friction,N=O.restitution)}d.runNarrowphase(p,B,F,G,H,C,J,K,L,M,t,N)}m.addEquations(p.contactEquations),m.addEquations(p.frictionEquations);var P=q.length;for(u=0;u!==P;u++){var Q=q[u];Q.update(),m.addEquations(Q.equations)}this.solveConstraints&&m.solve(a,this),m.removeAllEquations();for(var u=0;u!==n;u++){var R=k[u];R.mass>0&&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<h.type?r.call(a,b,c,B,p,f,h,C,q):r.call(a,f,h,C,q,b,c,B,p))}},d.prototype.addSpring=function(a){this.springs.push(a),this.addSpringEvent.spring=a,this.emit(this.addSpringEvent)},d.prototype.removeSpring=function(a){var b=this.springs.indexOf(a);-1===b&&this.springs.splice(b,1)},d.prototype.addBody=function(a){this.bodies.push(a),this.addBodyEvent.body=a,this.emit(this.addBodyEvent)},d.prototype.removeBody=function(a){var b=this.bodies.indexOf(a);-1!==b&&(this.bodies.splice(b,1),this.removeBodyEvent.body=a,a.resetConstraintVelocity(),this.emit(this.removeBodyEvent))},d.prototype.getBodyById=function(a){for(var b=this.bodies,c=0;c<b.length;c++){var d=b[c];if(d.id===a)return d}return!1},d.prototype.toJSON=function(){function a(a){return a?[a[0],a[1]]:a}for(var b={p2:z,bodies:[],springs:[],solver:{},gravity:a(this.gravity),broadphase:{},constraints:[],contactMaterials:[]},c=0;c!==this.springs.length;c++){var d=this.springs[c];b.springs.push({bodyA:this.bodies.indexOf(d.bodyA),bodyB:this.bodies.indexOf(d.bodyB),stiffness:d.stiffness,damping:d.damping,restLength:d.restLength,localAnchorA:a(d.localAnchorA),localAnchorB:a(d.localAnchorB)})}for(var c=0;c<this.constraints.length;c++){var e=this.constraints[c],f={bodyA:this.bodies.indexOf(e.bodyA),bodyB:this.bodies.indexOf(e.bodyB)};if(e instanceof t)f.type="DistanceConstraint",f.distance=e.distance,f.maxForce=e.getMaxForce();else if(e instanceof v)f.type="RevoluteConstraint",f.pivotA=a(e.pivotA),f.pivotB=a(e.pivotB),f.maxForce=e.maxForce,f.motorSpeed=e.getMotorSpeed(),f.lowerLimit=e.lowerLimit,f.lowerLimitEnabled=e.lowerLimitEnabled,f.upperLimit=e.upperLimit,f.upperLimitEnabled=e.upperLimitEnabled;else if(e instanceof w)f.type="PrismaticConstraint",f.localAxisA=a(e.localAxisA),f.localAnchorA=a(e.localAnchorA),f.localAnchorB=a(e.localAnchorB),f.maxForce=e.maxForce;else{if(!(e instanceof u)){console.error("Constraint not supported yet!");continue}f.type="LockConstraint",f.localOffsetB=a(e.localOffsetB),f.localAngleB=e.localAngleB,f.maxForce=e.maxForce}b.constraints.push(f)}for(var c=0;c!==this.bodies.length;c++){for(var g=this.bodies[c],o=g.shapes,p=[],q=0;q<o.length;q++){var r,d=o[q];if(d instanceof h)r={type:"Circle",radius:d.radius};else if(d instanceof l)r={type:"Plane"};else if(d instanceof n)r={type:"Particle"};else if(d instanceof k)r={type:"Line",length:d.length};else if(d instanceof i)r={type:"Rectangle",width:d.width,height:d.height};else if(d instanceof j){for(var s=[],x=0;x<d.vertices.length;x++)s.push(a(d.vertices[x]));r={type:"Convex",verts:s}}else{if(!(d instanceof m))throw new Error("Shape type not supported yet!");r={type:"Capsule",length:d.length,radius:d.radius}}r.offset=a(g.shapeOffsets[q]),r.angle=g.shapeAngles[q],r.collisionGroup=d.collisionGroup,r.collisionMask=d.collisionMask,r.material=d.material&&{id:d.material.id},p.push(r)}b.bodies.push({id:g.id,mass:g.mass,angle:g.angle,position:a(g.position),velocity:a(g.velocity),angularVelocity:g.angularVelocity,force:a(g.force),shapes:p,concavePath:g.concavePath})}for(var c=0;c<this.contactMaterials.length;c++){var y=this.contactMaterials[c];b.contactMaterials.push({id:y.id,materialA:y.materialA.id,materialB:y.materialB.id,friction:y.friction,restitution:y.restitution,stiffness:y.stiffness,relaxation:y.relaxation,frictionStiffness:y.frictionStiffness,frictionRelaxation:y.frictionRelaxation})}return b},d.upgradeJSON=function(a){if(!a||!a.p2)return!1;switch(a=JSON.parse(JSON.stringify(a)),a.p2){case z:return a;case"0.3":for(var b=0;b<a.constraints.length;b++){var c=a.constraints[b];"PrismaticConstraint"==c.type&&(delete c.localAxisA,delete c.localAxisB,c.localAxisA=[1,0],c.localAnchorA=[0,0],c.localAnchorB=[0,0])}a.p2="0.4"}return d.upgradeJSON(a)},d.prototype.fromJSON=function(a){if(this.clear(),a=d.upgradeJSON(a),!a)return!1;if(!a.p2)return!1;g.copy(this.gravity,a.gravity);for(var b=this.bodies,c={},e=0;e!==a.bodies.length;e++){var f=a.bodies[e],o=f.shapes,x=new p({mass:f.mass,position:f.position,angle:f.angle,velocity:f.velocity,angularVelocity:f.angularVelocity,force:f.force});x.id=f.id;for(var y=0;y<o.length;y++){var z,A=o[y];switch(A.type){case"Circle":z=new h(A.radius);break;case"Plane":z=new l;break;case"Particle":z=new n;break;case"Line":z=new k(A.length);break;case"Rectangle":z=new i(A.width,A.height);break;case"Convex":z=new j(A.verts);break;case"Capsule":z=new m(A.length,A.radius);break;default:throw new Error("Shape type not supported: "+A.type)}z.collisionMask=A.collisionMask,z.collisionGroup=A.collisionGroup,z.material=A.material,z.material&&(z.material=new r,z.material.id=A.material.id,c[z.material.id+""]=z.material),x.addShape(z,A.offset,A.angle)}f.concavePath&&(x.concavePath=f.concavePath),this.addBody(x)}for(var e=0;e<a.springs.length;e++){var A=a.springs[e],B=new q(b[A.bodyA],b[A.bodyB],{stiffness:A.stiffness,damping:A.damping,restLength:A.restLength,localAnchorA:A.localAnchorA,localAnchorB:A.localAnchorB});this.addSpring(B)}for(var e=0;e<a.contactMaterials.length;e++){var C=a.contactMaterials[e],D=new s(c[C.materialA+""],c[C.materialB+""],{friction:C.friction,restitution:C.restitution,stiffness:C.stiffness,relaxation:C.relaxation,frictionStiffness:C.frictionStiffness,frictionRelaxation:C.frictionRelaxation});D.id=C.id,this.addContactMaterial(D)}for(var e=0;e<a.constraints.length;e++){var E,F=a.constraints[e];switch(F.type){case"DistanceConstraint":E=new t(b[F.bodyA],b[F.bodyB],F.distance,F.maxForce);break;case"RevoluteConstraint":E=new v(b[F.bodyA],F.pivotA,b[F.bodyB],F.pivotB,F.maxForce),F.motorSpeed&&(E.enableMotor(),E.setMotorSpeed(F.motorSpeed)),E.lowerLimit=F.lowerLimit||0,E.upperLimit=F.upperLimit||0,E.lowerLimitEnabled=F.lowerLimitEnabled||!1,E.upperLimitEnabled=F.upperLimitEnabled||!1;break;case"PrismaticConstraint":E=new w(b[F.bodyA],b[F.bodyB],{maxForce:F.maxForce,localAxisA:F.localAxisA,localAnchorA:F.localAnchorA,localAnchorB:F.localAnchorB});break;case"LockConstraint":E=new u(b[F.bodyA],b[F.bodyB],{maxForce:F.maxForce,localOffsetB:F.localOffsetB,localAngleB:F.localAngleB});break;default:throw new Error("Constraint type not recognized: "+F.type)}this.addConstraint(E)}return!0},d.prototype.clear=function(){this.time=0,this.solver&&this.solver.equations.length&&this.solver.removeAllEquations();for(var a=this.constraints,b=a.length-1;b>=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))<c*c)&&s.push(v)}return s}},{"../../package.json":8,"../collision/Broadphase":9,"../collision/NaiveBroadphase":11,"../collision/Narrowphase":12,"../constraints/DistanceConstraint":17,"../constraints/LockConstraint":20,"../constraints/PrismaticConstraint":21,"../constraints/RevoluteConstraint":22,"../events/EventEmitter":25,"../material/ContactMaterial":26,"../material/Material":27,"../math/vec2":30,"../objects/Body":31,"../objects/Spring":32,"../shapes/Capsule":34,"../shapes/Circle":35,"../shapes/Convex":36,"../shapes/Line":37,"../shapes/Particle":38,"../shapes/Plane":39,"../shapes/Rectangle":40,"../solver/GSSolver":42}]},{},[33])(33)}); |