This repository has been archived by the owner on Jun 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
von-physics2.min.js
1 lines (1 loc) · 24.7 KB
/
von-physics2.min.js
1
(function(){var t=this,i={Boundary:{BOUNDARY_DISABLE:"disable",BOUNDARY_BOUNCE:"bounce",BOUNDARY_WRAP:"wrap"},Type:{AABB2:"AABB2",AABB3:"AABB3",CIRCLE:"Circle",SPHERE:"Sphere"}};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=i),exports.vgp=i):"undefined"!=typeof define&&define.amd?define(i):t.vgp=i}).call(this),vgp.utils={PI:Math.PI,TAU:2*Math.PI,DEG_TO_RAD:.0174532925,RAD_TO_DEG:57.2957795,clamp:function(t,i,s){return Math.max(i,Math.min(s,t))},sign:function(t){return t&&t/Math.abs(t)},random:function(t,i){return 1===arguments.length?Math.random()*t-.5*t:Math.random()*(i-t)+t},randomInt:function(t,i){return 1===arguments.length?Math.random()*t-.5*t|0:Math.random()*(i-t+1)+t|0},normalize:function(t,i,s){return(t-i)/(s-i)},getShortRotation:function(t){return t%=this.TAU,t>this.PI?t-=this.TAU:t<-this.PI&&(t+=this.TAU),t},generateID:function(){return Math.random().toString(36).slice(2)+Date.now()},isPlainObject:function(t){if("object"!=typeof t||t.nodeType||t===t.window)return!1;try{if(t.constructor&&!Object.prototype.hasOwnProperty.call(t.constructor.prototype,"isPrototypeOf"))return!1}catch(i){return!1}return!0},merge:function(){var t,i,s,e,n,o,h=arguments[0]||{},r=1,a=arguments.length,l=!1;for("boolean"==typeof h&&(l=h,h=arguments[1]||{},r=2);a>r;r++)if(null!==(t=arguments[r]))for(i in t)s=h[i],e=t[i],h!==e&&(l&&e&&(this.isPlainObject(e)||(n=Array.isArray(e)))?(n?(n=!1,o=s&&Array.isArray(s)?s:[]):o=s&&this.isPlainObject(s)?s:{},h[i]=this.merge(l,o,e)):void 0!==e&&(h[i]=e));return h},now:function(){return window.nwf?window.nwf.system.Performance.elapsedTime:window.performance.now()},empty:function(t){for(;t.lastChild;)t.removeChild(t.lastChild)},getJSON:function(t,i,s){var e;if("undefined"!=typeof XMLHttpRequest)e=new XMLHttpRequest;else for(var n=["MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp.2.0","Microsoft.XmlHttp"],o=0,h=n.length;h>o;o++)try{e=new ActiveXObject(n[o]);break}catch(r){}e.onreadystatechange=function(){return this.readyState<4||200!==this.status?void console.warn("[Tools] Error - "+this.statusText+" - loading "+t):void i.call(s||this,JSON.parse(this.responseText))},e.open("GET",t,!0),e.send("")}},vgp.Vec=function(t,i){"undefined"==typeof t&&(t=0),"undefined"==typeof i&&(i=0),this.x=t,this.y=i},vgp.Vec.prototype.setLength=function(t){var i=this.getLength();return 0!==i&&t!==i&&this.multiplyScalar(t/i),this},vgp.Vec.prototype.getLength=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},vgp.Vec.prototype.getLengthSq=function(){return this.x*this.x+this.y*this.y},vgp.Vec.prototype.setAngle=function(t){var i=this.getLength();return this.x=Math.cos(t)*i,this.y=Math.sin(t)*i,this},vgp.Vec.prototype.getAngle=function(){return Math.atan2(this.y,this.x)},vgp.Vec.prototype.rotateBy=function(t){var i=this.x,s=this.y,e=Math.cos(t),n=Math.sin(t);return this.x=i*e-s*n,this.y=i*n+s*e,this},vgp.Vec.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},vgp.Vec.prototype.addScalar=function(t){return this.x+=t,this.y+=t,this},vgp.Vec.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this},vgp.Vec.prototype.subScalar=function(t){return this.x-=t,this.y-=t,this},vgp.Vec.prototype.multiply=function(t){return this.x*=t.x,this.y*=t.y,this},vgp.Vec.prototype.multiplyScalar=function(t){return this.x*=t,this.y*=t,this},vgp.Vec.prototype.divide=function(t){return 0===t.x||0===t.y?this:(this.x/=t.x,this.y/=t.y,this)},vgp.Vec.prototype.divideScalar=function(t){return 0===t?this:(this.x/=t,this.y/=t,this)},vgp.Vec.prototype.min=function(t){return this.x>t.x&&(this.x=t.x),this.y>t.y&&(this.y=t.y),this},vgp.Vec.prototype.max=function(t){return this.x<t.x&&(this.x=t.x),this.y<t.y&&(this.y=t.y),this},vgp.Vec.prototype.perp=function(){var t=-this.y;return this.y=this.x,this.x=t,this},vgp.Vec.prototype.negate=function(){return this.x=-this.x,this.y=-this.y,this},vgp.Vec.prototype.clamp=function(t,i){return this.x<t.x?this.x=t.x:this.x>i.x&&(this.x=i.x),this.y<t.y?this.y=t.y:this.y>i.y&&(this.y=i.y),this},vgp.Vec.prototype.dot=function(t){return this.x*t.x+this.y*t.y},vgp.Vec.prototype.crossProd=function(t){return this.x*t.y-this.y*t.x},vgp.Vec.prototype.truncate=function(t){var i=this.getLength();return 0===i||t>i?this:(this.x/=i,this.y/=i,this.multiplyScalar(t),this)},vgp.Vec.prototype.angleTo=function(t){var i=this.x-t.x,s=this.y-t.y;return Math.atan2(s,i)},vgp.Vec.prototype.distanceTo=function(t){var i=this.x-t.x,s=this.y-t.y;return Math.sqrt(i*i+s*s)},vgp.Vec.prototype.distanceToSquared=function(t){var i=this.x-t.x,s=this.y-t.y;return i*i+s*s},vgp.Vec.prototype.lerp=function(t,i){return this.x+=(t.x-this.x)*i,this.y+=(t.y-this.y)*i,this},vgp.Vec.prototype.normalize=function(){var t=this.getLength();return 0===t?this:(this.x/=t,this.y/=t,this)},vgp.Vec.prototype.set=function(t,i){return t=t?t:0,i=i?i:0,this.x=t,this.y=i,this},vgp.Vec.prototype.equals=function(t){return this.x===t.x&&this.y===t.y?!0:!1},vgp.Vec.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this},vgp.Vec.prototype.clone=function(){return new vgp.Vec(this.x,this.y)},vgp.Vec.prototype.draw=function(t,i,s,e){i=i?i:0,s=s?s:0,e=e?e:"rgb(0, 250, 0)",t.strokeStyle=e,t.beginPath(),t.moveTo(i,s),t.lineTo(this.x,this.y),t.stroke()},vgp.Vec.prototype.toString=function(){return"["+this.x+", "+this.y+"]"},vgp.Vec.draw=function(t,i,s,e,n,o){n=n||0,o=o||0,t.strokeStyle=e?e:"rgb(250, 10, 10)",t.beginPath(),t.moveTo(i.x+n,i.y+o),t.lineTo(s.x+n,s.y+o),t.stroke()},vgp.LinkedListNode=function(){this.obj=null,this.next=null,this.prev=null,this.free=!0},vgp.LinkedList=function(){this.first=null,this.last=null,this.length=0,this.objToNodeMap={},this.uniqueID=Date.now()+""+Math.floor(1e3*Math.random()),this.sortArray=[]},vgp.LinkedList.prototype={constructor:vgp.LinkedList,getNode:function(t){return this.objToNodeMap[t.uniqueID]},addNode:function(t){var i=new vgp.LinkedListNode;if(!t.uniqueID)try{t.uniqueID=LinkedList.generateID(),console.log("New ID: "+t.uniqueID)}catch(s){return console.error("[LinkedList.addNode] obj passed is immutable: cannot attach necessary identifier"),null}return i.obj=t,i.free=!1,this.objToNodeMap[t.uniqueID]=i,i},swapObjects:function(t,i){this.objToNodeMap[t.obj.uniqueID]=null,this.objToNodeMap[i.uniqueID]=t,t.obj=i},add:function(t){var i=this.objToNodeMap[t.uniqueID];if(i){if(i.free===!1)return;i.obj=t,i.free=!1,i.next=null,i.prev=null}else i=this.addNode(t);if(this.first){if(!this.last)throw new Error("[LinkedList.add] No last in the list -- that shouldn't happen here");this.last.next=i,i.prev=this.last,this.last=i,i.next=null}else this.first=i,this.last=i,i.next=null,i.prev=null;this.length++,this.showDebug&&this.dump("after add")},has:function(t){return!!this.objToNodeMap[t.uniqueID]},moveUp:function(t){this.dump("before move up");var i=this.getNode(t);if(!i)throw"Oops, trying to move an object that isn't in the list";if(i.prev){var s=i.prev,e=s.prev;i==this.last&&(this.last=s);var n=i.next;e&&(e.next=i),i.next=s,i.prev=s.prev,s.next=n,s.prev=i,this.first==s&&(this.first=i)}},moveDown:function(t){var i=this.getNode(t);if(!i)throw"Oops, trying to move an object that isn't in the list";if(i.next){var s=i.next;this.moveUp(s.obj),this.last==s&&(this.last=i)}},sort:function(t){var i,s,e=this.sortArray,n=this.first;for(e.length=0;n;)e.push(n.obj),n=n.next;for(this.clear(),e.sort(t),s=e.length,i=0;s>i;i++)this.add(e[i])},remove:function(t){var i=this.getNode(t);return!i||i.free?!1:(i.prev&&(i.prev.next=i.next),i.next&&(i.next.prev=i.prev),i.prev||(this.first=i.next),i.next||(this.last=i.prev),i.free=!0,i.prev=null,i.next=null,this.length--,!0)},shift:function(){var t=this.first;return 0===this.length?null:(t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.first=t.next,t.next||(this.last=null),t.free=!0,t.prev=null,t.next=null,this.length--,t.obj)},pop:function(){var t=this.last;return 0===this.length?null:(t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),this.last=t.prev,t.prev||(this.first=null),t.free=!0,t.prev=null,t.next=null,this.length--,t.obj)},concat:function(t){for(var i=t.first;i;)this.add(i.obj),i=i.next},clear:function(){for(var t=this.first;t;)t.free=!0,t.prev&&(t.prev.next=t.next),t.next&&(t.next.prev=t.prev),t=t.next;this.first=null,this.length=0},dispose:function(){for(var t=this.first;t;)t.obj=null,t=t.next;this.first=null,this.objToNodeMap=null},dump:function(t){console.log("===================="+t+"=====================");for(var i=this.first;i;)console.log("{"+i.obj.toString()+"} previous="+(i.prev?i.prev.obj:"NULL")),i=i.next();console.log("==================================="),console.log("Last: {"+(this.last?this.last.obj:"NULL")+"} First: {"+(this.first?this.first.obj:"NULL")+"}")}},vgp.LinkedList.generateID=function(){return Math.random().toString(36).slice(2)+Date.now()},function(){var t=function(t,i,s,e,n){this._listener=i,this._isOnce=s,this.context=e,this._signal=t,this._priority=n||0};t.prototype={active:!0,params:null,execute:function(t){var i,s;return this.active&&this._listener&&(s=this.params?this.params.concat(t):t,i=this._listener.apply(this.context,s),this._isOnce&&this.detach()),i},detach:function(){return this.isBound()?this._signal.remove(this._listener,this.context):null},isBound:function(){return!!this._signal&&!!this._listener},isOnce:function(){return this._isOnce},getListener:function(){return this._listener},getSignal:function(){return this._signal},_destroy:function(){delete this._signal,delete this._listener,delete this.context},toString:function(){return"[SignalBinding isOnce:"+this._isOnce+", isBound:"+this.isBound()+", active:"+this.active+"]"}},t.prototype.constructor=t;var i=function(){this._bindings=[],this._prevParams=null;var t=this;this.dispatch=function(){i.prototype.dispatch.apply(t,arguments)}};i.prototype={memorize:!1,_shouldPropagate:!0,active:!0,validateListener:function(t,i){if("function"!=typeof t)throw new Error("Signal: listener is a required param of {fn}() and should be a Function.".replace("{fn}",i))},_registerListener:function(i,s,e,n){var o,h=this._indexOfListener(i,e);if(-1!==h){if(o=this._bindings[h],o.isOnce()!==s)throw new Error("You cannot add"+(s?"":"Once")+"() then add"+(s?"Once":"")+"() the same listener without removing the relationship first.")}else o=new t(this,i,s,e,n),this._addBinding(o);return this.memorize&&this._prevParams&&o.execute(this._prevParams),o},_addBinding:function(t){var i=this._bindings.length;do i--;while(this._bindings[i]&&t._priority<=this._bindings[i]._priority);this._bindings.splice(i+1,0,t)},_indexOfListener:function(t,i){for(var s,e=this._bindings.length;e--;)if(s=this._bindings[e],s._listener===t&&s.context===i)return e;return-1},has:function(t,i){return-1!==this._indexOfListener(t,i)},add:function(t,i,s){return this.validateListener(t,"add"),this._registerListener(t,!1,i,s)},addOnce:function(t,i,s){return this.validateListener(t,"addOnce"),this._registerListener(t,!0,i,s)},remove:function(t,i){this.validateListener(t,"remove");var s=this._indexOfListener(t,i);return-1!==s&&(this._bindings[s]._destroy(),this._bindings.splice(s,1)),t},removeAll:function(t){"undefined"==typeof t&&(t=null);for(var i=this._bindings.length;i--;)t?this._bindings[i].context===t&&(this._bindings[i]._destroy(),this._bindings.splice(i,1)):this._bindings[i]._destroy();t||(this._bindings.length=0)},getNumListeners:function(){return this._bindings.length},halt:function(){this._shouldPropagate=!1},dispatch:function(){if(this.active){var t,i=Array.prototype.slice.call(arguments),s=this._bindings.length;if(this.memorize&&(this._prevParams=i),s){t=this._bindings.slice(),this._shouldPropagate=!0;do s--;while(t[s]&&this._shouldPropagate&&t[s].execute(i)!==!1)}}},forget:function(){this._prevParams=null},dispose:function(){this.removeAll(),delete this._bindings,delete this._prevParams},toString:function(){return"[Signal active:"+this.active+" numListeners:"+this.getNumListeners()+"]"}},i.prototype.constructor=i,vgp.Signal=i}.call(this),vgp.Manifold=function(){this.a=null,this.b=null,this.penetration=0,this.normal=new vgp.Vec},vgp.physics={_scratch:new vgp.Vec,_scratch2:new vgp.Vec,_normal:new vgp.Vec,_impulse:new vgp.Vec,_manifold:new vgp.Manifold,_separateStr:"separate",_testStr:"test",elapsed:.01666,resolve:function(t,i,s){this._scratch.set(i.velocity.x-t.velocity.x,i.velocity.y-t.velocity.y);var e=this._scratch.dot(s.normal);if(!(e>0)){var n=Math.min(t.restitution,i.restitution),o=-(1+n)*e;o/=t.invmass+i.invmass,this._impulse.set(s.normal.x*o,s.normal.y*o),t.velocity.x-=t.invmass*this._impulse.x,t.velocity.y-=t.invmass*this._impulse.y,i.velocity.x+=i.invmass*this._impulse.x,i.velocity.y+=i.invmass*this._impulse.y}},test:function(t,i){if(t.type===i.type)return this[this._testStr+t.type+i.type](t,i);throw new Error("Sorry, mixed collider types are not supported")},separate:function(t,i){if(t.type===i.type)return this[this._separateStr+t.type+i.type](t,i);throw new Error("Sorry, mixed collider types are not supported")},testAABB2AABB2:function(t,i){return t.max.x<i.min.x||t.min.x>i.max.x?!1:t.max.y<i.min.y||t.min.y>i.max.y?!1:!0},separateAABB2AABB2:function(t,i){if(t.max.x<i.min.x||t.min.x>i.max.x)return null;if(t.max.y<i.min.y||t.min.y>i.max.y)return null;this._normal.set(i.position.x-t.position.x,i.position.y-t.position.y);var s=.5*(t.max.x-t.min.x),e=.5*(i.max.x-i.min.x),n=s+e-Math.abs(this._normal.x);s=.5*(t.max.y-t.min.y),e=.5*(i.max.y-i.min.y);var o=s+e-Math.abs(this._normal.y);o>n?(this._normal.x<0?this._manifold.normal.set(-1,0):this._manifold.normal.set(1,0),this._manifold.penetration=n):(this._normal.y<0?this._manifold.normal.set(0,-1):this._manifold.normal.set(0,1),this._manifold.penetration=o);var h=this._manifold.penetration*this._manifold.normal.x,r=this._manifold.penetration*this._manifold.normal.y,a=t.invmass+i.invmass;return t.position.x-=h*(t.invmass/a),t.position.y-=r*(t.invmass/a),i.position.x+=h*(i.invmass/a),i.position.y+=r*(i.invmass/a),this._manifold},testCircleCircle:function(t,i){var s=i.position.x-t.position.x,e=i.position.y-t.position.y,n=s*s+e*e,o=t.radius+i.radius;return o*o>n?!0:!1},separateCircleCircle:function(t,i){this._scratch.copy(i.position).sub(t.position);var s=t.radius+i.radius,e=s*s,n=this._scratch.dot(this._scratch);if(e>n){n=Math.sqrt(n),0===n?(n=s-1,this._scratch.set(s,s,s),this._manifold.penetration=t.radius,this._manifold.normal.set(1,0,0)):(this._manifold.penetration=s-n,this._manifold.normal.copy(this._scratch).normalize());var o=(s-n)/n,h=t.invmass+i.invmass;return this._scratch.multiplyScalar(o),this._scratch2.copy(this._scratch),this._scratch.multiplyScalar(t.invmass/h),t.position.sub(this._scratch),this._scratch2.multiplyScalar(i.invmass/h),i.position.add(this._scratch2),this._manifold}if(!t.continuous&&!i.continuous)return null;if(0>n-e)return null;this._scratch2.copy(i.velocity).sub(t.velocity).multiplyScalar(this.elapsed),this._impulse.copy(t.velocity).multiplyScalar(this.elapsed);var r=this._impulse.dot(this._impulse);if(this._impulse.copy(i.velocity).multiplyScalar(this.elapsed),r+this._impulse.dot(this._impulse)+e<n)return null;var a=this._scratch2.dot(this._scratch2),l=this._scratch2.dot(this._scratch);if(l>=0)return null;var p=l*l-a*(n-e);if(0>p)return null;var u=(-l-Math.sqrt(p))/a;return this._scratch2.copy(t.velocity).multiplyScalar(this.elapsed).multiplyScalar(u),t.position.add(this._scratch2),this._scratch2.copy(i.velocity).multiplyScalar(this.elapsed).multiplyScalar(u),i.position.add(this._scratch2),this._manifold.penetration=0,this._manifold.normal.copy(this._scratch).normalize(),this._manifold}},vgp.AABB2=function(t,i){this.active=!1,this.entity=t||null,this.uniqueID=vgp.utils.generateID(),this.type=vgp.Type.AABB2,this.solid=!0,this.width=50,this.height=50,this.offsetX=0,this.offsetY=0,this.maxSpeed=10,this.mass=10,this.invmass=0,this.restitution=.6,this.autoAdd=!0,this.boundaryBehavior=vgp.Boundary.BOUNDARY_BOUNCE,this.collisionID=this.uniqueID,this.collisionGroup=null,this.onCollision=new vgp.Signal,vgp.utils.merge(this,i),this.position=t&&t.position?t.position:new vgp.Vec,this.velocity=t&&t.velocity?t.velocity:new vgp.Vec,this.accel=t&&t.accel?t.accel:new vgp.Vec,this.min=new vgp.Vec,this.max=new vgp.Vec,this._hitBoundaryX=!1,this._hitBoundaryY=!1,this._v=new vgp.Vec,this.update(),this.setMass(this.mass)},vgp.AABB2.prototype={constructor:vgp.AABB2,activate:function(){this.active=!0,this.autoAdd&&game.world.add(this)},disable:function(){this.velocity.set(),this.accel.set(),this.active=!1,game.world.remove(this)},setMass:function(t){this.mass=t,this.invmass=0>=t?0:1/t},reset:function(){this.setMass(this.mass)},update:function(){var t=game.world,i=this.accel.getLength();if(0!==i&&i>this.maxSpeed&&(this.accel.divideScalar(i),this.accel.multiplyScalar(this.maxSpeed)),this.accel.add(t.gravity),this.velocity.multiplyScalar(t.friction),this.velocity.add(this.accel),this._v.copy(this.velocity).multiplyScalar(t.elapsed),this.position.add(this._v),t.bounded)switch(this.boundaryBehavior){case vgp.Boundary.BOUNDARY_DISABLE:(this.position.x+this.offsetX<t.min.x||this.position.x+this.width+this.offsetX>t.max.x||this.position.y+this.offsetY<t.min.y||this.position.y+this.height+this.offsetY>t.max.y)&&(this.onCollision.dispatch(null),this.disable());break;case vgp.Boundary.BOUNDARY_BOUNCE:this.position.x+this.offsetX<t.min.x?(this.position.x=t.min.x-this.offsetX,this.velocity.x=-this.velocity.x*this.restitution,this._hitBoundaryX||(this._hitBoundaryX=!0,this.onCollision.dispatch(vgp.Boundary))):this.position.x+this.width+this.offsetX>t.max.x?(this.position.x=t.max.x-this.width-this.offsetX,this.velocity.x=-this.velocity.x*this.restitution,this._hitBoundaryX||(this._hitBoundaryX=!0,this.onCollision.dispatch(vgp.Boundary))):this._hitBoundaryX=!1,this.position.y+this.offsetY<t.min.y?(this.position.y=t.min.y-this.offsetY,this.velocity.y=-this.velocity.y*this.restitution,this._hitBoundaryY||(this._hitBoundaryY=!0,this.onCollision.dispatch(vgp.Boundary))):this.position.y+this.height+this.offsetY>t.max.y?(this.position.y=t.max.y-this.height-this.offsetY,this.velocity.y=-this.velocity.y*this.restitution,this._hitBoundaryY||(this._hitBoundaryY=!0,this.onCollision.dispatch(vgp.Boundary))):this._hitBoundaryY=!1;break;case vgp.Boundary.BOUNDARY_WRAP:this.position.x+this.offsetX<t.min.x?this.position.x+=t.max.x-this.offsetX-this.width:this.position.x+this.width+this.offsetX>t.max.x&&(this.position.x-=t.max.x-this.width-this.offsetX),this.position.y+this.offsetY<t.min.y?this.position.y+=t.max.y-this.offsetY-this.height:this.position.y+this.height+this.offsetY>t.max.y&&(this.position.y-=t.max.y-this.height-this.offsetY)}else this.position.x+this.offsetX<t.min.x?t.min.x=this.position.x+this.offsetX:this.position.x+this.width+this.offsetX>t.max.x&&(t.max.x=this.position.x+this.width+this.offsetX),this.position.y+this.offsetY<t.min.y?t.min.y=this.position.y+this.offsetY:this.position.y+this.height+this.offsetY>t.max.y&&(t.max.y=this.position.y+this.height+this.offsetY);this.min.x=this.position.x+this.offsetX,this.min.y=this.position.y+this.offsetY,this.max.x=this.position.x+this.width+this.offsetX,this.max.y=this.position.y+this.height+this.offsetY},dispose:function(){this.onCollision.dispose(),this.onCollision=null,this.entity=null,this.position=null,this.velocity=null,this.accel=null,this.min=null,this.max=null}},vgp.Radial2=function(t,i){this.active=!1,this.entity=t||null,this.uniqueID=vgp.utils.generateID(),this.type=vgp.Type.CIRCLE,this.solid=!0,this.radius=10,this.offsetX=0,this.offsetY=0,this.maxSpeed=10,this.continuous=!1,this.mass=100,this.invmass=0,this.restitution=.8,this.autoAdd=!0,this.boundaryBehavior=vgp.Boundary.BOUNDARY_BOUNCE,this.collisionID=this.uniqueID,this.collisionGroup=null,this.onCollision=new vgp.Signal,vgp.utils.merge(this,i),this.position=t&&t.position?t.position:new vgp.Vec,this.velocity=t&&t.velocity?t.velocity:new vgp.Vec,this.accel=t&&t.accel?t.accel:new vgp.Vec,this.min=new vgp.Vec,this.max=new vgp.Vec,this._hitBoundaryX=!1,this._hitBoundaryY=!1,this._v=new vgp.Vec,this.setMass(this.mass),this.update()},vgp.Radial2.prototype={constructor:vgp.Radial2,activate:function(){this.active=!0,this.autoAdd&&game.world.add(this)},disable:function(){this.velocity.set(),this.accel.set(),this.active=!1,game.world.remove(this)},setMass:function(t){this.mass=t,this.invmass=0>=t?0:1/t},reset:function(){this.setMass(this.mass)},update:function(){var t=game.world,i=this.accel.getLength();if(0!==i&&i>this.maxSpeed&&(this.accel.divideScalar(i),this.accel.multiplyScalar(this.maxSpeed)),this.accel.add(t.gravity),this.velocity.multiplyScalar(t.friction),this.velocity.add(this.accel),this._v.copy(this.velocity).multiplyScalar(t.elapsed),this.position.add(this._v),t.bounded)switch(this.boundaryBehavior){case vgp.Boundary.BOUNDARY_DISABLE:(this.position.x+this.offsetX<t.min.x||this.position.x+this.radius+this.offsetX>t.max.x||this.position.y+this.offsetY<t.min.y||this.position.y+this.radius+this.offsetY>t.max.y)&&(this.onCollision.dispatch(vgp.Boundary),this.disable());break;case vgp.Boundary.BOUNDARY_BOUNCE:this.position.x-this.radius+this.offsetX<t.min.x?(this.position.x=t.min.x-this.offsetX+this.radius,this.velocity.x=-this.velocity.x*this.restitution,this._hitBoundaryX||(this._hitBoundaryX=!0,this.onCollision.dispatch(vgp.Boundary))):this.position.x+this.radius+this.offsetX>t.max.x?(this.position.x=t.max.x-this.radius-this.offsetX,this.velocity.x=-this.velocity.x*this.restitution,this._hitBoundaryX||(this._hitBoundaryX=!0,this.onCollision.dispatch(vgp.Boundary))):this._hitBoundaryX=!1,this.position.y-this.radius+this.offsetY<t.min.y?(this.position.y=t.min.y-this.offsetY+this.radius,this.velocity.y=-this.velocity.y*this.restitution,this._hitBoundaryY||(this._hitBoundaryY=!0,this.onCollision.dispatch(vgp.Boundary))):this.position.y+this.radius+this.offsetY>t.max.y?(this.position.y=t.max.y-this.radius-this.offsetY,this.velocity.y=-this.velocity.y*this.restitution,this._hitBoundaryY||(this._hitBoundaryY=!0,this.onCollision.dispatch(vgp.Boundary))):this._hitBoundaryY=!1;break;case vgp.Boundary.BOUNDARY_WRAP:this.position.x-this.radius+this.offsetX<t.min.x?this.position.x+=t.max.x-this.offsetX+this.radius:this.position.x+this.radius+this.offsetX>t.max.x&&(this.position.x-=t.max.x-this.radius-this.offsetX),this.position.y-this.radius+this.offsetY<t.min.y?this.position.y+=t.max.y-this.offsetY+this.radius:this.position.y+this.radius+this.offsetY>t.max.y&&(this.position.y-=t.max.y-this.radius-this.offsetY)}else this.position.x+this.offsetX<t.min.x?t.min.x=this.position.x+this.offsetX:this.position.x+this.radius+this.offsetX>t.max.x&&(t.max.x=this.position.x+this.radius+this.offsetX),this.position.y+this.offsetY<t.min.y?t.min.y=this.position.y+this.offsetY:this.position.y+this.radius+this.offsetY>t.max.y&&(t.max.y=this.position.y+this.radius+this.offsetY);this.min.x=this.position.x-this.radius+this.offsetX,this.min.y=this.position.y-this.radius+this.offsetY,this.max.x=this.position.x+this.radius+this.offsetX,this.max.y=this.position.y+this.radius+this.offsetY},dispose:function(){this.onCollision.dispose(),this.onCollision=null,this.entity=null,this.position=null,this.velocity=null,this.accel=null,this.min=null,this.max=null}},vgp.ObjectPool=function(t,i,s){this.free=new vgp.LinkedList,this.busy=new vgp.LinkedList,this.size=s,this._Class=t,this._settings=i||{},this._settings.pool=this;for(var e=0;e<this.size;e++)this.free.add(new this._Class(this._settings))},vgp.ObjectPool.prototype={constructor:vgp.ObjectPool,get:function(){var t;return this.free.length?(t=this.free.pop(),this.busy.add(t),t):(t=new this._Class(this._settings),this.busy.add(t),this.size++,t)},recycle:function(t){this.busy.has(t)&&(this.busy.remove(t),this.free.add(t))},freeAll:function(){for(var t,i=this.busy.first;i;)t=i.obj,i=i.next,this.busy.remove(t),this.free.add(t)},dispose:function(){for(var t=this.busy.first;t;)t.obj.dispose(),t=t.next;for(t=this.free.first;t;)t.obj.dispose(),t=t.next;this.free.dispose(),this.busy.dispose(),this.free=null,this.busy=null,this._Class=null,this._settings=null},toString:function(){return"[ObjectPool size: "+this.size+", free: "+this.free.length+", busy: "+this.busy.length+"]"}},vgp.World=function(){this.active=!0,this.bounded=!1,this.friction=.9,this.gravity=new vgp.Vec,this.elapsed=.0166,this.min=new vgp.Vec,this.max=new vgp.Vec(100,100,100),this.objects=new vgp.LinkedList},vgp.World.prototype={constructor:vgp.World,add:function(t){return t=t.body||t,t.onCollision?void this.objects.add(t):(console.warn("[vgp.World.add] Ignoring object; must be an entity or physics component"),void console.dir(t))},remove:function(t){t=t.body||t,this.objects.remove(t)},setBounds:function(t,i,s){this.bounded="boolean"==typeof t?t:!0,this.min.set(0,0,0),this.bounded&&this.max.set(t,i,s)},update:function(){var t,i,s,e,n;for(s=this.objects.first;s;)if(i=s.obj,i.solid&&i.active){for(n=s.next;n;)e=n.obj,n=n.next,e.solid&&e.active&&e.collisionID!==i.collisionID&&(t=vgp.physics.separate(i,e),t&&(vgp.physics.resolve(i,e,t),i.onCollision.dispatch(e,t),e.onCollision.dispatch(i,t)));s=s.next}else s=s.next},disable:function(){this.active=!1},dispose:function(){this.objects.dispose(),this.objects=null,this.grid=null,this.min=null,this.max=null,this._emptyCell=null}};