diff --git a/javascript/examples/Environment/Input/variableInputs/interface.js b/javascript/examples/Environment/Input/variableInputs/interface.js
new file mode 100644
index 000000000..9b7e53e49
--- /dev/null
+++ b/javascript/examples/Environment/Input/variableInputs/interface.js
@@ -0,0 +1,204 @@
+window.onload = function () {
+ tryFindSketch();
+}
+
+function tryFindSketch () {
+ var sketch = Processing.instances[0];
+ if ( sketch == undefined ) return setTimeout(tryFindSketch, 200);
+
+ var controller = new Controller(sketch,"form-form");
+ sketch.setController(controller);
+}
+
+var Controller = (function(){
+
+ function Controller () {
+ var sketch = arguments[0];
+ var form = document.getElementById(arguments[1]);
+ form.onsubmit = function () {return false};
+ var inputs = {};
+
+ this.createInputElement = function ( id, type, labelStr ) {
+ var input = document.createElement('input');
+ input.id = id;
+ input.name = id;
+ input.type = type;
+ if ( labelStr !== undefined && labelStr !== '' )
+ {
+ var label = document.createElement('label');
+ label['for'] = id;
+ label.id = id+'-label';
+ label.innerHTML = labelStr;
+ form.appendChild(label);
+ }
+ form.appendChild(input);
+ return input;
+ }
+
+ this.addInputField = function ( l, t ) {
+ var id = createIdFromLabel(l);
+ if ( inputs[id] == undefined ) {
+ inputs[id] = this.createInputElement(id, t, l);
+ inputs[id].onchange = function(){
+ changeFunc()(sketch, id, this.value);
+ return false;
+ }
+ }
+ return inputs[id];
+ }
+
+ this.addRange = function ( l, c, mi, mx ) {
+ var input = this.addInputField( l, "range" );
+ input.value = c;
+ input.min = mi;
+ input.max = mx;
+ return input;
+ }
+
+ this.addPassword = function ( l ) {
+ var input = this.addInputField ( l, "password" );
+ return input;
+ }
+
+ this.addEmail = function ( l ) {
+ var input = this.addInputField ( l, "email" );
+ return input;
+ }
+
+ this.addSearch = function ( l, c ) {
+ var input = this.addInputField ( l, "search" );
+ input.value = c;
+ return input;
+ }
+
+ this.addNumber = function ( l, c ) {
+ var input = this.addInputField ( l, "number" );
+ input.value = c;
+ return input;
+ }
+
+ this.addTelephone = function ( l, c ) {
+ var input = this.addInputField ( l, "tel" );
+ input.value = c;
+ return input;
+ }
+
+ this.addUrl = function ( l, c ) {
+ var input = this.addInputField ( l, "url" );
+ input.value = c;
+ return input;
+ }
+
+ this.addDate = function ( l, c ) {
+ var input = this.addInputField ( l, "date" );
+ input.value = c;
+ return input;
+ }
+
+ this.addCheckbox = function ( l, c ) {
+ var id = createIdFromLabel(l);
+ if ( inputs[id] == undefined ) {
+ inputs[id] = this.createInputElement(id, "checkbox", l);
+ inputs[id].onchange = function(){
+ changeFunc()(sketch, id, this.checked);
+ return false;
+ }
+ }
+ inputs[id].checked = c ? 'checked' : '';
+ return inputs[id];
+ }
+
+ this.addTextfield = function ( l, c ) {
+ var id = createIdFromLabel(l);
+ if ( inputs[id] == undefined ) {
+ inputs[id] = this.createInputElement(id, "text", l);
+ inputs[id].onchange = function(){
+ changeFunc()(sketch, id, this.value);
+ return false;
+ }
+ }
+ inputs[id].value = c;
+ return inputs[id];
+ }
+
+ this.addTextarea = function ( l, c ) {
+ var id = createIdFromLabel(l);
+ if ( inputs[id] == undefined ) {
+ var label = document.createElement('label');
+ label['for'] = id;
+ label.id = id+'-label';
+ label.innerHTML = l;
+ form.appendChild(label);
+ inputs[id] = document.createElement('textarea');
+ inputs[id].id = id;
+ inputs[id].name = id;
+ inputs[id].innerHTML = c;
+ inputs[id].onchange = function(){
+ changeFunc()(sketch, id, this.value);
+ return false;
+ }
+ form.appendChild(inputs[id]);
+ }
+ inputs[id].value = c;
+ return inputs[id];
+ }
+
+ this.addSelection = function ( l, o ) {
+ var id = createIdFromLabel(l);
+ if ( inputs[id] == undefined ) {
+ var label = document.createElement('label');
+ label['for'] = id;
+ label.id = id+'-label';
+ label.innerHTML = l;
+ form.appendChild(label);
+ var select = document.createElement('select');
+ select.id = id;
+ select.name = id;
+ if ( o !== undefined && o.length && o.length > 0 ) {
+ for ( var i = 0; i < o.length; i++ ) {
+ var value = o[i].length > 1 ? o[i][1] : i;
+ var option = document.createElement('option');
+ option.innerHTML = o[i][0];
+ option.value = value;
+ select.appendChild(option);
+ }
+ }
+ select.onchange = function( event ){
+ changeFunc()(sketch, id, this.value);
+ return false;
+ }
+ inputs[id] = select;
+ form.appendChild(inputs[id]);
+ }
+ return inputs[id];
+ }
+ this.addMenu = this.addSelection;
+
+ this.setElementLabel = function ( element, labelStr ) {
+ var label = document.getElementById(element.id+'-label');
+ if ( label && label.childNodes && label.childNodes.length > 0 ) {
+ label.childNodes[0].textContent = labelStr;
+ } else {
+ //console.log([element, label]);
+ }
+ }
+ }
+
+ var changeFunc = function () {
+ return function ( sketch, id, value ) {
+ try {
+ sketch[id](value);
+ } catch (e) {
+ //console.log(e);
+ sketch.println( "Function \"void "+id+"(value)\" is not defined in your sketch.");
+ }
+ }
+ }
+
+ var createIdFromLabel = function ( l ) {
+ return l.replace(/^[^-_a-z]/i,'_').replace(/[^-_a-z0-9]/gi,'');
+ }
+
+ return Controller;
+
+})();
diff --git a/javascript/examples/Environment/Input/variableInputs/variableInputs.pde b/javascript/examples/Environment/Input/variableInputs/variableInputs.pde
new file mode 100644
index 000000000..43d4830c0
--- /dev/null
+++ b/javascript/examples/Environment/Input/variableInputs/variableInputs.pde
@@ -0,0 +1,190 @@
+/**
+ * This examples shows you how to interact with diverse HTML inputs. It follows
+ * roughly the way that ControlP5
+ * works for standard Processing.
+ *
+ *
+ *
+ *
+ */
+
+ String[] menuItems;
+
+ int currentShape = 2;
+ float currentX = 0;
+ boolean hasStroke = true;
+ float hueValue = 0;
+ String fieldString = "Fancy Corp. Co.";
+ String areaString = "We are the fresh new company with "+
+ "activities ranging from A to Z and from "+
+ "alpha to omega.";
+ PFont fontLarge, fontSmall;
+
+ void setup ()
+ {
+ size(300,200);
+
+ colorMode(HSB);
+
+ currentX = 50;
+
+ menuItems = new String[] {
+ new String[] {"Rectangle"}, new String[] {"Ellipse"},
+ new String[] {"Star"}, new String[] {"Spirograph"}
+ };
+
+ textFont(createFont("Arial", 16));
+ }
+
+ int bg = 200; void setBG ( int b ) { bg = b; }
+ void draw ()
+ {
+ background( bg );
+
+ strokeWeight(4);
+
+ if ( hasStroke ) stroke( hueValue, 150, 95 );
+ else noStroke();
+
+ fill( hueValue, 200, 150 );
+
+ pushMatrix();
+ switch ( currentShape ) {
+ case 0:
+ rectMode(CENTER);
+ rect(currentX, height/4, 50, 50);
+ break;
+ case 1:
+ ellipse(currentX, height/4, 55, 55);
+ break;
+ case 2:
+ star(currentX, height/4, 17, 30);
+ break;
+ case 3:
+ spiro(currentX, height/4, 20);
+ break;
+ }
+ popMatrix();
+
+ fill( 0 );
+ textSize(16);
+ textAlign( CENTER );
+ float tWidth = textWidth(fieldString);
+ float tX = currentX;
+ if ( currentX-tWidth/2 < 25 )
+ {
+ textAlign( LEFT );
+ tX = currentX-25;
+ }
+ else if ( currentX+tWidth/2 > width-25 )
+ {
+ textAlign( RIGHT );
+ tX = currentX+25;
+ }
+ text( fieldString, tX, height/4+50 );
+
+ textSize(11.5);
+ textAlign( currentX > width/2 ? RIGHT : LEFT );
+ int l, w;
+ if ( currentX <= width/2 )
+ {
+ l = currentX-50+25;
+ w = width-l-25;
+ }
+ else
+ {
+ l = 25;
+ w = currentX+50-25-25;
+ }
+ text( areaString, l, height/4+70, w, height/2 );
+ }
+
+ void star ( float x, float y, float inner, float outer )
+ {
+ beginShape();
+ for ( int i = 0; i < 360; i+=36 )
+ {
+ float r = radians(i + sin(frameCount/90.0)*25);
+ vertex( x + cos(r)*outer, y + sin(r)*outer );
+ r = radians(i+(36/2));
+ vertex( x + cos(r)*inner, y + sin(r)*inner );
+ }
+ endShape(CLOSE);
+ }
+
+ void spiro ( float x, float y, float rad )
+ {
+ beginShape();
+ for ( int i = 0; i < 360; i+=2 )
+ {
+ float r = radians(i);
+ float r2 = radians(i*(sin(frameCount/240.0)+2)*2);
+ vertex( x + (cos(r)+cos(r2)/2)*rad, y + (sin(r)+sin(r2)/2)*rad );
+ }
+ endShape();
+ }
+
+ /* these are callbacks */
+
+ void setController ( Controller ctlr )
+ {
+ // labels are supposed to be existing function names
+
+ InterfaceElement element = ctlr.addRange( "rangeCallback", currentX, 0, 100 );
+ ctlr.setElementLabel( element, "Example range input field" );
+
+ element = ctlr.addCheckbox( "textBoxCallback", hasStroke );
+ ctlr.setElementLabel( element, "A checkbox here" );
+
+ element = ctlr.addTextfield( "textFieldChanged", fieldString );
+ ctlr.setElementLabel( element, "... and this is a textfield" );
+
+ element = ctlr.addTextarea( "calledByTextarea", areaString );
+ ctlr.setElementLabel( element, "Ta-dah: a textarea" );
+
+ element = ctlr.addMenu( "theMenu", menuItems );
+ ctlr.setElementLabel( element, "LBNL a select menu" );
+ }
+
+ void rangeCallback ( float value )
+ {
+ currentX = map( value, 0, 100, 50, width-50 );
+ }
+
+ void textBoxCallback ( boolean value )
+ {
+ hasStroke = value;
+ }
+
+ void textFieldChanged ( String value )
+ {
+ fieldString = value;
+ }
+
+ void calledByTextarea ( String value )
+ {
+ areaString = value;
+ }
+
+ void theMenu ( String value )
+ {
+ currentShape = int(value);
+ }
+
+ /* and the interfaces */
+
+ /* explain inputs to Processing */
+ interface InputElement
+ {
+ String type;
+ String id;
+ Object value;
+ }
+
+ /* explain Controller to Processing */
+ interface Controller
+ {
+ InputElement addRange ( String label, float initialValue, float minValue, float maxValue );
+ void setLabel ( InputElement element, String label );
+ }
diff --git a/javascript/examples/Libraries/Box2D/simpleBox2D/data/box2d-min.js b/javascript/examples/Libraries/Box2D/simpleBox2D/data/box2d-min.js
new file mode 100644
index 000000000..6581f9803
--- /dev/null
+++ b/javascript/examples/Libraries/Box2D/simpleBox2D/data/box2d-min.js
@@ -0,0 +1,306 @@
+// See: http://box2d-js.sourceforge.net/
+/*
+* Copyright (c) 2006-2007 Erin Catto http:
+*
+* This software is provided 'as-is', without any express or implied
+* warranty. In no event will the authors be held liable for any damages
+* arising from the use of this software.
+* Permission is granted to anyone to use this software for any purpose,
+* including commercial applications, and to alter it and redistribute it
+* freely, subject to the following restrictions:
+* 1. The origin of this software must not be misrepresented; you must not
+* claim that you wrote the original software. If you use this software
+* in a product, an acknowledgment in the product documentation would be
+* appreciated but is not required.
+* 2. Altered source versions must be plainly marked, and must not be
+* misrepresented the original software.
+* 3. This notice may not be removed or altered from any source distribution.
+*/
+var b2Settings=Class.create();b2Settings.prototype={initialize:function(){}};b2Settings.USHRT_MAX=65535;b2Settings.b2_pi=Math.PI;b2Settings.b2_massUnitsPerKilogram=1;b2Settings.b2_timeUnitsPerSecond=1;b2Settings.b2_lengthUnitsPerMeter=30;b2Settings.b2_maxManifoldPoints=2;b2Settings.b2_maxShapesPerBody=64;b2Settings.b2_maxPolyVertices=8;b2Settings.b2_maxProxies=1024;b2Settings.b2_maxPairs=8*b2Settings.b2_maxProxies;b2Settings.b2_linearSlop=0.0050*b2Settings.b2_lengthUnitsPerMeter;
+b2Settings.b2_angularSlop=2/180*b2Settings.b2_pi;b2Settings.b2_velocityThreshold=1*b2Settings.b2_lengthUnitsPerMeter/b2Settings.b2_timeUnitsPerSecond;b2Settings.b2_maxLinearCorrection=0.2*b2Settings.b2_lengthUnitsPerMeter;b2Settings.b2_maxAngularCorrection=8/180*b2Settings.b2_pi;b2Settings.b2_contactBaumgarte=0.2;b2Settings.b2_timeToSleep=0.5*b2Settings.b2_timeUnitsPerSecond;b2Settings.b2_linearSleepTolerance=0.01*b2Settings.b2_lengthUnitsPerMeter/b2Settings.b2_timeUnitsPerSecond;
+b2Settings.b2_angularSleepTolerance=2/180/b2Settings.b2_timeUnitsPerSecond;b2Settings.b2Assert=function(a){a||(void 0).x++};var b2Vec2=Class.create();
+b2Vec2.prototype={initialize:function(a,c){this.x=a;this.y=c},SetZero:function(){this.y=this.x=0},Set:function(a,c){this.x=a;this.y=c},SetV:function(a){this.x=a.x;this.y=a.y},Negative:function(){return new b2Vec2(-this.x,-this.y)},Copy:function(){return new b2Vec2(this.x,this.y)},Add:function(a){this.x+=a.x;this.y+=a.y},Subtract:function(a){this.x-=a.x;this.y-=a.y},Multiply:function(a){this.x*=a;this.y*=a},MulM:function(a){var c=this.x;this.x=a.col1.x*c+a.col2.x*this.y;this.y=a.col1.y*c+a.col2.y*
+this.y},MulTM:function(a){var c=b2Math.b2Dot(this,a.col1);this.y=b2Math.b2Dot(this,a.col2);this.x=c},CrossVF:function(a){var c=this.x;this.x=a*this.y;this.y=-a*c},CrossFV:function(a){var c=this.x;this.x=-a*this.y;this.y=a*c},MinV:function(a){this.x=this.xa.x?this.x:a.x;this.y=this.y>a.y?this.y:a.y},Abs:function(){this.x=Math.abs(this.x);this.y=Math.abs(this.y)},Length:function(){return Math.sqrt(this.x*this.x+this.y*this.y)},
+Normalize:function(){var a=this.Length();if(a0?a:-a};
+b2Math.b2AbsV=function(a){return new b2Vec2(b2Math.b2Abs(a.x),b2Math.b2Abs(a.y))};b2Math.b2AbsM=function(a){return new b2Mat22(0,b2Math.b2AbsV(a.col1),b2Math.b2AbsV(a.col2))};b2Math.b2Min=function(a,c){return ac?a:c};b2Math.b2MaxV=function(a,c){return new b2Vec2(b2Math.b2Max(a.x,c.x),b2Math.b2Max(a.y,c.y))};
+b2Math.b2Clamp=function(a,c,b){return b2Math.b2Max(c,b2Math.b2Min(a,b))};b2Math.b2ClampV=function(a,c,b){return b2Math.b2MaxV(c,b2Math.b2MinV(a,b))};b2Math.b2Swap=function(a,c){var b=a[0];a[0]=c[0];c[0]=b};b2Math.b2Random=function(){return Math.random()*2-1};b2Math.b2NextPowerOfTwo=function(a){a|=a>>1&2147483647;a|=a>>2&1073741823;a|=a>>4&268435455;a|=a>>8&16777215;a|=a>>16&65535;return a+1};b2Math.b2IsPowerOfTwo=function(a){return a>0&&(a&a-1)==0};b2Math.tempVec2=new b2Vec2;b2Math.tempVec3=new b2Vec2;
+b2Math.tempVec4=new b2Vec2;b2Math.tempVec5=new b2Vec2;b2Math.tempMat=new b2Mat22;var b2AABB=Class.create();b2AABB.prototype={IsValid:function(){var a=this.maxVertex.x,c=this.maxVertex.y,a=this.maxVertex.x,c=this.maxVertex.y;a-=this.minVertex.x;c-=this.minVertex.y;return a=a>=0&&c>=0&&this.minVertex.IsValid()&&this.maxVertex.IsValid()},minVertex:new b2Vec2,maxVertex:new b2Vec2,initialize:function(){this.minVertex=new b2Vec2;this.maxVertex=new b2Vec2}};var b2Bound=Class.create();
+b2Bound.prototype={IsLower:function(){return(this.value&1)==0},IsUpper:function(){return(this.value&1)==1},Swap:function(a){var c=this.value,b=this.proxyId,e=this.stabbingCount;this.value=a.value;this.proxyId=a.proxyId;this.stabbingCount=a.stabbingCount;a.value=c;a.proxyId=b;a.stabbingCount=e},value:0,proxyId:0,stabbingCount:0,initialize:function(){}};var b2BoundValues=Class.create();
+b2BoundValues.prototype={lowerValues:[0,0],upperValues:[0,0],initialize:function(){this.lowerValues=[0,0];this.upperValues=[0,0]}};var b2Pair=Class.create();
+b2Pair.prototype={SetBuffered:function(){this.status|=b2Pair.e_pairBuffered},ClearBuffered:function(){this.status&=~b2Pair.e_pairBuffered},IsBuffered:function(){return(this.status&b2Pair.e_pairBuffered)==b2Pair.e_pairBuffered},SetRemoved:function(){this.status|=b2Pair.e_pairRemoved},ClearRemoved:function(){this.status&=~b2Pair.e_pairRemoved},IsRemoved:function(){return(this.status&b2Pair.e_pairRemoved)==b2Pair.e_pairRemoved},SetFinal:function(){this.status|=b2Pair.e_pairFinal},IsFinal:function(){return(this.status&
+b2Pair.e_pairFinal)==b2Pair.e_pairFinal},userData:null,proxyId1:0,proxyId2:0,next:0,status:0,initialize:function(){}};b2Pair.b2_nullPair=b2Settings.USHRT_MAX;b2Pair.b2_nullProxy=b2Settings.USHRT_MAX;b2Pair.b2_tableCapacity=b2Settings.b2_maxPairs;b2Pair.b2_tableMask=b2Pair.b2_tableCapacity-1;b2Pair.e_pairBuffered=1;b2Pair.e_pairRemoved=2;b2Pair.e_pairFinal=4;var b2PairCallback=Class.create();b2PairCallback.prototype={PairAdded:function(){return null},PairRemoved:function(){},initialize:function(){}};
+var b2BufferedPair=Class.create();b2BufferedPair.prototype={proxyId1:0,proxyId2:0,initialize:function(){}};var b2PairManager=Class.create();
+b2PairManager.prototype={initialize:function(){var a=0;this.m_hashTable=Array(b2Pair.b2_tableCapacity);for(a=0;ac)var b=a,a=c,c=b;var b=b2PairManager.Hash(a,c)&b2Pair.b2_tableMask,e=e=this.FindHash(a,c,b);if(e!=null)return e;var f=this.m_freePair,e=this.m_pairs[f];this.m_freePair=e.next;e.proxyId1=a;e.proxyId2=c;e.status=0;e.userData=null;e.next=this.m_hashTable[b];this.m_hashTable[b]=f;++this.m_pairCount;return e},RemovePair:function(a,c){if(a>c)var b=a,a=c,c=b;for(var e=b2PairManager.Hash(a,c)&b2Pair.b2_tableMask,f=this.m_hashTable[e],g=null;f!=b2Pair.b2_nullPair;)if(b2PairManager.Equals(this.m_pairs[f],
+a,c))return b=f,g?g.next=this.m_pairs[f].next:this.m_hashTable[e]=this.m_pairs[f].next,e=this.m_pairs[b],f=e.userData,e.next=this.m_freePair,e.proxyId1=b2Pair.b2_nullProxy,e.proxyId2=b2Pair.b2_nullProxy,e.userData=null,e.status=0,this.m_freePair=b,--this.m_pairCount,f;else g=this.m_pairs[f],f=g.next;return null},Find:function(a,c){if(a>c)var b=a,a=c,c=b;b=b2PairManager.Hash(a,c)&b2Pair.b2_tableMask;return this.FindHash(a,c,b)},FindHash:function(a,c,b){for(b=this.m_hashTable[b];b!=b2Pair.b2_nullPair&&
+b2PairManager.Equals(this.m_pairs[b],a,c)==!1;)b=this.m_pairs[b].next;if(b==b2Pair.b2_nullPair)return null;return this.m_pairs[b]},ValidateBuffer:function(){},ValidateTable:function(){},m_broadPhase:null,m_callback:null,m_pairs:null,m_freePair:0,m_pairCount:0,m_pairBuffer:null,m_pairBufferCount:0,m_hashTable:null};b2PairManager.Hash=function(a,c){var b=c<<16&4294901760|a,b=~b+(b<<15&4294934528);b^=b>>12&1048575;b+=b<<2&4294967292;b^=b>>4&268435455;b*=2057;b^=b>>16&65535;return b};
+b2PairManager.Equals=function(a,c,b){return a.proxyId1==c&&a.proxyId2==b};b2PairManager.EqualsPair=function(a,c){return a.proxyId1==c.proxyId1&&a.proxyId2==c.proxyId2};var b2BroadPhase=Class.create();
+b2BroadPhase.prototype={initialize:function(a,c){this.m_pairManager=new b2PairManager;this.m_proxyPool=Array(b2Settings.b2_maxPairs);this.m_bounds=Array(2*b2Settings.b2_maxProxies);this.m_queryResults=Array(b2Settings.b2_maxProxies);this.m_quantizationFactor=new b2Vec2;var b=0;this.m_pairManager.Initialize(this,c);this.m_worldAABB=a;for(b=this.m_proxyCount=0;b0&&q0)for(e=p;e0)for(e=o;e0&&se[c.upperBounds[b]].value)return!1;if(e[a.upperBounds[b]].valuee[c.upperBounds[b]].value)return!1;if(a.upperValues[b]0)for(var g=b-1,i=f[g].stabbingCount;i;)f[g].IsLower()&&b<=this.m_proxyPool[f[g].proxyId].upperBounds[h]&&(this.IncrementOverlapCount(f[g].proxyId),--i),--g;a[0]=b;c[0]=e},IncrementOverlapCount:function(a){var c=
+this.m_proxyPool[a];c.timeStampb)c=f-1;else if(a[f].value0?c[0].id:c[1].id,++f;return f};
+b2Collision.EdgeSeparation=function(a,c,b){for(var e=a.m_vertices,f=b.m_vertexCount,g=b.m_vertices,h=a.m_normals[c].x,i=a.m_normals[c].y,k=h,j=a.m_R,h=j.col1.x*k+j.col2.x*i,i=j.col1.y*k+j.col2.y*i,l=h,m=i,j=b.m_R,k=l*j.col1.x+m*j.col1.y,m=l*j.col2.x+m*j.col2.y,l=k,k=0,j=Number.MAX_VALUE,n=0;nk&&(k=l,g=j)}i=b2Collision.EdgeSeparation(c,g,b);if(i>0&&e==!1)return i;j=g-1>=0?g-1:f-1;l=b2Collision.EdgeSeparation(c,j,b);if(l>0&&e==!1)return l;var m=g+10&&e==!1)return n;
+k=h=0;if(l>i&&l>n)k=-1,h=j,j=l;else if(n>i)k=1,h=m,j=n;else return a[0]=g,i;for(;;){g=k==-1?h-1>=0?h-1:f-1:h+10&&e==!1)return i;if(i>j)h=g,j=i;else break}a[0]=h;return j};
+b2Collision.FindIncidentEdge=function(a,c,b,e){var f=c.m_vertices,g=e.m_vertexCount,h=e.m_vertices,i=f[b+1==c.m_vertexCount?0:b+1],k=i.x,j=i.y,i=f[b];k-=i.x;j-=i.y;i=k;k=j;j=-i;i=1/Math.sqrt(k*k+j*j);k*=i;j*=i;for(var i=k,f=c.m_R,c=f.col1.x*i+f.col2.x*j,k=j=f.col1.y*i+f.col2.y*j,f=e.m_R,i=c*f.col1.x+k*f.col1.y,k=c*f.col2.x+k*f.col2.y,c=i,f=j=0,l=Number.MAX_VALUE,m=0;m0&&e==!1)){var i,g=[0],k=b2Collision.FindMaxSeparation(g,b,c,e);i=g[0];if(!(k>0&&e==!1)){var j=0,g=0;k>0.98*h+0.0010?(h=b,j=i,g=1):(h=c,c=b,j=f,g=0);b=[new ClipVertex,new ClipVertex];b2Collision.FindIncidentEdge(b,h,j,c);var c=h.m_vertices,l=c[j],m=j+1c*c&&e==!1))hi)return;l>j&&(j=l,k=e)}if(ji))a.pointCount=1,a.normal.Set(h.col1.x*f+h.col2.x*g,h.col1.y*f+h.col2.y*g),e=a.points[0],e.id.features.incidentEdge=b2Collision.b2_nullFeature,e.id.features.incidentVertex=k,e.id.features.referenceFace=b2Collision.b2_nullFeature,e.id.features.flip=0,e.position.x=b.m_position.x-i*a.normal.x,e.position.y=b.m_position.y-i*a.normal.y,e.separation=c-i}else{var o=(f-c.m_vertices[k].x)*m+(g-c.m_vertices[k].y)*l;e=a.points[0];e.id.features.incidentEdge=b2Collision.b2_nullFeature;
+e.id.features.incidentVertex=b2Collision.b2_nullFeature;e.id.features.referenceFace=b2Collision.b2_nullFeature;e.id.features.flip=0;o<=0?(m=c.m_vertices[k].x,c=c.m_vertices[k].y,e.id.features.incidentVertex=k):o>=n?(m=c.m_vertices[j].x,c=c.m_vertices[j].y,e.id.features.incidentVertex=j):(m=m*o+c.m_vertices[k].x,c=l*o+c.m_vertices[k].y,e.id.features.incidentEdge=k);f-=m;g-=c;c=Math.sqrt(f*f+g*g);f/=c;g/=c;if(!(c>i))a.pointCount=1,a.normal.Set(h.col1.x*f+h.col2.x*g,h.col1.y*f+h.col2.y*g),e.position.x=
+b.m_position.x-i*a.normal.x,e.position.y=b.m_position.y-i*a.normal.y,e.separation=c-i}}};b2Collision.b2TestOverlap=function(a,c){var b=c.minVertex,e=a.maxVertex,f=b.x-e.x,g=b.y-e.y,b=a.minVertex,e=c.maxVertex,h=b.y-e.y;if(f>0||g>0)return!1;if(b.x-e.x>0||h>0)return!1;return!0};var Features=Class.create();
+Features.prototype={set_referenceFace:function(a){this._referenceFace=a;this._m_id._key=this._m_id._key&4294967040|this._referenceFace&255},get_referenceFace:function(){return this._referenceFace},_referenceFace:0,set_incidentEdge:function(a){this._incidentEdge=a;this._m_id._key=this._m_id._key&4294902015|this._incidentEdge<<8&65280},get_incidentEdge:function(){return this._incidentEdge},_incidentEdge:0,set_incidentVertex:function(a){this._incidentVertex=a;this._m_id._key=this._m_id._key&4278255615|
+this._incidentVertex<<16&16711680},get_incidentVertex:function(){return this._incidentVertex},_incidentVertex:0,set_flip:function(a){this._flip=a;this._m_id._key=this._m_id._key&16777215|this._flip<<24&4278190080},get_flip:function(){return this._flip},_flip:0,_m_id:null,initialize:function(){}};var b2ContactID=Class.create();
+b2ContactID.prototype={initialize:function(){this.features=new Features;this.features._m_id=this},Set:function(a){this.set_key(a._key)},Copy:function(){var a=new b2ContactID;a.set_key(this._key);return a},get_key:function(){return this._key},set_key:function(a){this._key=a;this.features._referenceFace=this._key&255;this.features._incidentEdge=(this._key&65280)>>8&255;this.features._incidentVertex=(this._key&16711680)>>16&255;this.features._flip=(this._key&4278190080)>>24&255},features:new Features,
+_key:0};var b2ContactPoint=Class.create();b2ContactPoint.prototype={position:new b2Vec2,separation:null,normalImpulse:null,tangentImpulse:null,id:new b2ContactID,initialize:function(){this.position=new b2Vec2;this.id=new b2ContactID}};var b2Distance=Class.create();b2Distance.prototype={initialize:function(){}};
+b2Distance.ProcessTwo=function(a,c,b,e,f){var g=-f[1].x,h=-f[1].y,i=f[0].x-f[1].x,k=f[0].y-f[1].y,j=Math.sqrt(i*i+k*k);i/=j;k/=j;g=g*i+h*k;if(g<=0||j=0&&q>=0)return r=z/(z+q),a.x=b[1].x+r*(b[2].x-b[1].x),a.y=b[1].y+r*(b[2].y-b[1].y),c.x=e[1].x+r*(e[2].x-e[1].x),c.y=e[1].y+r*(e[2].y-e[1].y),b[0].SetV(b[2]),e[0].SetV(e[2]),
+f[0].SetV(f[2]),2;g=n*(j*h-l*g);if(g<=0&&r>=0&&u>=0)return r/=r+u,a.x=b[0].x+r*(b[2].x-b[0].x),a.y=b[0].y+r*(b[2].y-b[0].y),c.x=e[0].x+r*(e[2].x-e[0].x),c.y=e[0].y+r*(e[2].y-e[0].y),b[1].SetV(b[2]),e[1].SetV(e[2]),f[1].SetV(f[2]),2;r=1/(i+g+m);f=i*r;r*=g;u=1-f-r;a.x=f*b[0].x+r*b[1].x+u*b[2].x;a.y=f*b[0].y+r*b[1].y+u*b[2].y;c.x=f*e[0].x+r*e[1].x+u*e[2].x;c.y=f*e[0].y+r*e[1].y+u*e[2].y;return 3};b2Distance.InPoinsts=function(a,c,b){for(var e=0;e0)return!1}return!0},initialize:function(a,c,b){this.m_R=new b2Mat22;this.m_position=new b2Vec2;this.m_userData=a.userData;this.m_friction=a.friction;this.m_restitution=a.restitution;this.m_body=c;this.m_proxyId=b2Pair.b2_nullProxy;this.m_maxRadius=
+0;this.m_categoryBits=a.categoryBits;this.m_maskBits=a.maskBits;this.m_groupIndex=a.groupIndex;this.syncAABB=new b2AABB;this.syncMat=new b2Mat22;this.m_localCentroid=new b2Vec2;this.m_localOBB=new b2OBB;var e=0,f,c=new b2AABB;this.m_vertices=Array(b2Settings.b2_maxPolyVertices);this.m_coreVertices=Array(b2Settings.b2_maxPolyVertices);this.m_normals=Array(b2Settings.b2_maxPolyVertices);this.m_type=b2Shape.e_polyShape;var g=new b2Mat22(a.localRotation);if(a.type==b2Shape.e_boxShape){this.m_localCentroid.x=
+a.localPosition.x-b.x;this.m_localCentroid.y=a.localPosition.y-b.y;this.m_vertexCount=4;b=a.extents.x;f=a.extents.y;var a=Math.max(0,b-2*b2Settings.b2_linearSlop),h=Math.max(0,f-2*b2Settings.b2_linearSlop),e=this.m_vertices[0]=new b2Vec2;e.x=g.col1.x*b+g.col2.x*f;e.y=g.col1.y*b+g.col2.y*f;e=this.m_vertices[1]=new b2Vec2;e.x=g.col1.x*-b+g.col2.x*f;e.y=g.col1.y*-b+g.col2.y*f;e=this.m_vertices[2]=new b2Vec2;e.x=g.col1.x*-b+g.col2.x*-f;e.y=g.col1.y*-b+g.col2.y*-f;e=this.m_vertices[3]=new b2Vec2;e.x=g.col1.x*
+b+g.col2.x*-f;e.y=g.col1.y*b+g.col2.y*-f;e=this.m_coreVertices[0]=new b2Vec2;e.x=g.col1.x*a+g.col2.x*h;e.y=g.col1.y*a+g.col2.y*h;e=this.m_coreVertices[1]=new b2Vec2;e.x=g.col1.x*-a+g.col2.x*h;e.y=g.col1.y*-a+g.col2.y*h;e=this.m_coreVertices[2]=new b2Vec2;e.x=g.col1.x*-a+g.col2.x*-h;e.y=g.col1.y*-a+g.col2.y*-h;e=this.m_coreVertices[3]=new b2Vec2;e.x=g.col1.x*a+g.col2.x*-h;e.y=g.col1.y*a+g.col2.y*-h}else{this.m_vertexCount=a.vertexCount;b2Shape.PolyCentroid(a.vertices,a.vertexCount,b2PolyShape.tempVec);
+var h=b2PolyShape.tempVec.x,i=b2PolyShape.tempVec.y;this.m_localCentroid.x=a.localPosition.x+(g.col1.x*h+g.col2.x*i)-b.x;this.m_localCentroid.y=a.localPosition.y+(g.col1.y*h+g.col2.y*i)-b.y;for(e=0;eNumber.MIN_VALUE&&
+(b*=1/k,f*=1/k);this.m_coreVertices[e].x=this.m_vertices[e].x-2*b2Settings.b2_linearSlop*b;this.m_coreVertices[e].y=this.m_vertices[e].y-2*b2Settings.b2_linearSlop*f}}a=g=Number.MAX_VALUE;b=-Number.MAX_VALUE;f=-Number.MAX_VALUE;for(e=this.m_maxRadius=0;ef&&(c=g,f=h)}b.Set(this.m_position.x+(this.m_R.col1.x*this.m_coreVertices[c].x+this.m_R.col2.x*this.m_coreVertices[c].y),this.m_position.y+(this.m_R.col1.y*this.m_coreVertices[c].x+this.m_R.col2.y*this.m_coreVertices[c].y))},m_localCentroid:new b2Vec2,m_localOBB:new b2OBB,m_vertices:null,m_coreVertices:null,m_vertexCount:0,m_normals:null});
+b2PolyShape.tempVec=new b2Vec2;b2PolyShape.tAbsR=new b2Mat22;var b2Body=Class.create();
+b2Body.prototype={SetOriginPosition:function(a,c){if(!this.IsFrozen()){this.m_rotation=c;this.m_R.Set(this.m_rotation);this.m_position=b2Math.AddVV(a,b2Math.b2MulMV(this.m_R,this.m_center));this.m_position0.SetV(this.m_position);this.m_rotation0=this.m_rotation;for(var b=this.m_shapeList;b!=null;b=b.m_next)b.Synchronize(this.m_position,this.m_R,this.m_position,this.m_R);this.m_world.m_broadPhase.Commit()}},GetOriginPosition:function(){return b2Math.SubtractVV(this.m_position,b2Math.b2MulMV(this.m_R,
+this.m_center))},SetCenterPosition:function(a,c){if(!this.IsFrozen()){this.m_rotation=c;this.m_R.Set(this.m_rotation);this.m_position.SetV(a);this.m_position0.SetV(this.m_position);this.m_rotation0=this.m_rotation;for(var b=this.m_shapeList;b!=null;b=b.m_next)b.Synchronize(this.m_position,this.m_R,this.m_position,this.m_R);this.m_world.m_broadPhase.Commit()}},GetCenterPosition:function(){return this.m_position},GetRotation:function(){return this.m_rotation},GetRotationMatrix:function(){return this.m_R},
+SetLinearVelocity:function(a){this.m_linearVelocity.SetV(a)},GetLinearVelocity:function(){return this.m_linearVelocity},SetAngularVelocity:function(a){this.m_angularVelocity=a},GetAngularVelocity:function(){return this.m_angularVelocity},ApplyForce:function(a,c){this.IsSleeping()==!1&&(this.m_force.Add(a),this.m_torque+=b2Math.b2CrossVV(b2Math.SubtractVV(c,this.m_position),a))},ApplyTorque:function(a){this.IsSleeping()==!1&&(this.m_torque+=a)},ApplyImpulse:function(a,c){this.IsSleeping()==!1&&(this.m_linearVelocity.Add(b2Math.MulFV(this.m_invMass,
+a)),this.m_angularVelocity+=this.m_invI*b2Math.b2CrossVV(b2Math.SubtractVV(c,this.m_position),a))},GetMass:function(){return this.m_mass},GetInertia:function(){return this.m_I},GetWorldPoint:function(a){return b2Math.AddVV(this.m_position,b2Math.b2MulMV(this.m_R,a))},GetWorldVector:function(a){return b2Math.b2MulMV(this.m_R,a)},GetLocalPoint:function(a){return b2Math.b2MulTMV(this.m_R,b2Math.SubtractVV(a,this.m_position))},GetLocalVector:function(a){return b2Math.b2MulTMV(this.m_R,a)},IsStatic:function(){return(this.m_flags&
+b2Body.e_staticFlag)==b2Body.e_staticFlag},IsFrozen:function(){return(this.m_flags&b2Body.e_frozenFlag)==b2Body.e_frozenFlag},IsSleeping:function(){return(this.m_flags&b2Body.e_sleepFlag)==b2Body.e_sleepFlag},AllowSleeping:function(a){a?this.m_flags|=b2Body.e_allowSleepFlag:(this.m_flags&=~b2Body.e_allowSleepFlag,this.WakeUp())},WakeUp:function(){this.m_flags&=~b2Body.e_sleepFlag;this.m_sleepTime=0},GetShapeList:function(){return this.m_shapeList},GetContactList:function(){return this.m_contactList},
+GetJointList:function(){return this.m_jointList},GetNext:function(){return this.m_next},GetUserData:function(){return this.m_userData},initialize:function(a,c){this.sMat0=new b2Mat22;this.m_position=new b2Vec2;this.m_R=new b2Mat22(0);this.m_position0=new b2Vec2;var b=0,e,f;this.m_flags=0;this.m_position.SetV(a.position);this.m_rotation=a.rotation;this.m_R.Set(this.m_rotation);this.m_position0.SetV(this.m_position);this.m_rotation0=this.m_rotation;this.m_world=c;this.m_linearDamping=b2Math.b2Clamp(1-
+a.linearDamping,0,1);this.m_angularDamping=b2Math.b2Clamp(1-a.angularDamping,0,1);this.m_force=new b2Vec2(0,0);this.m_mass=this.m_torque=0;for(var g=Array(b2Settings.b2_maxShapesPerBody),b=0;b0?(this.m_center.Multiply(1/this.m_mass),this.m_position.Add(b2Math.b2MulMV(this.m_R,this.m_center))):this.m_flags|=b2Body.e_staticFlag;for(b=this.m_I=0;b0?1/this.m_mass:0;this.m_invI=this.m_I>0&&a.preventRotation==!1?1/this.m_I:this.m_I=0;this.m_linearVelocity=b2Math.AddVV(a.linearVelocity,
+b2Math.b2CrossFV(a.angularVelocity,this.m_center));this.m_angularVelocity=a.angularVelocity;this.m_shapeList=this.m_next=this.m_prev=this.m_contactList=this.m_jointList=null;for(b=0;b0;return(a.m_maskBits&c.m_categoryBits)!=0&&(a.m_categoryBits&c.m_maskBits)!=0},initialize:function(){}};b2CollisionFilter.b2_defaultFilter=new b2CollisionFilter;var b2Island=Class.create();
+b2Island.prototype={initialize:function(a,c,b,e){var f=0;this.m_bodyCapacity=a;this.m_contactCapacity=c;this.m_jointCapacity=b;this.m_jointCount=this.m_contactCount=this.m_bodyCount=0;this.m_bodies=Array(a);for(f=0;fg||b2Math.b2Dot(b.m_linearVelocity,b.m_linearVelocity)>f?e=b.m_sleepTime=0:(b.m_sleepTime+=a,e=b2Math.b2Min(e,b.m_sleepTime))}if(e>=b2Settings.b2_timeToSleep)for(c=0;c0&&(a.m_shape1.m_body.WakeUp(),a.m_shape2.m_body.WakeUp());var b=b2Contact.s_registers[a.m_shape1.m_type][a.m_shape2.m_type].destroyFcn;b(a,c)};b2Contact.s_registers=null;b2Contact.s_initialized=!1;var b2ContactConstraint=Class.create();
+b2ContactConstraint.prototype={initialize:function(){this.normal=new b2Vec2;this.points=Array(b2Settings.b2_maxManifoldPoints);for(var a=0;a0)v.velocityBias=-60*v.separation;A=y.normal.x*(p+
+-r*t-n- -s*D)+y.normal.y*(q+r*F-o-s*A);A<-b2Settings.b2_velocityThreshold&&(v.velocityBias+=-y.restitution*A)}++g}},PreSolve:function(){for(var a,c,b=0;b=-b2Settings.b2_linearSlop},PostSolve:function(){for(var a=0;a0?1:0},GetManifolds:function(){return this.m_manifold},m_manifold:[new b2Manifold]});
+b2CircleContact.Create=function(a,c){return new b2CircleContact(a,c)};b2CircleContact.Destroy=function(){};var b2Conservative=Class.create();b2Conservative.prototype={initialize:function(){}};b2Conservative.R1=new b2Mat22;b2Conservative.R2=new b2Mat22;b2Conservative.x1=new b2Vec2;b2Conservative.x2=new b2Vec2;
+b2Conservative.Conservative=function(a,c){var b=a.GetBody(),e=c.GetBody(),f=b.m_position.x-b.m_position0.x,g=b.m_position.y-b.m_position0.y,h=b.m_rotation-b.m_rotation0,i=e.m_position.x-e.m_position0.x,k=e.m_position.y-e.m_position0.y,j=e.m_rotation-e.m_rotation0,l=a.GetMaxRadius(),m=c.GetMaxRadius(),n=b.m_position0.x,o=b.m_position0.y,p=b.m_rotation0,q=e.m_position0.x,s=e.m_position0.y,r=e.m_rotation0,u=n,z=o,x=p,B=q,y=s,C=r;b2Conservative.R1.Set(x);b2Conservative.R2.Set(C);a.QuickSync(p1,b2Conservative.R1);
+c.QuickSync(p2,b2Conservative.R2);var t=0,v,A;v=0;for(var D=!0,F=0;F<10;++F){var E=b2Distance.Distance(b2Conservative.x1,b2Conservative.x2,a,c);if(EFLT_EPSILON&&(d*=b2_linearSlop/f),b.IsStatic()?(b.m_position.x=u,b.m_position.y=z):(b.m_position.x=u-v,b.m_position.y=z-A),b.m_rotation=x,b.m_R.Set(x),b.QuickSyncShapes(),e.IsStatic()?(e.m_position.x=B,e.m_position.y=y):(e.m_position.x=B+v,e.m_position.y=
+y+A),e.m_position.x=B+v,e.m_position.y=y+A,e.m_rotation=C,e.m_R.Set(C),e.QuickSyncShapes(),!0;a.QuickSync(b.m_position,b.m_R);c.QuickSync(e.m_position,e.m_R);return!1};var b2NullContact=Class.create();Object.extend(b2NullContact.prototype,b2Contact.prototype);
+Object.extend(b2NullContact.prototype,{initialize:function(a,c){this.m_node1=new b2ContactNode;this.m_node2=new b2ContactNode;this.m_flags=0;!a||!c?this.m_shape2=this.m_shape1=null:(this.m_shape1=a,this.m_shape2=c,this.m_manifoldCount=0,this.m_friction=Math.sqrt(this.m_shape1.m_friction*this.m_shape2.m_friction),this.m_restitution=b2Math.b2Max(this.m_shape1.m_restitution,this.m_shape2.m_restitution),this.m_next=this.m_prev=null,this.m_node1.contact=null,this.m_node1.prev=null,this.m_node1.next=null,
+this.m_node1.other=null,this.m_node2.contact=null,this.m_node2.prev=null,this.m_node2.next=null,this.m_node2.other=null)},Evaluate:function(){},GetManifolds:function(){return null}});var b2PolyAndCircleContact=Class.create();Object.extend(b2PolyAndCircleContact.prototype,b2Contact.prototype);
+Object.extend(b2PolyAndCircleContact.prototype,{initialize:function(a,c){this.m_node1=new b2ContactNode;this.m_node2=new b2ContactNode;this.m_flags=0;!a||!c?this.m_shape2=this.m_shape1=null:(this.m_shape1=a,this.m_shape2=c,this.m_manifoldCount=0,this.m_friction=Math.sqrt(this.m_shape1.m_friction*this.m_shape2.m_friction),this.m_restitution=b2Math.b2Max(this.m_shape1.m_restitution,this.m_shape2.m_restitution),this.m_next=this.m_prev=null,this.m_node1.contact=null,this.m_node1.prev=null,this.m_node1.next=
+null,this.m_node1.other=null,this.m_node2.contact=null,this.m_node2.prev=null,this.m_node2.next=null,this.m_node2.other=null,this.m_manifold=[new b2Manifold],b2Settings.b2Assert(this.m_shape1.m_type==b2Shape.e_polyShape),b2Settings.b2Assert(this.m_shape2.m_type==b2Shape.e_circleShape),this.m_manifold[0].pointCount=0,this.m_manifold[0].points[0].normalImpulse=0,this.m_manifold[0].points[0].tangentImpulse=0)},Evaluate:function(){b2Collision.b2CollidePolyAndCircle(this.m_manifold[0],this.m_shape1,this.m_shape2,
+!1);this.m_manifoldCount=this.m_manifold[0].pointCount>0?1:0},GetManifolds:function(){return this.m_manifold},m_manifold:[new b2Manifold]});b2PolyAndCircleContact.Create=function(a,c){return new b2PolyAndCircleContact(a,c)};b2PolyAndCircleContact.Destroy=function(){};var b2PolyContact=Class.create();Object.extend(b2PolyContact.prototype,b2Contact.prototype);
+Object.extend(b2PolyContact.prototype,{initialize:function(a,c){this.m_node1=new b2ContactNode;this.m_node2=new b2ContactNode;this.m_flags=0;!a||!c?this.m_shape2=this.m_shape1=null:(this.m_shape1=a,this.m_shape2=c,this.m_manifoldCount=0,this.m_friction=Math.sqrt(this.m_shape1.m_friction*this.m_shape2.m_friction),this.m_restitution=b2Math.b2Max(this.m_shape1.m_restitution,this.m_shape2.m_restitution),this.m_next=this.m_prev=null,this.m_node1.contact=null,this.m_node1.prev=null,this.m_node1.next=null,
+this.m_node1.other=null,this.m_node2.contact=null,this.m_node2.prev=null,this.m_node2.next=null,this.m_node2.other=null,this.m0=new b2Manifold,this.m_manifold=[new b2Manifold],this.m_manifold[0].pointCount=0)},m0:new b2Manifold,Evaluate:function(){for(var a=this.m_manifold[0],c=this.m0.points,b=0;b0){c=[!1,!1];for(b=0;b0){var c=a.m_shape1.m_body,b=a.m_shape2.m_body,e=a.m_node1,f=a.m_node2;c.WakeUp();b.WakeUp();if(e.prev)e.prev.next=e.next;if(e.next)e.next.prev=e.prev;if(e==c.m_contactList)c.m_contactList=e.next;e.prev=null;e.next=null;if(f.prev)f.prev.next=f.next;if(f.next)f.next.prev=f.prev;if(f==b.m_contactList)b.m_contactList=f.next;f.prev=null;f.next=null}b2Contact.Destroy(a,this.m_world.m_blockAllocator);--this.m_world.m_contactCount},
+CleanContactList:function(){for(var a=this.m_world.m_contactList;a!=null;){var c=a,a=a.m_next;c.m_flags&b2Contact.e_destroyFlag&&this.DestroyContact(c)}},Collide:function(){for(var a,c,b,e,f=this.m_world.m_contactList;f!=null;f=f.m_next)if(!f.m_shape1.m_body.IsSleeping()||!f.m_shape2.m_body.IsSleeping())if(a=f.GetManifoldCount(),f.Evaluate(),c=f.GetManifoldCount(),a==0&&c>0){a=f.m_shape1.m_body;c=f.m_shape2.m_body;b=f.m_node1;e=f.m_node2;b.contact=f;b.other=c;b.prev=null;b.next=a.m_contactList;if(b.next!=
+null)b.next.prev=f.m_node1;a.m_contactList=f.m_node1;e.contact=f;e.other=a;e.prev=null;e.next=c.m_contactList;if(e.next!=null)e.next.prev=e;c.m_contactList=e}else if(a>0&&c==0){a=f.m_shape1.m_body;c=f.m_shape2.m_body;b=f.m_node1;e=f.m_node2;if(b.prev)b.prev.next=b.next;if(b.next)b.next.prev=b.prev;if(b==a.m_contactList)a.m_contactList=b.next;b.prev=null;b.next=null;if(e.prev)e.prev.next=e.next;if(e.next)e.next.prev=e.prev;if(e==c.m_contactList)c.m_contactList=e.next;e.prev=null;e.next=null}},m_world:null,
+m_nullContact:new b2NullContact,m_destroyImmediate:null});var b2World=Class.create();
+b2World.prototype={initialize:function(a,c,b){this.step=new b2TimeStep;this.m_contactManager=new b2ContactManager;this.m_listener=null;this.m_filter=b2CollisionFilter.b2_defaultFilter;this.m_jointList=this.m_contactList=this.m_bodyList=null;this.m_jointCount=this.m_contactCount=this.m_bodyCount=0;this.m_bodyDestroyList=null;this.m_allowSleep=b;this.m_gravity=c;this.m_contactManager.m_world=this;this.m_broadPhase=new b2BroadPhase(a,this.m_contactManager);this.m_groundBody=this.CreateBody(new b2BodyDef)},
+SetListener:function(a){this.m_listener=a},SetFilter:function(a){this.m_filter=a},CreateBody:function(a){a=new b2Body(a,this);a.m_prev=null;if(a.m_next=this.m_bodyList)this.m_bodyList.m_prev=a;this.m_bodyList=a;++this.m_bodyCount;return a},DestroyBody:function(a){if(!(a.m_flags&b2Body.e_destroyFlag)){if(a.m_prev)a.m_prev.m_next=a.m_next;if(a.m_next)a.m_next.m_prev=a.m_prev;if(a==this.m_bodyList)this.m_bodyList=a.m_next;a.m_flags|=b2Body.e_destroyFlag;--this.m_bodyCount;a.m_prev=null;a.m_next=this.m_bodyDestroyList;
+this.m_bodyDestroyList=a}},CleanBodyList:function(){this.m_contactManager.m_destroyImmediate=!0;for(var a=this.m_bodyDestroyList;a;){for(var c=a,a=a.m_next,b=c.m_jointList;b;){var e=b,b=b.next;this.m_listener&&this.m_listener.NotifyJointDestroyed(e.joint);this.DestroyJoint(e.joint)}c.Destroy()}this.m_bodyDestroyList=null;this.m_contactManager.m_destroyImmediate=!1},CreateJoint:function(a){var c=b2Joint.Create(a,this.m_blockAllocator);c.m_prev=null;if(c.m_next=this.m_jointList)this.m_jointList.m_prev=
+c;this.m_jointList=c;++this.m_jointCount;c.m_node1.joint=c;c.m_node1.other=c.m_body2;c.m_node1.prev=null;if(c.m_node1.next=c.m_body1.m_jointList)c.m_body1.m_jointList.prev=c.m_node1;c.m_body1.m_jointList=c.m_node1;c.m_node2.joint=c;c.m_node2.other=c.m_body1;c.m_node2.prev=null;if(c.m_node2.next=c.m_body2.m_jointList)c.m_body2.m_jointList.prev=c.m_node2;c.m_body2.m_jointList=c.m_node2;if(a.collideConnected==!1)for(a=(a.body1.m_shapeCount0?1/a:0;this.m_positionIterationCount=0;this.m_contactManager.CleanContactList();
+this.CleanBodyList();this.m_contactManager.Collide();var f=new b2Island(this.m_bodyCount,this.m_contactCount,this.m_jointCount,this.m_stackAllocator);for(b=this.m_bodyList;b!=null;b=b.m_next)b.m_flags&=~b2Body.e_islandFlag;for(var g=this.m_contactList;g!=null;g=g.m_next)g.m_flags&=~b2Contact.e_islandFlag;for(g=this.m_jointList;g!=null;g=g.m_next)g.m_islandFlag=!1;for(var g=Array(this.m_bodyCount),h=0;h0;)if(b=g[--i],f.AddBody(b),b.m_flags&=~b2Body.e_sleepFlag,!(b.m_flags&b2Body.e_staticFlag)){for(var k=b.m_contactList;k!=null;k=k.next)if(!(k.contact.m_flags&b2Contact.e_islandFlag))f.AddContact(k.contact),k.contact.m_flags|=b2Contact.e_islandFlag,e=k.other,e.m_flags&b2Body.e_islandFlag||(g[i++]=e,e.m_flags|=b2Body.e_islandFlag);for(b=b.m_jointList;b!=null;b=b.next)if(b.joint.m_islandFlag!=
+!0)f.AddJoint(b.joint),b.joint.m_islandFlag=!0,e=b.other,e.m_flags&b2Body.e_islandFlag||(g[i++]=e,e.m_flags|=b2Body.e_islandFlag)}f.Solve(this.step,this.m_gravity);this.m_positionIterationCount=b2Math.b2Max(this.m_positionIterationCount,b2Island.m_positionIterationCount);this.m_allowSleep&&f.UpdateSleep(a);for(e=0;eb2Settings.b2_linearSlop?this.m_u.Multiply(1/f):this.m_u.SetZero();
+var f=c*this.m_u.y-b*this.m_u.x,g=e*this.m_u.y-a*this.m_u.x;this.m_mass=this.m_body1.m_invMass+this.m_body1.m_invI*f*f+this.m_body2.m_invMass+this.m_body2.m_invI*g*g;this.m_mass=1/this.m_mass;b2World.s_enableWarmStarting?(f=this.m_impulse*this.m_u.x,g=this.m_impulse*this.m_u.y,this.m_body1.m_linearVelocity.x-=this.m_body1.m_invMass*f,this.m_body1.m_linearVelocity.y-=this.m_body1.m_invMass*g,this.m_body1.m_angularVelocity-=this.m_body1.m_invI*(c*g-b*f),this.m_body2.m_linearVelocity.x+=this.m_body2.m_invMass*
+f,this.m_body2.m_linearVelocity.y+=this.m_body2.m_invMass*g,this.m_body2.m_angularVelocity+=this.m_body2.m_invI*(e*g-a*f)):this.m_impulse=0},SolveVelocityConstraints:function(){var a;a=this.m_body1.m_R;var c=a.col1.x*this.m_localAnchor1.x+a.col2.x*this.m_localAnchor1.y,b=a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y;a=this.m_body2.m_R;var e=a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y;a=a.col1.y*this.m_localAnchor2.x+a.col2.y*this.m_localAnchor2.y;var f=-this.m_mass*
+(this.m_u.x*(this.m_body2.m_linearVelocity.x+-this.m_body2.m_angularVelocity*a-(this.m_body1.m_linearVelocity.x+-this.m_body1.m_angularVelocity*b))+this.m_u.y*(this.m_body2.m_linearVelocity.y+this.m_body2.m_angularVelocity*e-(this.m_body1.m_linearVelocity.y+this.m_body1.m_angularVelocity*c)));this.m_impulse+=f;var g=f*this.m_u.x;f*=this.m_u.y;this.m_body1.m_linearVelocity.x-=this.m_body1.m_invMass*g;this.m_body1.m_linearVelocity.y-=this.m_body1.m_invMass*f;this.m_body1.m_angularVelocity-=this.m_body1.m_invI*
+(c*f-b*g);this.m_body2.m_linearVelocity.x+=this.m_body2.m_invMass*g;this.m_body2.m_linearVelocity.y+=this.m_body2.m_invMass*f;this.m_body2.m_angularVelocity+=this.m_body2.m_invI*(e*f-a*g)},SolvePositionConstraints:function(){var a;a=this.m_body1.m_R;var c=a.col1.x*this.m_localAnchor1.x+a.col2.x*this.m_localAnchor1.y,b=a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y;a=this.m_body2.m_R;var e=a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y;a=a.col1.y*this.m_localAnchor2.x+
+a.col2.y*this.m_localAnchor2.y;var f=this.m_body2.m_position.x+e-this.m_body1.m_position.x-c,g=this.m_body2.m_position.y+a-this.m_body1.m_position.y-b,h=Math.sqrt(f*f+g*g);f/=h;g/=h;h-=this.m_length;var h=b2Math.b2Clamp(h,-b2Settings.b2_maxLinearCorrection,b2Settings.b2_maxLinearCorrection),i=-this.m_mass*h;this.m_u.Set(f,g);f=i*this.m_u.x;g=i*this.m_u.y;this.m_body1.m_position.x-=this.m_body1.m_invMass*f;this.m_body1.m_position.y-=this.m_body1.m_invMass*g;this.m_body1.m_rotation-=this.m_body1.m_invI*
+(c*g-b*f);this.m_body2.m_position.x+=this.m_body2.m_invMass*f;this.m_body2.m_position.y+=this.m_body2.m_invMass*g;this.m_body2.m_rotation+=this.m_body2.m_invI*(e*g-a*f);this.m_body1.m_R.Set(this.m_body1.m_rotation);this.m_body2.m_R.Set(this.m_body2.m_rotation);return b2Math.b2Abs(h)a.dt*this.m_maxForce&&this.m_impulse.Multiply(a.dt*this.m_maxForce/h);h=this.m_impulse.x-b;i=this.m_impulse.y-g;c.m_linearVelocity.x+=c.m_invMass*h;c.m_linearVelocity.y+=c.m_invMass*i;c.m_angularVelocity+=c.m_invI*(e*i-f*h)},SolvePositionConstraints:function(){return!0},m_localAnchor:new b2Vec2,m_target:new b2Vec2,
+m_impulse:new b2Vec2,m_ptpMass:new b2Mat22,m_C:new b2Vec2,m_maxForce:null,m_beta:null,m_gamma:null});var b2MouseJointDef=Class.create();Object.extend(b2MouseJointDef.prototype,b2JointDef.prototype);
+Object.extend(b2MouseJointDef.prototype,{initialize:function(){this.type=b2Joint.e_unknownJoint;this.body2=this.body1=this.userData=null;this.collideConnected=!1;this.target=new b2Vec2;this.type=b2Joint.e_mouseJoint;this.maxForce=0;this.frequencyHz=5;this.dampingRatio=0.7;this.timeStep=1/60},target:new b2Vec2,maxForce:null,frequencyHz:null,dampingRatio:null,timeStep:null});var b2PrismaticJoint=Class.create();Object.extend(b2PrismaticJoint.prototype,b2Joint.prototype);
+Object.extend(b2PrismaticJoint.prototype,{GetAnchor1:function(){var a=this.m_body1,c=new b2Vec2;c.SetV(this.m_localAnchor1);c.MulM(a.m_R);c.Add(a.m_position);return c},GetAnchor2:function(){var a=this.m_body2,c=new b2Vec2;c.SetV(this.m_localAnchor2);c.MulM(a.m_R);c.Add(a.m_position);return c},GetJointTranslation:function(){var a=this.m_body1,c=this.m_body2,b;b=a.m_R;var e=b.col1.x*this.m_localAnchor1.x+b.col2.x*this.m_localAnchor1.y,f=b.col1.y*this.m_localAnchor1.x+b.col2.y*this.m_localAnchor1.y;
+b=c.m_R;e=c.m_position.x+(b.col1.x*this.m_localAnchor2.x+b.col2.x*this.m_localAnchor2.y)-(a.m_position.x+e);c=c.m_position.y+(b.col1.y*this.m_localAnchor2.x+b.col2.y*this.m_localAnchor2.y)-(a.m_position.y+f);b=a.m_R;return(b.col1.x*this.m_localXAxis1.x+b.col2.x*this.m_localXAxis1.y)*e+(b.col1.y*this.m_localXAxis1.x+b.col2.y*this.m_localXAxis1.y)*c},GetJointSpeed:function(){var a=this.m_body1,c=this.m_body2,b;b=a.m_R;var e=b.col1.x*this.m_localAnchor1.x+b.col2.x*this.m_localAnchor1.y,f=b.col1.y*this.m_localAnchor1.x+
+b.col2.y*this.m_localAnchor1.y;b=c.m_R;var g=b.col1.x*this.m_localAnchor2.x+b.col2.x*this.m_localAnchor2.y,h=b.col1.y*this.m_localAnchor2.x+b.col2.y*this.m_localAnchor2.y,i=c.m_position.x+g-(a.m_position.x+e),k=c.m_position.y+h-(a.m_position.y+f);b=a.m_R;var j=b.col1.x*this.m_localXAxis1.x+b.col2.x*this.m_localXAxis1.y;b=b.col1.y*this.m_localXAxis1.x+b.col2.y*this.m_localXAxis1.y;var l=a.m_linearVelocity,m=c.m_linearVelocity,a=a.m_angularVelocity,c=c.m_angularVelocity;return i*-a*b+k*a*j+(j*(m.x+
+-c*h-l.x- -a*f)+b*(m.y+c*g-l.y-a*e))},GetMotorForce:function(a){return a*this.m_motorImpulse},SetMotorSpeed:function(a){this.m_motorSpeed=a},SetMotorForce:function(a){this.m_maxMotorForce=a},GetReactionForce:function(a){a*=this.m_limitImpulse;var c;c=this.m_body1.m_R;return new b2Vec2(a*(c.col1.x*this.m_localXAxis1.x+c.col2.x*this.m_localXAxis1.y)+a*(c.col1.x*this.m_localYAxis1.x+c.col2.x*this.m_localYAxis1.y),a*(c.col1.y*this.m_localXAxis1.x+c.col2.y*this.m_localXAxis1.y)+a*(c.col1.y*this.m_localYAxis1.x+
+c.col2.y*this.m_localYAxis1.y))},GetReactionTorque:function(a){return a*this.m_angularImpulse},initialize:function(a){this.m_node1=new b2JointNode;this.m_node2=new b2JointNode;this.m_type=a.type;this.m_next=this.m_prev=null;this.m_body1=a.body1;this.m_body2=a.body2;this.m_collideConnected=a.collideConnected;this.m_islandFlag=!1;this.m_userData=a.userData;this.m_localAnchor1=new b2Vec2;this.m_localAnchor2=new b2Vec2;this.m_localXAxis1=new b2Vec2;this.m_localYAxis1=new b2Vec2;this.m_linearJacobian=
+new b2Jacobian;this.m_motorJacobian=new b2Jacobian;var c,b,e;c=this.m_body1.m_R;b=a.anchorPoint.x-this.m_body1.m_position.x;e=a.anchorPoint.y-this.m_body1.m_position.y;this.m_localAnchor1.Set(b*c.col1.x+e*c.col1.y,b*c.col2.x+e*c.col2.y);c=this.m_body2.m_R;b=a.anchorPoint.x-this.m_body2.m_position.x;e=a.anchorPoint.y-this.m_body2.m_position.y;this.m_localAnchor2.Set(b*c.col1.x+e*c.col1.y,b*c.col2.x+e*c.col2.y);c=this.m_body1.m_R;b=a.axis.x;e=a.axis.y;this.m_localXAxis1.Set(b*c.col1.x+e*c.col1.y,b*
+c.col2.x+e*c.col2.y);this.m_localYAxis1.x=-this.m_localXAxis1.y;this.m_localYAxis1.y=this.m_localXAxis1.x;this.m_initialAngle=this.m_body2.m_rotation-this.m_body1.m_rotation;this.m_linearJacobian.SetZero();this.m_angularImpulse=this.m_angularMass=this.m_linearImpulse=this.m_linearMass=0;this.m_motorJacobian.SetZero();this.m_limitPositionImpulse=this.m_limitImpulse=this.m_motorImpulse=this.m_motorMass=0;this.m_lowerTranslation=a.lowerTranslation;this.m_upperTranslation=a.upperTranslation;this.m_maxMotorForce=
+a.motorForce;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor},PrepareVelocitySolver:function(){var a=this.m_body1,c=this.m_body2,b;b=a.m_R;var e=b.col1.x*this.m_localAnchor1.x+b.col2.x*this.m_localAnchor1.y,f=b.col1.y*this.m_localAnchor1.x+b.col2.y*this.m_localAnchor1.y;b=c.m_R;var g=b.col1.x*this.m_localAnchor2.x+b.col2.x*this.m_localAnchor2.y,h=b.col1.y*this.m_localAnchor2.x+b.col2.y*this.m_localAnchor2.y,i=a.m_invMass,k=c.m_invMass,j=a.m_invI,l=
+c.m_invI;b=a.m_R;var m=b.col1.x*this.m_localYAxis1.x+b.col2.x*this.m_localYAxis1.y;b=b.col1.y*this.m_localYAxis1.x+b.col2.y*this.m_localYAxis1.y;var n=c.m_position.x+g-a.m_position.x,o=c.m_position.y+h-a.m_position.y;this.m_linearJacobian.linear1.x=-m;this.m_linearJacobian.linear1.y=-b;this.m_linearJacobian.linear2.x=m;this.m_linearJacobian.linear2.y=b;this.m_linearJacobian.angular1=-(n*b-o*m);this.m_linearJacobian.angular2=g*b-h*m;this.m_linearMass=i+j*this.m_linearJacobian.angular1*this.m_linearJacobian.angular1+
+k+l*this.m_linearJacobian.angular2*this.m_linearJacobian.angular2;this.m_linearMass=1/this.m_linearMass;this.m_angularMass=1/(j+l);if(this.m_enableLimit||this.m_enableMotor)if(b=a.m_R,m=b.col1.x*this.m_localXAxis1.x+b.col2.x*this.m_localXAxis1.y,b=b.col1.y*this.m_localXAxis1.x+b.col2.y*this.m_localXAxis1.y,this.m_motorJacobian.linear1.x=-m,this.m_motorJacobian.linear1.y=-b,this.m_motorJacobian.linear2.x=m,this.m_motorJacobian.linear2.y=b,this.m_motorJacobian.angular1=-(n*b-o*m),this.m_motorJacobian.angular2=
+g*b-h*m,this.m_motorMass=i+j*this.m_motorJacobian.angular1*this.m_motorJacobian.angular1+k+l*this.m_motorJacobian.angular2*this.m_motorJacobian.angular2,this.m_motorMass=1/this.m_motorMass,this.m_enableLimit)if(e=m*(n-e)+b*(o-f),b2Math.b2Abs(this.m_upperTranslation-this.m_lowerTranslation)<2*b2Settings.b2_linearSlop)this.m_limitState=b2Joint.e_equalLimits;else if(e<=this.m_lowerTranslation){if(this.m_limitState!=b2Joint.e_atLowerLimit)this.m_limitImpulse=0;this.m_limitState=b2Joint.e_atLowerLimit}else if(e>=
+this.m_upperTranslation){if(this.m_limitState!=b2Joint.e_atUpperLimit)this.m_limitImpulse=0;this.m_limitState=b2Joint.e_atUpperLimit}else this.m_limitState=b2Joint.e_inactiveLimit,this.m_limitImpulse=0;if(this.m_enableMotor==!1)this.m_motorImpulse=0;if(this.m_enableLimit==!1)this.m_limitImpulse=0;b2World.s_enableWarmStarting?(e=this.m_linearImpulse*this.m_linearJacobian.linear1.y+(this.m_motorImpulse+this.m_limitImpulse)*this.m_motorJacobian.linear1.y,f=this.m_linearImpulse*this.m_linearJacobian.linear2.x+
+(this.m_motorImpulse+this.m_limitImpulse)*this.m_motorJacobian.linear2.x,g=this.m_linearImpulse*this.m_linearJacobian.linear2.y+(this.m_motorImpulse+this.m_limitImpulse)*this.m_motorJacobian.linear2.y,h=this.m_linearImpulse*this.m_linearJacobian.angular1-this.m_angularImpulse+(this.m_motorImpulse+this.m_limitImpulse)*this.m_motorJacobian.angular1,n=this.m_linearImpulse*this.m_linearJacobian.angular2+this.m_angularImpulse+(this.m_motorImpulse+this.m_limitImpulse)*this.m_motorJacobian.angular2,a.m_linearVelocity.x+=
+i*(this.m_linearImpulse*this.m_linearJacobian.linear1.x+(this.m_motorImpulse+this.m_limitImpulse)*this.m_motorJacobian.linear1.x),a.m_linearVelocity.y+=i*e,a.m_angularVelocity+=j*h,c.m_linearVelocity.x+=k*f,c.m_linearVelocity.y+=k*g,c.m_angularVelocity+=l*n):this.m_motorImpulse=this.m_limitImpulse=this.m_angularImpulse=this.m_linearImpulse=0;this.m_limitPositionImpulse=0},SolveVelocityConstraints:function(a){var c=this.m_body1,b=this.m_body2,e=c.m_invMass,f=b.m_invMass,g=c.m_invI,h=b.m_invI,i=-this.m_linearMass*
+this.m_linearJacobian.Compute(c.m_linearVelocity,c.m_angularVelocity,b.m_linearVelocity,b.m_angularVelocity);this.m_linearImpulse+=i;c.m_linearVelocity.x+=e*i*this.m_linearJacobian.linear1.x;c.m_linearVelocity.y+=e*i*this.m_linearJacobian.linear1.y;c.m_angularVelocity+=g*i*this.m_linearJacobian.angular1;b.m_linearVelocity.x+=f*i*this.m_linearJacobian.linear2.x;b.m_linearVelocity.y+=f*i*this.m_linearJacobian.linear2.y;b.m_angularVelocity+=h*i*this.m_linearJacobian.angular2;i=-this.m_angularMass*(b.m_angularVelocity-
+c.m_angularVelocity);this.m_angularImpulse+=i;c.m_angularVelocity-=g*i;b.m_angularVelocity+=h*i;if(this.m_enableMotor&&this.m_limitState!=b2Joint.e_equalLimits){var i=-this.m_motorMass*(this.m_motorJacobian.Compute(c.m_linearVelocity,c.m_angularVelocity,b.m_linearVelocity,b.m_angularVelocity)-this.m_motorSpeed),k=this.m_motorImpulse;this.m_motorImpulse=b2Math.b2Clamp(this.m_motorImpulse+i,-a.dt*this.m_maxMotorForce,a.dt*this.m_maxMotorForce);i=this.m_motorImpulse-k;c.m_linearVelocity.x+=e*i*this.m_motorJacobian.linear1.x;
+c.m_linearVelocity.y+=e*i*this.m_motorJacobian.linear1.y;c.m_angularVelocity+=g*i*this.m_motorJacobian.angular1;b.m_linearVelocity.x+=f*i*this.m_motorJacobian.linear2.x;b.m_linearVelocity.y+=f*i*this.m_motorJacobian.linear2.y;b.m_angularVelocity+=h*i*this.m_motorJacobian.angular2}if(this.m_enableLimit&&this.m_limitState!=b2Joint.e_inactiveLimit){i=-this.m_motorMass*this.m_motorJacobian.Compute(c.m_linearVelocity,c.m_angularVelocity,b.m_linearVelocity,b.m_angularVelocity);if(this.m_limitState==b2Joint.e_equalLimits)this.m_limitImpulse+=
+i;else if(this.m_limitState==b2Joint.e_atLowerLimit)a=this.m_limitImpulse,this.m_limitImpulse=b2Math.b2Max(this.m_limitImpulse+i,0),i=this.m_limitImpulse-a;else if(this.m_limitState==b2Joint.e_atUpperLimit)a=this.m_limitImpulse,this.m_limitImpulse=b2Math.b2Min(this.m_limitImpulse+i,0),i=this.m_limitImpulse-a;c.m_linearVelocity.x+=e*i*this.m_motorJacobian.linear1.x;c.m_linearVelocity.y+=e*i*this.m_motorJacobian.linear1.y;c.m_angularVelocity+=g*i*this.m_motorJacobian.angular1;b.m_linearVelocity.x+=
+f*i*this.m_motorJacobian.linear2.x;b.m_linearVelocity.y+=f*i*this.m_motorJacobian.linear2.y;b.m_angularVelocity+=h*i*this.m_motorJacobian.angular2}},SolvePositionConstraints:function(){var a,c,b=this.m_body1,e=this.m_body2,f=b.m_invMass,g=e.m_invMass,h=b.m_invI,i=e.m_invI;a=b.m_R;var k=a.col1.x*this.m_localAnchor1.x+a.col2.x*this.m_localAnchor1.y,j=a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y;a=e.m_R;var l=a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y;a=a.col1.y*this.m_localAnchor2.x+
+a.col2.y*this.m_localAnchor2.y;var k=b.m_position.x+k,j=b.m_position.y+j,l=e.m_position.x+l,m=e.m_position.y+a;a=b.m_R;var n=(a.col1.x*this.m_localYAxis1.x+a.col2.x*this.m_localYAxis1.y)*(l-k)+(a.col1.y*this.m_localYAxis1.x+a.col2.y*this.m_localYAxis1.y)*(m-j),n=b2Math.b2Clamp(n,-b2Settings.b2_maxLinearCorrection,b2Settings.b2_maxLinearCorrection);c=-this.m_linearMass*n;b.m_position.x+=f*c*this.m_linearJacobian.linear1.x;b.m_position.y+=f*c*this.m_linearJacobian.linear1.y;b.m_rotation+=h*c*this.m_linearJacobian.angular1;
+e.m_position.x+=g*c*this.m_linearJacobian.linear2.x;e.m_position.y+=g*c*this.m_linearJacobian.linear2.y;e.m_rotation+=i*c*this.m_linearJacobian.angular2;n=b2Math.b2Abs(n);c=e.m_rotation-b.m_rotation-this.m_initialAngle;c=b2Math.b2Clamp(c,-b2Settings.b2_maxAngularCorrection,b2Settings.b2_maxAngularCorrection);var o=-this.m_angularMass*c;b.m_rotation-=b.m_invI*o;b.m_R.Set(b.m_rotation);e.m_rotation+=e.m_invI*o;e.m_R.Set(e.m_rotation);o=b2Math.b2Abs(c);if(this.m_enableLimit&&this.m_limitState!=b2Joint.e_inactiveLimit){a=
+b.m_R;k=a.col1.x*this.m_localAnchor1.x+a.col2.x*this.m_localAnchor1.y;j=a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y;a=e.m_R;l=a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y;a=a.col1.y*this.m_localAnchor2.x+a.col2.y*this.m_localAnchor2.y;k=b.m_position.x+k;j=b.m_position.y+j;l=e.m_position.x+l;m=e.m_position.y+a;a=b.m_R;k=(a.col1.x*this.m_localXAxis1.x+a.col2.x*this.m_localXAxis1.y)*(l-k)+(a.col1.y*this.m_localXAxis1.x+a.col2.y*this.m_localXAxis1.y)*(m-j);a=0;if(this.m_limitState==
+b2Joint.e_equalLimits)a=b2Math.b2Clamp(k,-b2Settings.b2_maxLinearCorrection,b2Settings.b2_maxLinearCorrection),a*=-this.m_motorMass,n=b2Math.b2Max(n,b2Math.b2Abs(c));else if(this.m_limitState==b2Joint.e_atLowerLimit)a=k-this.m_lowerTranslation,n=b2Math.b2Max(n,-a),a=b2Math.b2Clamp(a+b2Settings.b2_linearSlop,-b2Settings.b2_maxLinearCorrection,0),a*=-this.m_motorMass,c=this.m_limitPositionImpulse,this.m_limitPositionImpulse=b2Math.b2Max(this.m_limitPositionImpulse+a,0),a=this.m_limitPositionImpulse-
+c;else if(this.m_limitState==b2Joint.e_atUpperLimit)a=k-this.m_upperTranslation,n=b2Math.b2Max(n,a),a=b2Math.b2Clamp(a-b2Settings.b2_linearSlop,0,b2Settings.b2_maxLinearCorrection),a*=-this.m_motorMass,c=this.m_limitPositionImpulse,this.m_limitPositionImpulse=b2Math.b2Min(this.m_limitPositionImpulse+a,0),a=this.m_limitPositionImpulse-c;b.m_position.x+=f*a*this.m_motorJacobian.linear1.x;b.m_position.y+=f*a*this.m_motorJacobian.linear1.y;b.m_rotation+=h*a*this.m_motorJacobian.angular1;b.m_R.Set(b.m_rotation);
+e.m_position.x+=g*a*this.m_motorJacobian.linear2.x;e.m_position.y+=g*a*this.m_motorJacobian.linear2.y;e.m_rotation+=i*a*this.m_motorJacobian.angular2;e.m_R.Set(e.m_rotation)}return n<=b2Settings.b2_linearSlop&&o<=b2Settings.b2_angularSlop},m_localAnchor1:new b2Vec2,m_localAnchor2:new b2Vec2,m_localXAxis1:new b2Vec2,m_localYAxis1:new b2Vec2,m_initialAngle:null,m_linearJacobian:new b2Jacobian,m_linearMass:null,m_linearImpulse:null,m_angularMass:null,m_angularImpulse:null,m_motorJacobian:new b2Jacobian,
+m_motorMass:null,m_motorImpulse:null,m_limitImpulse:null,m_limitPositionImpulse:null,m_lowerTranslation:null,m_upperTranslation:null,m_maxMotorForce:null,m_motorSpeed:null,m_enableLimit:null,m_enableMotor:null,m_limitState:0});var b2PrismaticJointDef=Class.create();Object.extend(b2PrismaticJointDef.prototype,b2JointDef.prototype);
+Object.extend(b2PrismaticJointDef.prototype,{initialize:function(){this.type=b2Joint.e_unknownJoint;this.body2=this.body1=this.userData=null;this.collideConnected=!1;this.type=b2Joint.e_prismaticJoint;this.anchorPoint=new b2Vec2(0,0);this.axis=new b2Vec2(0,0);this.motorSpeed=this.motorForce=this.upperTranslation=this.lowerTranslation=0;this.enableMotor=this.enableLimit=!1},anchorPoint:null,axis:null,lowerTranslation:null,upperTranslation:null,motorForce:null,motorSpeed:null,enableLimit:null,enableMotor:null});
+var b2PulleyJoint=Class.create();Object.extend(b2PulleyJoint.prototype,b2Joint.prototype);
+Object.extend(b2PulleyJoint.prototype,{GetAnchor1:function(){var a=this.m_body1.m_R;return new b2Vec2(this.m_body1.m_position.x+(a.col1.x*this.m_localAnchor1.x+a.col2.x*this.m_localAnchor1.y),this.m_body1.m_position.y+(a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y))},GetAnchor2:function(){var a=this.m_body2.m_R;return new b2Vec2(this.m_body2.m_position.x+(a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y),this.m_body2.m_position.y+(a.col1.y*this.m_localAnchor2.x+a.col2.y*
+this.m_localAnchor2.y))},GetGroundPoint1:function(){return new b2Vec2(this.m_ground.m_position.x+this.m_groundAnchor1.x,this.m_ground.m_position.y+this.m_groundAnchor1.y)},GetGroundPoint2:function(){return new b2Vec2(this.m_ground.m_position.x+this.m_groundAnchor2.x,this.m_ground.m_position.y+this.m_groundAnchor2.y)},GetReactionForce:function(){return new b2Vec2},GetReactionTorque:function(){return 0},GetLength1:function(){var a;a=this.m_body1.m_R;var c=this.m_body1.m_position.x+(a.col1.x*this.m_localAnchor1.x+
+a.col2.x*this.m_localAnchor1.y)-(this.m_ground.m_position.x+this.m_groundAnchor1.x);a=this.m_body1.m_position.y+(a.col1.y*this.m_localAnchor1.x+a.col2.y*this.m_localAnchor1.y)-(this.m_ground.m_position.y+this.m_groundAnchor1.y);return Math.sqrt(c*c+a*a)},GetLength2:function(){var a;a=this.m_body2.m_R;var c=this.m_body2.m_position.x+(a.col1.x*this.m_localAnchor2.x+a.col2.x*this.m_localAnchor2.y)-(this.m_ground.m_position.x+this.m_groundAnchor2.x);a=this.m_body2.m_position.y+(a.col1.y*this.m_localAnchor2.x+
+a.col2.y*this.m_localAnchor2.y)-(this.m_ground.m_position.y+this.m_groundAnchor2.y);return Math.sqrt(c*c+a*a)},GetRatio:function(){return this.m_ratio},initialize:function(a){this.m_node1=new b2JointNode;this.m_node2=new b2JointNode;this.m_type=a.type;this.m_next=this.m_prev=null;this.m_body1=a.body1;this.m_body2=a.body2;this.m_collideConnected=a.collideConnected;this.m_islandFlag=!1;this.m_userData=a.userData;this.m_groundAnchor1=new b2Vec2;this.m_groundAnchor2=new b2Vec2;this.m_localAnchor1=new b2Vec2;
+this.m_localAnchor2=new b2Vec2;this.m_u1=new b2Vec2;this.m_u2=new b2Vec2;var c,b,e;this.m_ground=this.m_body1.m_world.m_groundBody;this.m_groundAnchor1.x=a.groundPoint1.x-this.m_ground.m_position.x;this.m_groundAnchor1.y=a.groundPoint1.y-this.m_ground.m_position.y;this.m_groundAnchor2.x=a.groundPoint2.x-this.m_ground.m_position.x;this.m_groundAnchor2.y=a.groundPoint2.y-this.m_ground.m_position.y;c=this.m_body1.m_R;b=a.anchorPoint1.x-this.m_body1.m_position.x;e=a.anchorPoint1.y-this.m_body1.m_position.y;
+this.m_localAnchor1.x=b*c.col1.x+e*c.col1.y;this.m_localAnchor1.y=b*c.col2.x+e*c.col2.y;c=this.m_body2.m_R;b=a.anchorPoint2.x-this.m_body2.m_position.x;e=a.anchorPoint2.y-this.m_body2.m_position.y;this.m_localAnchor2.x=b*c.col1.x+e*c.col1.y;this.m_localAnchor2.y=b*c.col2.x+e*c.col2.y;this.m_ratio=a.ratio;b=a.groundPoint1.x-a.anchorPoint1.x;e=a.groundPoint1.y-a.anchorPoint1.y;c=Math.sqrt(b*b+e*e);b=a.groundPoint2.x-a.anchorPoint2.x;e=a.groundPoint2.y-a.anchorPoint2.y;b=Math.sqrt(b*b+e*e);e=b2Math.b2Max(0.5*
+b2PulleyJoint.b2_minPulleyLength,c);b=b2Math.b2Max(0.5*b2PulleyJoint.b2_minPulleyLength,b);this.m_constant=e+this.m_ratio*b;this.m_maxLength1=b2Math.b2Clamp(a.maxLength1,e,this.m_constant-this.m_ratio*b2PulleyJoint.b2_minPulleyLength);this.m_maxLength2=b2Math.b2Clamp(a.maxLength2,b,(this.m_constant-b2PulleyJoint.b2_minPulleyLength)/this.m_ratio);this.m_limitImpulse2=this.m_limitImpulse1=this.m_pulleyImpulse=0},PrepareVelocitySolver:function(){var a=this.m_body1,c=this.m_body2,b;b=a.m_R;var e=b.col1.x*
+this.m_localAnchor1.x+b.col2.x*this.m_localAnchor1.y,f=b.col1.y*this.m_localAnchor1.x+b.col2.y*this.m_localAnchor1.y;b=c.m_R;var g=b.col1.x*this.m_localAnchor2.x+b.col2.x*this.m_localAnchor2.y;b=b.col1.y*this.m_localAnchor2.x+b.col2.y*this.m_localAnchor2.y;var h=c.m_position.x+g,i=c.m_position.y+b,k=this.m_ground.m_position.x+this.m_groundAnchor2.x,j=this.m_ground.m_position.y+this.m_groundAnchor2.y;this.m_u1.Set(a.m_position.x+e-(this.m_ground.m_position.x+this.m_groundAnchor1.x),a.m_position.y+
+f-(this.m_ground.m_position.y+this.m_groundAnchor1.y));this.m_u2.Set(h-k,i-j);h=this.m_u1.Length();i=this.m_u2.Length();h>b2Settings.b2_linearSlop?this.m_u1.Multiply(1/h):this.m_u1.SetZero();i>b2Settings.b2_linearSlop?this.m_u2.Multiply(1/i):this.m_u2.SetZero();hb2Settings.b2_linearSlop?
+this.m_u1.Multiply(1/l):this.m_u1.SetZero();m>b2Settings.b2_linearSlop?this.m_u2.Multiply(1/m):this.m_u2.SetZero();l=this.m_constant-l-this.m_ratio*m;p=b2Math.b2Max(p,Math.abs(l));l=b2Math.b2Clamp(l,-b2Settings.b2_maxLinearCorrection,b2Settings.b2_maxLinearCorrection);o=-this.m_pulleyMass*l;l=-o*this.m_u1.x;m=-o*this.m_u1.y;n=-this.m_ratio*o*this.m_u2.x;o=-this.m_ratio*o*this.m_u2.y;a.m_position.x+=a.m_invMass*l;a.m_position.y+=a.m_invMass*m;a.m_rotation+=a.m_invI*(i*m-k*l);c.m_position.x+=c.m_invMass*
+n;c.m_position.y+=c.m_invMass*o;c.m_rotation+=c.m_invI*(j*o-b*n);a.m_R.Set(a.m_rotation);c.m_R.Set(c.m_rotation);if(this.m_limitState1==b2Joint.e_atUpperLimit)b=a.m_R,i=b.col1.x*this.m_localAnchor1.x+b.col2.x*this.m_localAnchor1.y,k=b.col1.y*this.m_localAnchor1.x+b.col2.y*this.m_localAnchor1.y,l=a.m_position.x+i,m=a.m_position.y+k,this.m_u1.Set(l-e,m-f),l=this.m_u1.Length(),l>b2Settings.b2_linearSlop?(this.m_u1.x*=1/l,this.m_u1.y*=1/l):this.m_u1.SetZero(),l=this.m_maxLength1-l,p=b2Math.b2Max(p,-l),
+l=b2Math.b2Clamp(l+b2Settings.b2_linearSlop,-b2Settings.b2_maxLinearCorrection,0),o=-this.m_limitMass1*l,e=this.m_limitPositionImpulse1,this.m_limitPositionImpulse1=b2Math.b2Max(0,this.m_limitPositionImpulse1+o),o=this.m_limitPositionImpulse1-e,l=-o*this.m_u1.x,m=-o*this.m_u1.y,a.m_position.x+=a.m_invMass*l,a.m_position.y+=a.m_invMass*m,a.m_rotation+=a.m_invI*(i*m-k*l),a.m_R.Set(a.m_rotation);if(this.m_limitState2==b2Joint.e_atUpperLimit)b=c.m_R,j=b.col1.x*this.m_localAnchor2.x+b.col2.x*this.m_localAnchor2.y,
+b=b.col1.y*this.m_localAnchor2.x+b.col2.y*this.m_localAnchor2.y,n=c.m_position.x+j,o=c.m_position.y+b,this.m_u2.Set(n-g,o-h),m=this.m_u2.Length(),m>b2Settings.b2_linearSlop?(this.m_u2.x*=1/m,this.m_u2.y*=1/m):this.m_u2.SetZero(),l=this.m_maxLength2-m,p=b2Math.b2Max(p,-l),l=b2Math.b2Clamp(l+b2Settings.b2_linearSlop,-b2Settings.b2_maxLinearCorrection,0),o=-this.m_limitMass2*l,e=this.m_limitPositionImpulse2,this.m_limitPositionImpulse2=b2Math.b2Max(0,this.m_limitPositionImpulse2+o),o=this.m_limitPositionImpulse2-
+e,n=-o*this.m_u2.x,o=-o*this.m_u2.y,c.m_position.x+=c.m_invMass*n,c.m_position.y+=c.m_invMass*o,c.m_rotation+=c.m_invI*(j*o-b*n),c.m_R.Set(c.m_rotation);return p=this.m_upperAngle){if(this.m_limitState!=b2Joint.e_atUpperLimit)this.m_limitImpulse=0;this.m_limitState=
+b2Joint.e_atUpperLimit}else this.m_limitState=b2Joint.e_inactiveLimit,this.m_limitImpulse=0}else this.m_limitImpulse=0;b2World.s_enableWarmStarting?(a.m_linearVelocity.x-=h*this.m_ptpImpulse.x,a.m_linearVelocity.y-=h*this.m_ptpImpulse.y,a.m_angularVelocity-=k*(e*this.m_ptpImpulse.y-f*this.m_ptpImpulse.x+this.m_motorImpulse+this.m_limitImpulse),c.m_linearVelocity.x+=i*this.m_ptpImpulse.x,c.m_linearVelocity.y+=i*this.m_ptpImpulse.y,c.m_angularVelocity+=j*(g*this.m_ptpImpulse.y-b*this.m_ptpImpulse.x+
+this.m_motorImpulse+this.m_limitImpulse)):(this.m_ptpImpulse.SetZero(),this.m_limitImpulse=this.m_motorImpulse=0);this.m_limitPositionImpulse=0},SolveVelocityConstraints:function(a){var c=this.m_body1,b=this.m_body2,e;e=c.m_R;var f=e.col1.x*this.m_localAnchor1.x+e.col2.x*this.m_localAnchor1.y,g=e.col1.y*this.m_localAnchor1.x+e.col2.y*this.m_localAnchor1.y;e=b.m_R;var h=e.col1.x*this.m_localAnchor2.x+e.col2.x*this.m_localAnchor2.y;e=e.col1.y*this.m_localAnchor2.x+e.col2.y*this.m_localAnchor2.y;var i=
+b.m_linearVelocity.x+-b.m_angularVelocity*e-c.m_linearVelocity.x- -c.m_angularVelocity*g,k=b.m_linearVelocity.y+b.m_angularVelocity*h-c.m_linearVelocity.y-c.m_angularVelocity*f,j=-(this.m_ptpMass.col1.x*i+this.m_ptpMass.col2.x*k),i=-(this.m_ptpMass.col1.y*i+this.m_ptpMass.col2.y*k);this.m_ptpImpulse.x+=j;this.m_ptpImpulse.y+=i;c.m_linearVelocity.x-=c.m_invMass*j;c.m_linearVelocity.y-=c.m_invMass*i;c.m_angularVelocity-=c.m_invI*(f*i-g*j);b.m_linearVelocity.x+=b.m_invMass*j;b.m_linearVelocity.y+=b.m_invMass*
+i;b.m_angularVelocity+=b.m_invI*(h*i-e*j);if(this.m_enableMotor&&this.m_limitState!=b2Joint.e_equalLimits)f=-this.m_motorMass*(b.m_angularVelocity-c.m_angularVelocity-this.m_motorSpeed),g=this.m_motorImpulse,this.m_motorImpulse=b2Math.b2Clamp(this.m_motorImpulse+f,-a.dt*this.m_maxMotorTorque,a.dt*this.m_maxMotorTorque),f=this.m_motorImpulse-g,c.m_angularVelocity-=c.m_invI*f,b.m_angularVelocity+=b.m_invI*f;if(this.m_enableLimit&&this.m_limitState!=b2Joint.e_inactiveLimit){f=-this.m_motorMass*(b.m_angularVelocity-
+c.m_angularVelocity);if(this.m_limitState==b2Joint.e_equalLimits)this.m_limitImpulse+=f;else if(this.m_limitState==b2Joint.e_atLowerLimit)a=this.m_limitImpulse,this.m_limitImpulse=b2Math.b2Max(this.m_limitImpulse+f,0),f=this.m_limitImpulse-a;else if(this.m_limitState==b2Joint.e_atUpperLimit)a=this.m_limitImpulse,this.m_limitImpulse=b2Math.b2Min(this.m_limitImpulse+f,0),f=this.m_limitImpulse-a;c.m_angularVelocity-=c.m_invI*f;b.m_angularVelocity+=b.m_invI*f}},SolvePositionConstraints:function(){var a,
+c=this.m_body1,b=this.m_body2,e=0,e=c.m_R,f=e.col1.x*this.m_localAnchor1.x+e.col2.x*this.m_localAnchor1.y,g=e.col1.y*this.m_localAnchor1.x+e.col2.y*this.m_localAnchor1.y,e=b.m_R;a=e.col1.x*this.m_localAnchor2.x+e.col2.x*this.m_localAnchor2.y;var h=e.col1.y*this.m_localAnchor2.x+e.col2.y*this.m_localAnchor2.y,i=b.m_position.x+a-(c.m_position.x+f),k=b.m_position.y+h-(c.m_position.y+g),e=Math.sqrt(i*i+k*k),j=c.m_invMass,l=b.m_invMass,m=c.m_invI,n=b.m_invI;this.K1.col1.x=j+l;this.K1.col2.x=0;this.K1.col1.y=
+0;this.K1.col2.y=j+l;this.K2.col1.x=m*g*g;this.K2.col2.x=-m*f*g;this.K2.col1.y=-m*f*g;this.K2.col2.y=m*f*f;this.K3.col1.x=n*h*h;this.K3.col2.x=-n*a*h;this.K3.col1.y=-n*a*h;this.K3.col2.y=n*a*a;this.K.SetM(this.K1);this.K.AddM(this.K2);this.K.AddM(this.K3);this.K.Solve(b2RevoluteJoint.tImpulse,-i,-k);i=b2RevoluteJoint.tImpulse.x;k=b2RevoluteJoint.tImpulse.y;c.m_position.x-=c.m_invMass*i;c.m_position.y-=c.m_invMass*k;c.m_rotation-=c.m_invI*(f*k-g*i);c.m_R.Set(c.m_rotation);b.m_position.x+=b.m_invMass*
+i;b.m_position.y+=b.m_invMass*k;b.m_rotation+=b.m_invI*(a*k-h*i);b.m_R.Set(b.m_rotation);f=0;if(this.m_enableLimit&&this.m_limitState!=b2Joint.e_inactiveLimit){a=b.m_rotation-c.m_rotation-this.m_intialAngle;g=0;if(this.m_limitState==b2Joint.e_equalLimits)a=b2Math.b2Clamp(a,-b2Settings.b2_maxAngularCorrection,b2Settings.b2_maxAngularCorrection),g=-this.m_motorMass*a,f=b2Math.b2Abs(a);else if(this.m_limitState==b2Joint.e_atLowerLimit)a-=this.m_lowerAngle,f=b2Math.b2Max(0,-a),a=b2Math.b2Clamp(a+b2Settings.b2_angularSlop,
+-b2Settings.b2_maxAngularCorrection,0),g=-this.m_motorMass*a,a=this.m_limitPositionImpulse,this.m_limitPositionImpulse=b2Math.b2Max(this.m_limitPositionImpulse+g,0),g=this.m_limitPositionImpulse-a;else if(this.m_limitState==b2Joint.e_atUpperLimit)a-=this.m_upperAngle,f=b2Math.b2Max(0,a),a=b2Math.b2Clamp(a-b2Settings.b2_angularSlop,0,b2Settings.b2_maxAngularCorrection),g=-this.m_motorMass*a,a=this.m_limitPositionImpulse,this.m_limitPositionImpulse=b2Math.b2Min(this.m_limitPositionImpulse+g,0),g=this.m_limitPositionImpulse-
+a;c.m_rotation-=c.m_invI*g;c.m_R.Set(c.m_rotation);b.m_rotation+=b.m_invI*g;b.m_R.Set(b.m_rotation)}return e<=b2Settings.b2_linearSlop&&f<=b2Settings.b2_angularSlop},m_localAnchor1:new b2Vec2,m_localAnchor2:new b2Vec2,m_ptpImpulse:new b2Vec2,m_motorImpulse:null,m_limitImpulse:null,m_limitPositionImpulse:null,m_ptpMass:new b2Mat22,m_motorMass:null,m_intialAngle:null,m_lowerAngle:null,m_upperAngle:null,m_maxMotorTorque:null,m_motorSpeed:null,m_enableLimit:null,m_enableMotor:null,m_limitState:0});
+b2RevoluteJoint.tImpulse=new b2Vec2;
diff --git a/javascript/examples/Libraries/Box2D/simpleBox2D/data/prototype-min.js b/javascript/examples/Libraries/Box2D/simpleBox2D/data/prototype-min.js
new file mode 100644
index 000000000..e1177783f
--- /dev/null
+++ b/javascript/examples/Libraries/Box2D/simpleBox2D/data/prototype-min.js
@@ -0,0 +1,167 @@
+/* Prototype JavaScript framework, version 1.6.0.2
+ * (c) 2005-2008 Sam Stephenson
+ *
+ * Prototype is freely distributable under the terms of an MIT-style license.
+ * For details, see the Prototype web site: http://www.prototypejs.org/
+ *
+ *--------------------------------------------------------------------------*/
+
+var Prototype={Version:"1.6.0.2",Browser:{IE:!(!window.attachEvent||window.opera),Opera:!!window.opera,WebKit:navigator.userAgent.indexOf("AppleWebKit/")>-1,Gecko:navigator.userAgent.indexOf("Gecko")>-1&&navigator.userAgent.indexOf("KHTML")==-1,MobileSafari:!!navigator.userAgent.match(/Apple.*Mobile.*Safari/)},BrowserFeatures:{XPath:!!document.evaluate,ElementExtensions:!!window.HTMLElement,SpecificElementExtensions:document.createElement("div").__proto__&&document.createElement("div").__proto__!==
+document.createElement("form").__proto__},ScriptFragment:"");
+// add Box2D.js library
+document.write("");
+
+// event handler called once document has loaded ..
+window.onload = function () {
+ tryFindSketch();
+}
+
+// try to get the sketch instance from Processing.js
+function tryFindSketch () {
+ var sketch = Processing.instances[0];
+ if ( sketch == undefined )
+ return setTimeout( tryFindSketch, 200 ); // retry
+
+ var inter = new Box2DJSInterface(sketch);
+ sketch.setBox2DInterface(inter);
+}
+
+/**
+ * This is just a tiny simple wrapper to get you started ...
+ * ... or spawn an idea.
+ *
+ * Based on Ando Yasushi example code.
+ */
+var Box2DJSInterface = (function() {
+ function Box2DJSInterface () {
+ if ( arguments.length <= 0 || typeof arguments[0] !== 'object' ) {
+ alert('You need to pass a Processing instance in here!');
+ return undefined;
+ }
+
+ var world = createWorld();
+ createGround(world);
+ createBox(world, null, -10, 125, 10, 250 );
+ createBox(world, null, 510, 125, 10, 250 );
+
+ var sketch = arguments[0];
+
+ this.update = function () {
+ world.Step( 1/60.0, 1.0 );
+ }
+
+ this.draw = function () {
+ this.drawJoints();
+ this.drawShapes();
+ }
+
+ this.drawJoints = function () {
+ for (var j = world.m_jointList; j; j = j.m_next) {
+ var b1 = j.m_body1;
+ var b2 = j.m_body2;
+ var x1 = b1.m_position;
+ var x2 = b2.m_position;
+ var p1 = j.GetAnchor1();
+ var p2 = j.GetAnchor2();
+
+ switch (j.m_type) {
+ case b2Joint.e_distanceJoint:
+ sketch.drawJoint(p1.x, p1.y, p2.x, p2.y);
+ break;
+
+ case b2Joint.e_pulleyJoint:
+ // TODO
+ break;
+
+ default:
+ if (b1 == world.m_groundBody) {
+ sketch.drawJoint([p1.x, p1.y, x2.x, x2.y]);
+ }
+ else if (b2 == world.m_groundBody) {
+ sketch.drawJoint([p1.x, p1.y, x1.x, x1.y]);
+ }
+ else {
+ sketch.drawJoint([x1.x, x1.y, p1.x, p1.y, x2.x, x2.y, p2.x, p2.y]);
+ }
+ break;
+ }
+ }
+ }
+
+ this.drawShapes = function () {
+ for (var b = world.m_bodyList; b; b = b.m_next) {
+ for (var s = b.GetShapeList(); s != null; s = s.GetNext()) {
+ switch (s.m_type) {
+ case b2Shape.e_circleShape:
+ var pos = s.m_position;
+ var r = s.m_radius;
+ sketch.drawCircle(s.GetUserData(),pos.x,pos.y,r);
+ break;
+ case b2Shape.e_polyShape:
+ var tV = b2Math.AddVV( s.m_position,
+ b2Math.b2MulMV( s.m_R, s.m_vertices[0] ) );
+ var points = [tV.x, tV.y];
+ for (var i = 0; i < s.m_vertexCount; i++) {
+ var v = b2Math.AddVV( s.m_position, b2Math.b2MulMV( s.m_R, s.m_vertices[i] ) );
+ points[points.length] = v.x;
+ points[points.length] = v.y;
+ }
+ points[points.length] = tV.x;
+ points[points.length] = tV.y;
+ sketch.drawPolygon(s.GetUserData(),points);
+ break;
+ }
+ }
+ }
+ }
+
+ this.createBall = function ( c, x, y, r ) {
+ createBall( world, c, x, y, r );
+ }
+
+ this.createBox = function ( c, x, y, w, h ) {
+ createBox( world, c, x, y, w, h, false );
+ }
+ }
+
+ var createWorld = function () {
+ var worldAABB = new b2AABB();
+ worldAABB.minVertex.Set(-1000, -1000);
+ worldAABB.maxVertex.Set(1000, 1000);
+ var gravity = new b2Vec2(0, 300);
+ var doSleep = true;
+ var world = new b2World(worldAABB, gravity, doSleep);
+ return world;
+ }
+
+ var createGround = function (world) {
+ var groundSd = new b2BoxDef();
+ groundSd.extents.Set(1000, 50);
+ groundSd.restitution = 0.2;
+ var groundBd = new b2BodyDef();
+ groundBd.AddShape(groundSd);
+ groundBd.position.Set(-500, 350);
+ return world.CreateBody(groundBd);
+ }
+
+ var createBall = function (world, c, x, y, r) {
+ var ballSd = new b2CircleDef();
+ ballSd.density = 2.0;
+ ballSd.radius = r;
+ ballSd.restitution = 1.0;
+ ballSd.friction = 2.0;
+ ballSd.userData = c;
+ var ballBd = new b2BodyDef();
+ ballBd.AddShape(ballSd);
+ ballBd.position.Set(x, y);
+ return world.CreateBody(ballBd);
+ }
+
+ var createBox = function (world, c, x, y, width, height, fixed) {
+ if (typeof(fixed) == 'undefined') fixed = true;
+ var boxSd = new b2BoxDef();
+ boxSd.userData = c;
+ if (!fixed) boxSd.density = 1.0;
+ boxSd.extents.Set(width, height);
+ var boxBd = new b2BodyDef();
+ boxBd.AddShape(boxSd);
+ boxBd.position.Set(x, y);
+ return world.CreateBody(boxBd);
+ }
+
+ return Box2DJSInterface;
+})();
+
diff --git a/javascript/examples/Libraries/Box2D/simpleBox2D/simpleBox2D.pde b/javascript/examples/Libraries/Box2D/simpleBox2D/simpleBox2D.pde
new file mode 100644
index 000000000..90196f90d
--- /dev/null
+++ b/javascript/examples/Libraries/Box2D/simpleBox2D/simpleBox2D.pde
@@ -0,0 +1,128 @@
+/**
+ * A Box2D (by Erin Catto) example based on a port and examples by Ando Yasushi.
+ * Click & drag to create balls, hold alt/option to create boxes.
+ *
+ *
+ * - Erin Catto http://code.google.com/p/box2d/
+ * - Ando Yasushi http://box2d-js.sourceforge.net/
+ *
+ */
+
+/**
+ * Note that this uses a rather old port of a (ActionScript) Box2D library.
+ */
+
+Box2DInterface b2d;
+
+void setup ()
+{
+ size( 500, 300 );
+
+ colorMode(HSB);
+}
+
+void draw ()
+{
+ background( 100 );
+
+ if ( isDragged )
+ {
+ if ( !keyPressed )
+ {
+ float d = dist(mouseX,mouseY,pressedX,pressedY)*2;
+ fill(120);
+ ellipse( pressedX, pressedY, d, d );
+ }
+ else if ( key == CODED && keyCode == ALT )
+ {
+ float w = mouseX-pressedX;
+ float h = mouseY-pressedY;
+ rect( pressedX-w, pressedY-h, w*2, h*2 );
+ }
+ }
+
+ if ( b2d != null )
+ {
+ b2d.update();
+ b2d.draw();
+ }
+}
+
+float pressedX, pressedY;
+boolean isDragged = false;
+void mousePressed ()
+{
+ pressedX = mouseX; pressedY = mouseY;
+ isDragged = false;
+}
+
+void mouseDragged ()
+{
+ isDragged = true;
+}
+
+void mouseReleased ()
+{
+ color rc = color(random(255), 190, 140);
+
+ if ( !keyPressed )
+ {
+ if ( !isDragged )
+ b2d.createBall( rc, mouseX, mouseY, 20 );
+ else
+ b2d.createBall( rc, pressedX,pressedY, dist(mouseX,mouseY,pressedX,pressedY) );
+ }
+ else if ( key == CODED && keyCode == ALT )
+ {
+ if ( !isDragged )
+ b2d.createBox( rc, mouseX-20, mouseY-20, 40, 40 );
+ else
+ {
+ b2d.createBox( rc, pressedX,pressedY, mouseX-pressedX, mouseY-pressedY );
+ }
+ }
+ isDragged = false;
+}
+
+// these three drawing functions are being called by the
+// Box2D interface in the .js tab
+
+void drawJoints ( float[] points )
+{
+ for ( int i = 0; i < points.length-2; i+=2 )
+ line( points[i], points[i+1], points[i+2], points[i+3] );
+}
+
+void drawPolygon ( color c, float[] points )
+{
+ fill( c == null ? 255 : c );
+ noStroke();
+ beginShape();
+ for ( int i = 0; i < points.length; i+=2 )
+ vertex( points[i], points[i+1] );
+ endShape();
+}
+
+void drawCircle ( color c, float x, float y, float r )
+{
+ fill( c == null ? 255 : c );
+ noStroke();
+ ellipse( x, y, r*2, r*2 );
+}
+
+// this is being called from JavaScript to set the Box2D interface
+void setBox2DInterface ( Box2DInterface b )
+{
+ b2d = b;
+}
+
+// explain Processing how the interface is set up
+interface Box2DInterface
+{
+ void createBall( color c, float x, float y, float r );
+ void createBox( color c, float x, float y, float w, float h );
+
+ void update();
+ void draw();
+}
+