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:"]*>([\\S\\s]*?)<\/script>",JSONFilter:/^\/\*-secure-([\s\S]*)\*\/\s*$/,emptyFunction:function(){},K:function(a){return a}};if(Prototype.Browser.MobileSafari)Prototype.BrowserFeatures.SpecificElementExtensions=!1; +var Class={create:function(){function a(){this.initialize.apply(this,arguments)}var b=null,c=$A(arguments);Object.isFunction(c[0])&&(b=c.shift());Object.extend(a,Class.Methods);a.superclass=b;a.subclasses=[];if(b){var d=function(){};d.prototype=b.prototype;a.prototype=new d;b.subclasses.push(a)}for(b=0;b0;)(e=d.match(a))?(c+=d.slice(0,e.index),c+=String.interpret(b(e)),d=d.slice(e.index+e[0].length)):(c+=d,d="");return c},sub:function(a,b,c){b=this.gsub.prepareReplacement(b);c=Object.isUndefined(c)?1:c;return this.gsub(a,function(a){if(--c<0)return a[0];return b(a)})},scan:function(a,b){this.gsub(a,b);return String(this)},truncate:function(a,b){a=a||30;b=Object.isUndefined(b)? +"...":b;return this.length>a?this.slice(0,a-b.length)+b:String(this)},strip:function(){return this.replace(/^\s+/,"").replace(/\s+$/,"")},stripTags:function(){return this.replace(/<\/?[^>]+>/gi,"")},stripScripts:function(){return this.replace(RegExp(Prototype.ScriptFragment,"img"),"")},extractScripts:function(){var a=RegExp(Prototype.ScriptFragment,"im");return(this.match(RegExp(Prototype.ScriptFragment,"img"))||[]).map(function(b){return(b.match(a)||["",""])[1]})},evalScripts:function(){return this.extractScripts().map(function(a){return eval(a)})}, +escapeHTML:function(){var a=arguments.callee;a.text.data=this;return a.div.innerHTML},unescapeHTML:function(){var a=new Element("div");a.innerHTML=this.stripTags();return a.childNodes[0]?a.childNodes.length>1?$A(a.childNodes).inject("",function(a,c){return a+c.nodeValue}):a.childNodes[0].nodeValue:""},toQueryParams:function(a){var b=this.strip().match(/([^?#]*)(#.*)?$/);if(!b)return{};return b[1].split(a||"&").inject({},function(a,b){if((b=b.split("="))[0]){var e=decodeURIComponent(b.shift()),f=b.length> +1?b.join("="):b[0];f!=void 0&&(f=decodeURIComponent(f));e in a?(Object.isArray(a[e])||(a[e]=[a[e]]),a[e].push(f)):a[e]=f}return a})},toArray:function(){return this.split("")},succ:function(){return this.slice(0,this.length-1)+String.fromCharCode(this.charCodeAt(this.length-1)+1)},times:function(a){return a<1?"":Array(a+1).join(this)},camelize:function(){var a=this.split("-"),b=a.length;if(b==1)return a[0];for(var c=this.charAt(0)=="-"?a[0].charAt(0).toUpperCase()+a[0].substring(1):a[0],d=1;d-1},startsWith:function(a){return this.indexOf(a)===0},endsWith:function(a){var b=this.length-a.length;return b>=0&&this.lastIndexOf(a)===b},empty:function(){return this==""},blank:function(){return/^\s*$/.test(this)},interpolate:function(a,b){return(new Template(this,b)).evaluate(a)}}); +(Prototype.Browser.WebKit||Prototype.Browser.IE)&&Object.extend(String.prototype,{escapeHTML:function(){return this.replace(/&/g,"&").replace(//g,">")},unescapeHTML:function(){return this.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}});String.prototype.gsub.prepareReplacement=function(a){if(Object.isFunction(a))return a;var b=new Template(a);return function(a){return b.evaluate(a)}};String.prototype.parseQuery=String.prototype.toQueryParams; +Object.extend(String.prototype.escapeHTML,{div:document.createElement("div"),text:document.createTextNode("")});with(String.prototype.escapeHTML)div.appendChild(text); +var Template=Class.create({initialize:function(a,b){this.template=a.toString();this.pattern=b||Template.Pattern},evaluate:function(a){Object.isFunction(a.toTemplateReplacements)&&(a=a.toTemplateReplacements());return this.template.gsub(this.pattern,function(b){if(a==null)return"";var c=b[1]||"";if(c=="\\")return b[2];var d=a,e=b[3],f=/^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/,b=f.exec(e);if(b==null)return c;for(;b!=null;){var g=b[1].startsWith("[")?b[2].gsub("\\\\]","]"):b[1],d=d[g];if(null==d||""== +b[3])break;e=e.substring("["==b[3]?b[1].length:b[0].length);b=f.exec(e)}return c+String.interpret(d)})}});Template.Pattern=/(^|.|\r|\n)(#\{(.*?)\})/; +var $break={},Enumerable={each:function(a,b){var c=0,a=a.bind(b);try{this._each(function(b){a(b,c++)})}catch(d){if(d!=$break)throw d;}return this},eachSlice:function(a,b,c){for(var b=b?b.bind(c):Prototype.K,d=-a,e=[],f=this.toArray();(d+=a)=c)c=b});return c},min:function(a,b){var a=a?a.bind(b):Prototype.K,c;this.each(function(b,e){b=a(b,e);if(c==null||bf?1:0}).pluck("value")},toArray:function(){return this.map()},zip:function(){var a=Prototype.K,b=$A(arguments);Object.isFunction(b.last())&&(a=b.pop());var c=[this].concat(b).map($A);return this.map(function(b,e){return a(c.pluck(e))})},size:function(){return this.toArray().length},inspect:function(){return"#"}}; +Object.extend(Enumerable,{map:Enumerable.collect,find:Enumerable.detect,select:Enumerable.findAll,filter:Enumerable.findAll,member:Enumerable.include,entries:Enumerable.toArray,every:Enumerable.all,some:Enumerable.any});function $A(a){if(!a)return[];if(a.toArray)return a.toArray();for(var b=a.length||0,c=Array(b);b--;)c[b]=a[b];return c} +Prototype.Browser.WebKit&&($A=function(a){if(!a)return[];if(!(Object.isFunction(a)&&a=="[object NodeList]")&&a.toArray)return a.toArray();for(var b=a.length||0,c=Array(b);b--;)c[b]=a[b];return c});Array.from=$A;Object.extend(Array.prototype,Enumerable);if(!Array.prototype._reverse)Array.prototype._reverse=Array.prototype.reverse; +Object.extend(Array.prototype,{_each:function(a){for(var b=0,c=this.length;b1?this:this[0]},uniq:function(a){return this.inject([],function(b,c,d){(0==d||(a?b.last()!=c:!b.include(c)))&&b.push(c);return b})},intersect:function(a){return this.uniq().findAll(function(b){return a.detect(function(a){return b===a})})},clone:function(){return[].concat(this)},size:function(){return this.length},inspect:function(){return"["+this.map(Object.inspect).join(", ")+"]"},toJSON:function(){var a=[];this.each(function(b){b= +Object.toJSON(b);Object.isUndefined(b)||a.push(b)});return"["+a.join(", ")+"]"}});if(Object.isFunction(Array.prototype.forEach))Array.prototype._each=Array.prototype.forEach;if(!Array.prototype.indexOf)Array.prototype.indexOf=function(a,b){b||(b=0);var c=this.length;for(b<0&&(b=c+b);b"},toJSON:function(){return Object.toJSON(this.toObject())},clone:function(){return new Hash(this)}}}());Hash.prototype.toTemplateReplacements=Hash.prototype.toObject;Hash.from=$H; +var ObjectRange=Class.create(Enumerable,{initialize:function(a,b,c){this.start=a;this.end=b;this.exclusive=c},_each:function(a){for(var b=this.start;this.include(b);)a(b),b=b.succ()},include:function(a){if(a1&&!(a==4&&this._complete)&&this.respondToReadyState(this.transport.readyState)},setRequestHeaders:function(){var a={"X-Requested-With":"XMLHttpRequest","X-Prototype-Version":Prototype.Version,Accept:"text/javascript, text/html, application/xml, text/xml, */*"};if(this.method=="post"&&(a["Content-type"]=this.options.contentType+(this.options.encoding?"; charset="+this.options.encoding:""),this.transport.overrideMimeType&&(navigator.userAgent.match(/Gecko\/(\d{4})/)|| +[0,2005])[1]<2005))a.Connection="close";if(typeof this.options.requestHeaders=="object"){var b=this.options.requestHeaders;if(Object.isFunction(b.push))for(var c=0,d=b.length;c=200&&a<300},getStatus:function(){try{return this.transport.status||0}catch(a){return 0}},respondToReadyState:function(a){var a=Ajax.Request.Events[a], +b=new Ajax.Response(this);if(a=="Complete"){try{this._complete=!0,(this.options["on"+b.status]||this.options["on"+(this.success()?"Success":"Failure")]||Prototype.emptyFunction)(b,b.headerJSON)}catch(c){this.dispatchException(c)}var d=b.getHeader("Content-type");(this.options.evalJS=="force"||this.options.evalJS&&this.isSameOrigin()&&d&&d.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i))&&this.evalResponse()}try{(this.options["on"+a]||Prototype.emptyFunction)(b,b.headerJSON),Ajax.Responders.dispatch("on"+ +a,this,b,b.headerJSON)}catch(e){this.dispatchException(e)}if(a=="Complete")this.transport.onreadystatechange=Prototype.emptyFunction},isSameOrigin:function(){var a=this.url.match(/^\s*https?:\/\/[^\/]*/);return!a||a[0]=="#{protocol}//#{domain}#{port}".interpolate({protocol:location.protocol,domain:document.domain,port:location.port?":"+location.port:""})},getHeader:function(a){try{return this.transport.getResponseHeader(a)||null}catch(b){return null}},evalResponse:function(){try{return eval((this.transport.responseText|| +"").unfilterJSON())}catch(a){this.dispatchException(a)}},dispatchException:function(a){(this.options.onException||Prototype.emptyFunction)(this,a);Ajax.Responders.dispatch("onException",this,a)}});Ajax.Request.Events=["Uninitialized","Loading","Loaded","Interactive","Complete"]; +Ajax.Response=Class.create({initialize:function(a){this.request=a;var a=this.transport=a.transport,b=this.readyState=a.readyState;if(b>2&&!Prototype.Browser.IE||b==4)this.status=this.getStatus(),this.statusText=this.getStatusText(),this.responseText=String.interpret(a.responseText),this.headerJSON=this._getHeaderJSON();if(b==4)a=a.responseXML,this.responseXML=Object.isUndefined(a)?null:a,this.responseJSON=this._getResponseJSON()},status:0,statusText:"",getStatus:Ajax.Request.prototype.getStatus,getStatusText:function(){try{return this.transport.statusText|| +""}catch(a){return""}},getHeader:Ajax.Request.prototype.getHeader,getAllHeaders:function(){try{return this.getAllResponseHeaders()}catch(a){return null}},getResponseHeader:function(a){return this.transport.getResponseHeader(a)},getAllResponseHeaders:function(){return this.transport.getAllResponseHeaders()},_getHeaderJSON:function(){var a=this.getHeader("X-JSON");if(!a)return null;a=decodeURIComponent(escape(a));try{return a.evalJSON(this.request.options.sanitizeJSON||!this.request.isSameOrigin())}catch(b){this.request.dispatchException(b)}}, +_getResponseJSON:function(){var a=this.request.options;if(!a.evalJSON||a.evalJSON!="force"&&!(this.getHeader("Content-type")||"").include("application/json")||this.responseText.blank())return null;try{return this.responseText.evalJSON(a.sanitizeJSON||!this.request.isSameOrigin())}catch(b){this.request.dispatchException(b)}}}); +Ajax.Updater=Class.create(Ajax.Request,{initialize:function($super,b,c,d){this.container={success:b.success||b,failure:b.failure||(b.success?null:b)};var d=Object.clone(d),e=d.onComplete;d.onComplete=function(b,c){this.updateContent(b.responseText);Object.isFunction(e)&&e(b,c)}.bind(this);$super(c,d)},updateContent:function(a){var b=this.container[this.success()?"success":"failure"],c=this.options;c.evalScripts||(a=a.stripScripts());if(b=$(b))if(c.insertion)if(Object.isString(c.insertion)){var d= +{};d[c.insertion]=a;b.insert(d)}else c.insertion(b,a);else b.update(a)}}); +Ajax.PeriodicalUpdater=Class.create(Ajax.Base,{initialize:function($super,b,c,d){$super(d);this.onComplete=this.options.onComplete;this.frequency=this.options.frequency||2;this.decay=this.options.decay||1;this.updater={};this.container=b;this.url=c;this.start()},start:function(){this.options.onComplete=this.updateComplete.bind(this);this.onTimerEvent()},stop:function(){this.updater.options.onComplete=void 0;clearTimeout(this.timer);(this.onComplete||Prototype.emptyFunction).apply(this,arguments)}, +updateComplete:function(a){if(this.options.decay)this.decay=a.responseText==this.lastText?this.decay*this.options.decay:1,this.lastText=a.responseText;this.timer=this.onTimerEvent.bind(this).delay(this.decay*this.frequency)},onTimerEvent:function(){this.updater=new Ajax.Updater(this.container,this.url,this.options)}}); +function $(a){if(arguments.length>1){for(var b=0,c=[],d=arguments.length;b',delete c.name,Element.writeAttribute(document.createElement(a),c);d[a]||(d[a]=Element.extend(document.createElement(a)));return Element.writeAttribute(d[a].cloneNode(!1),c)};Object.extend(this.Element,a||{})}).call(window);Element.cache={}; +Element.Methods={visible:function(a){return $(a).style.display!="none"},toggle:function(a){a=$(a);Element[Element.visible(a)?"hide":"show"](a);return a},hide:function(a){$(a).style.display="none";return a},show:function(a){$(a).style.display="";return a},remove:function(a){a=$(a);a.parentNode.removeChild(a);return a},update:function(a,b){a=$(a);b&&b.toElement&&(b=b.toElement());if(Object.isElement(b))return a.update().insert(b);b=Object.toHTML(b);a.innerHTML=b.stripScripts();b.evalScripts.bind(b).defer(); +return a},replace:function(a,b){a=$(a);if(b&&b.toElement)b=b.toElement();else if(!Object.isElement(b)){var b=Object.toHTML(b),c=a.ownerDocument.createRange();c.selectNode(a);b.evalScripts.bind(b).defer();b=c.createContextualFragment(b.stripScripts())}a.parentNode.replaceChild(b,a);return a},insert:function(a,b){a=$(a);if(Object.isString(b)||Object.isNumber(b)||Object.isElement(b)||b&&(b.toElement||b.toHTML))b={bottom:b};var c,d,e,f;for(f in b)c=b[f],f=f.toLowerCase(),d=Element._insertionTranslations[f], +c&&c.toElement&&(c=c.toElement()),Object.isElement(c)?d(a,c):(c=Object.toHTML(c),e=(f=="before"||f=="after"?a.parentNode:a).tagName.toUpperCase(),e=Element._getContentFromAnonymousElement(e,c.stripScripts()),(f=="top"||f=="after")&&e.reverse(),e.each(d.curry(a)),c.evalScripts.bind(c).defer());return a},wrap:function(a,b,c){a=$(a);Object.isElement(b)?$(b).writeAttribute(c||{}):b=Object.isString(b)?new Element(b,c):new Element("div",b);a.parentNode&&a.parentNode.replaceChild(b,a);b.appendChild(a);return b}, +inspect:function(a){var a=$(a),b="<"+a.tagName.toLowerCase();$H({id:"id",className:"class"}).each(function(c){var d=c.first(),c=c.last();(d=(a[d]||"").toString())&&(b+=" "+c+"="+d.inspect(!0))});return b+">"},recursivelyCollect:function(a,b){for(var a=$(a),c=[];a=a[b];)a.nodeType==1&&c.push(Element.extend(a));return c},ancestors:function(a){return $(a).recursivelyCollect("parentNode")},descendants:function(a){return $(a).select("*")},firstDescendant:function(a){for(a=$(a).firstChild;a&&a.nodeType!= +1;)a=a.nextSibling;return $(a)},immediateDescendants:function(a){if(!(a=$(a).firstChild))return[];for(;a&&a.nodeType!=1;)a=a.nextSibling;if(a)return[a].concat($(a).nextSiblings());return[]},previousSiblings:function(a){return $(a).recursivelyCollect("previousSibling")},nextSiblings:function(a){return $(a).recursivelyCollect("nextSibling")},siblings:function(a){a=$(a);return a.previousSiblings().reverse().concat(a.nextSiblings())},match:function(a,b){Object.isString(b)&&(b=new Selector(b));return b.match($(a))}, +up:function(a,b,c){a=$(a);if(arguments.length==1)return $(a.parentNode);var d=a.ancestors();return Object.isNumber(b)?d[b]:Selector.findElement(d,b,c)},down:function(a,b,c){a=$(a);if(arguments.length==1)return a.firstDescendant();return Object.isNumber(b)?a.descendants()[b]:a.select(b)[c||0]},previous:function(a,b,c){a=$(a);if(arguments.length==1)return $(Selector.handlers.previousElementSibling(a));var d=a.previousSiblings();return Object.isNumber(b)?d[b]:Selector.findElement(d,b,c)},next:function(a, +b,c){a=$(a);if(arguments.length==1)return $(Selector.handlers.nextElementSibling(a));var d=a.nextSiblings();return Object.isNumber(b)?d[b]:Selector.findElement(d,b,c)},select:function(){var a=$A(arguments),b=$(a.shift());return Selector.findChildElements(b,a)},adjacent:function(){var a=$A(arguments),b=$(a.shift());return Selector.findChildElements(b.parentNode,a).without(b)},identify:function(a){var a=$(a),b=a.readAttribute("id"),c=arguments.callee;if(b)return b;do b="anonymous_element_"+c.counter++; +while($(b));a.writeAttribute("id",b);return b},readAttribute:function(a,b){a=$(a);if(Prototype.Browser.IE){var c=Element._attributeTranslations.read;if(c.values[b])return c.values[b](a,b);c.names[b]&&(b=c.names[b]);if(b.include(":"))return!a.attributes||!a.attributes[b]?null:a.attributes[b].value}return a.getAttribute(b)},writeAttribute:function(a,b,c){var a=$(a),d={},e=Element._attributeTranslations.write;typeof b=="object"?d=b:d[b]=Object.isUndefined(c)?!0:c;for(var f in d)b=e.names[f]||f,c=d[f], +e.values[f]&&(b=e.values[f](a,c)),c===!1||c===null?a.removeAttribute(b):c===!0?a.setAttribute(b,b):a.setAttribute(b,c);return a},getHeight:function(a){return $(a).getDimensions().height},getWidth:function(a){return $(a).getDimensions().width},classNames:function(a){return new Element.ClassNames(a)},hasClassName:function(a,b){if(a=$(a)){var c=a.className;return c.length>0&&(c==b||RegExp("(^|\\s)"+b+"(\\s|$)").test(c))}},addClassName:function(a,b){if(a=$(a))return a.hasClassName(b)||(a.className+=(a.className? +" ":"")+b),a},removeClassName:function(a,b){if(a=$(a))return a.className=a.className.replace(RegExp("(^|\\s+)"+b+"(\\s+|$)")," ").strip(),a},toggleClassName:function(a,b){if(a=$(a))return a[a.hasClassName(b)?"removeClassName":"addClassName"](b)},cleanWhitespace:function(a){for(var a=$(a),b=a.firstChild;b;){var c=b.nextSibling;b.nodeType==3&&!/\S/.test(b.nodeValue)&&a.removeChild(b);b=c}return a},empty:function(a){return $(a).innerHTML.blank()},descendantOf:function(a,b){var a=$(a),c=b=$(b);if(a.compareDocumentPosition)return(a.compareDocumentPosition(b)& +8)===8;if(a.sourceIndex&&!Prototype.Browser.Opera){var d=a.sourceIndex,e=b.sourceIndex,f=b.nextSibling;if(!f){do b=b.parentNode;while(!(f=b.nextSibling)&&b.parentNode)}if(f&&f.sourceIndex)return d>e&&d","",1],TBODY:["","
",2],TR:["","
",3],TD:["
","
",4],SELECT:["",1]}}; +(function(){Object.extend(this.tags,{THEAD:this.tags.TBODY,TFOOT:this.tags.TBODY,TH:this.tags.TD})}).call(Element._insertionTranslations);Element.Methods.Simulated={hasAttribute:function(a,b){var b=Element._attributeTranslations.has[b]||b,c=$(a).getAttributeNode(b);return c&&c.specified}};Element.Methods.ByTag={};Object.extend(Element,Element.Methods); +if(!Prototype.BrowserFeatures.ElementExtensions&&document.createElement("div").__proto__)window.HTMLElement={},window.HTMLElement.prototype=document.createElement("div").__proto__,Prototype.BrowserFeatures.ElementExtensions=!0; +Element.extend=function(){if(Prototype.BrowserFeatures.SpecificElementExtensions)return Prototype.K;var a={},b=Element.Methods.ByTag,c=Object.extend(function(c){if(!c||c._extendedByPrototype||c.nodeType!=1||c==window)return c;var e=Object.clone(a),f=c.tagName,g;b[f]&&Object.extend(e,b[f]);for(g in e)f=e[g],Object.isFunction(f)&&!(g in c)&&(c[g]=f.methodize());c._extendedByPrototype=Prototype.emptyFunction;return c},{refresh:function(){Prototype.BrowserFeatures.ElementExtensions||(Object.extend(a, +Element.Methods),Object.extend(a,Element.Methods.Simulated))}});c.refresh();return c}();Element.hasAttribute=function(a,b){if(a.hasAttribute)return a.hasAttribute(b);return Element.Methods.Simulated.hasAttribute(a,b)}; +Element.addMethods=function(a){function b(b){b=b.toUpperCase();Element.Methods.ByTag[b]||(Element.Methods.ByTag[b]={});Object.extend(Element.Methods.ByTag[b],a)}function c(a,b,c){var c=c||!1,d;for(d in a){var e=a[d];if(Object.isFunction(e)&&(!c||!(d in b)))b[d]=e.methodize()}}function d(a){var b,c={OPTGROUP:"OptGroup",TEXTAREA:"TextArea",P:"Paragraph",FIELDSET:"FieldSet",UL:"UList",OL:"OList",DL:"DList",DIR:"Directory",H1:"Heading",H2:"Heading",H3:"Heading",H4:"Heading",H5:"Heading",H6:"Heading", +Q:"Quote",INS:"Mod",DEL:"Mod",A:"Anchor",IMG:"Image",CAPTION:"TableCaption",COL:"TableCol",COLGROUP:"TableCol",THEAD:"TableSection",TFOOT:"TableSection",TBODY:"TableSection",TR:"TableRow",TH:"TableCell",TD:"TableCell",FRAMESET:"FrameSet",IFRAME:"IFrame"};c[a]&&(b="HTML"+c[a]+"Element");if(window[b])return window[b];b="HTML"+a+"Element";if(window[b])return window[b];b="HTML"+a.capitalize()+"Element";if(window[b])return window[b];window[b]={};window[b].prototype=document.createElement(a).__proto__; +return window[b]}var e=Prototype.BrowserFeatures,f=Element.Methods.ByTag;a||(Object.extend(Form,Form.Methods),Object.extend(Form.Element,Form.Element.Methods),Object.extend(Element.Methods.ByTag,{FORM:Object.clone(Form.Methods),INPUT:Object.clone(Form.Element.Methods),SELECT:Object.clone(Form.Element.Methods),TEXTAREA:Object.clone(Form.Element.Methods)}));if(arguments.length==2)var g=a,a=arguments[1];g?Object.isArray(g)?g.each(b):b(g):Object.extend(Element.Methods,a||{});e.ElementExtensions&&(c(Element.Methods, +HTMLElement.prototype),c(Element.Methods.Simulated,HTMLElement.prototype,!0));if(e.SpecificElementExtensions)for(var h in Element.Methods.ByTag)e=d(h),Object.isUndefined(e)||c(f[h],e.prototype);Object.extend(Element,Element.Methods);delete Element.ByTag;Element.extend.refresh&&Element.extend.refresh();Element.cache={}}; +document.viewport={getDimensions:function(){var a={},b=Prototype.Browser;$w("width height").each(function(c){var d=c.capitalize();a[c]=b.WebKit&&!document.evaluate?self["inner"+d]:b.Opera?document.body["client"+d]:document.documentElement["client"+d]});return a},getWidth:function(){return this.getDimensions().width},getHeight:function(){return this.getDimensions().height},getScrollOffsets:function(){return Element._returnOffset(window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft, +window.pageYOffset||document.documentElement.scrollTop||document.body.scrollTop)}}; +var Selector=Class.create({initialize:function(a){this.expression=a.strip();this.compileMatcher()},shouldUseXPath:function(){if(!Prototype.BrowserFeatures.XPath)return!1;var a=this.expression;if(Prototype.Browser.WebKit&&(a.include("-of-type")||a.include(":empty")))return!1;if(/(\[[\w-]*?:|:checked)/.test(this.expression))return!1;return!0},compileMatcher:function(){if(this.shouldUseXPath())return this.compileXPathMatcher();var a=this.expression,b=Selector.patterns,c=Selector.criteria,d,e;if(Selector._cache[a])this.matcher= +Selector._cache[a];else{for(this.matcher=["this.matcher = function(root) {","var r = root, h = Selector.handlers, c = false, n;"];a&&d!=a&&/\S/.test(a);){d=a;for(var f in b)if(e=b[f],e=a.match(e)){this.matcher.push(Object.isFunction(c[f])?c[f](e):(new Template(c[f])).evaluate(e));a=a.replace(e[0],"");break}}this.matcher.push("return h.unique(n);\n}");eval(this.matcher.join("\n"));Selector._cache[this.expression]=this.matcher}},compileXPathMatcher:function(){var a=this.expression,b=Selector.patterns, +c=Selector.xpath,d,e;if(Selector._cache[a])this.xpath=Selector._cache[a];else{for(this.matcher=[".//*"];a&&d!=a&&/\S/.test(a);){d=a;for(var f in b)if(e=a.match(b[f])){this.matcher.push(Object.isFunction(c[f])?c[f](e):(new Template(c[f])).evaluate(e));a=a.replace(e[0],"");break}}this.xpath=this.matcher.join("");Selector._cache[this.expression]=this.xpath}},findElements:function(a){a=a||document;if(this.xpath)return document._getElementsByXPath(this.xpath,a);return this.matcher(a)},match:function(a){this.tokens= +[];for(var b=this.expression,c=Selector.patterns,d=Selector.assertions,e,f;b&&e!==b&&/\S/.test(b);){e=b;for(var g in c)if(f=c[g],f=b.match(f))if(d[g])this.tokens.push([g,Object.clone(f)]),b=b.replace(f[0],"");else return this.findElements(document).include(a)}b=!0;for(g=0;d=this.tokens[g];g++)if(c=d[0],d=d[1],!Selector.assertions[c](a,d)){b=!1;break}return b},toString:function(){return this.expression},inspect:function(){return"#"}}); +Object.extend(Selector,{_cache:{},xpath:{descendant:"//*",child:"/*",adjacent:"/following-sibling::*[1]",laterSibling:"/following-sibling::*",tagName:function(a){if(a[1]=="*")return"";return"[local-name()='"+a[1].toLowerCase()+"' or local-name()='"+a[1].toUpperCase()+"']"},className:"[contains(concat(' ', @class, ' '), ' #{1} ')]",id:"[@id='#{1}']",attrPresence:function(a){a[1]=a[1].toLowerCase();return(new Template("[@#{1}]")).evaluate(a)},attr:function(a){a[1]=a[1].toLowerCase();a[3]=a[5]||a[6]; +return(new Template(Selector.xpath.operators[a[2]])).evaluate(a)},pseudo:function(a){var b=Selector.xpath.pseudos[a[1]];if(!b)return"";if(Object.isFunction(b))return b(a);return(new Template(Selector.xpath.pseudos[a[1]])).evaluate(a)},operators:{"=":"[@#{1}='#{3}']","!=":"[@#{1}!='#{3}']","^=":"[starts-with(@#{1}, '#{3}')]","$=":"[substring(@#{1}, (string-length(@#{1}) - string-length('#{3}') + 1))='#{3}']","*=":"[contains(@#{1}, '#{3}')]","~=":"[contains(concat(' ', @#{1}, ' '), ' #{3} ')]","|=":"[contains(concat('-', @#{1}, '-'), '-#{3}-')]"}, +pseudos:{"first-child":"[not(preceding-sibling::*)]","last-child":"[not(following-sibling::*)]","only-child":"[not(preceding-sibling::* or following-sibling::*)]",empty:"[count(*) = 0 and (count(text()) = 0 or translate(text(), ' \t\r\n', '') = '')]",checked:"[@checked]",disabled:"[@disabled]",enabled:"[not(@disabled)]",not:function(a){for(var b=a[6],c=Selector.patterns,d=Selector.xpath,e,f,g=[];b&&e!=b&&/\S/.test(b);){e=b;for(var h in c)if(a=b.match(c[h])){f=Object.isFunction(d[h])?d[h](a):(new Template(d[h])).evaluate(a); +g.push("("+f.substring(1,f.length-1)+")");b=b.replace(a[0],"");break}}return"[not("+g.join(" and ")+")]"},"nth-child":function(a){return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*) + 1) ",a)},"nth-last-child":function(a){return Selector.xpath.pseudos.nth("(count(./following-sibling::*) + 1) ",a)},"nth-of-type":function(a){return Selector.xpath.pseudos.nth("position() ",a)},"nth-last-of-type":function(a){return Selector.xpath.pseudos.nth("(last() + 1 - position()) ",a)},"first-of-type":function(a){a[6]= +"1";return Selector.xpath.pseudos["nth-of-type"](a)},"last-of-type":function(a){a[6]="1";return Selector.xpath.pseudos["nth-last-of-type"](a)},"only-of-type":function(a){var b=Selector.xpath.pseudos;return b["first-of-type"](a)+b["last-of-type"](a)},nth:function(a,b){var c,d=b[6];d=="even"&&(d="2n+0");d=="odd"&&(d="2n+1");if(c=d.match(/^(\d+)$/))return"["+a+"= "+c[1]+"]";if(c=d.match(/^(-?\d*)?n(([+-])(\d+))?/))return c[1]=="-"&&(c[1]=-1),d=c[1]?Number(c[1]):1,c=c[2]?Number(c[2]):0,(new Template("[((#{fragment} - #{b}) mod #{a} = 0) and ((#{fragment} - #{b}) div #{a} >= 0)]")).evaluate({fragment:a, +a:d,b:c})}}},criteria:{tagName:'n = h.tagName(n, r, "#{1}", c); c = false;',className:'n = h.className(n, r, "#{1}", c); c = false;',id:'n = h.id(n, r, "#{1}", c); c = false;',attrPresence:'n = h.attrPresence(n, r, "#{1}", c); c = false;',attr:function(a){a[3]=a[5]||a[6];return(new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}", c); c = false;')).evaluate(a)},pseudo:function(a){a[6]&&(a[6]=a[6].replace(/"/g,'\\"'));return(new Template('n = h.pseudo(n, "#{1}", "#{6}", r, c); c = false;')).evaluate(a)}, +descendant:'c = "descendant";',child:'c = "child";',adjacent:'c = "adjacent";',laterSibling:'c = "laterSibling";'},patterns:{laterSibling:/^\s*~\s*/,child:/^\s*>\s*/,adjacent:/^\s*\+\s*/,descendant:/^\s/,tagName:/^\s*(\*|[\w\-]+)(\b|$)?/,id:/^#([\w\-\*]+)(\b|$)/,className:/^\.([\w\-\*]+)(\b|$)/,pseudo:/^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s|[:+~>]))/,attrPresence:/^\[([\w]+)\]/,attr:/\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/}, +assertions:{tagName:function(a,b){return b[1].toUpperCase()==a.tagName.toUpperCase()},className:function(a,b){return Element.hasClassName(a,b[1])},id:function(a,b){return a.id===b[1]},attrPresence:function(a,b){return Element.hasAttribute(a,b[1])},attr:function(a,b){var c=Element.readAttribute(a,b[1]);return c&&Selector.operators[b[2]](c,b[5]||b[6])}},handlers:{concat:function(a,b){for(var c=0,d;d=b[c];c++)a.push(d);return a},mark:function(a){for(var b=Prototype.emptyFunction,c=0,d;d=a[c];c++)d._countedByPrototype= +b;return a},unmark:function(a){for(var b=0,c;c=a[b];b++)c._countedByPrototype=void 0;return a},index:function(a,b,c){a._countedByPrototype=Prototype.emptyFunction;if(b)for(var a=a.childNodes,b=a.length-1,d=1;b>=0;b--){var e=a[b];if(e.nodeType==1&&(!c||e._countedByPrototype))e.nodeIndex=d++}else{b=0;d=1;for(a=a.childNodes;e=a[b];b++)if(e.nodeType==1&&(!c||e._countedByPrototype))e.nodeIndex=d++}},unique:function(a){if(a.length==0)return a;for(var b=[],c,d=0,e=a.length;d0?[b]:[];return $R(1,c).inject([],function(c,e){0==(e-b)%a&&(e-b)/a>=0&&c.push(e);return c})},nth:function(a,b,c,d,e){if(a.length==0)return[];b=="even"&&(b="2n+0");b=="odd"&&(b="2n+1");var c=Selector.handlers,f=[],g=[],h;c.mark(a);h=0;for(var i;i=a[h];h++)i.parentNode._countedByPrototype|| +(c.index(i.parentNode,d,e),g.push(i.parentNode));if(b.match(/^\d+$/)){b=Number(b);for(h=0;i=a[h];h++)i.nodeIndex==b&&f.push(i)}else if(h=b.match(/^(-?\d*)?n(([+-])(\d+))?/)){h[1]=="-"&&(h[1]=-1);b=Selector.pseudos.getIndices(h[1]?Number(h[1]):1,h[2]?Number(h[2]):0,a.length);h=0;for(d=b.length;i=a[h];h++)for(e=0;e+()\s-]+|\*|\[.*?\])+)\s*(,|$)/,function(a){b.push(a[1].strip())});return b},matchElements:function(a,b){var c=$$(b),d=Selector.handlers;d.mark(c);for(var e=0,f=[],g;g=a[e];e++)g._countedByPrototype&& +f.push(g);d.unmark(c);return f},findElement:function(a,b,c){Object.isNumber(b)&&(c=b,b=!1);return Selector.matchElements(a,b||"*")[c||0]},findChildElements:function(a,b){for(var b=Selector.split(b.join(",")),c=[],d=Selector.handlers,e=0,f=b.length,g;e1?d.unique(c):c}}); +Prototype.Browser.IE&&Object.extend(Selector.handlers,{concat:function(a,b){for(var c=0,d;d=b[c];c++)d.tagName!=="!"&&a.push(d);return a},unmark:function(a){for(var b=0,c;c=a[b];b++)c.removeAttribute("_countedByPrototype");return a}});function $$(){return Selector.findChildElements(document,$A(arguments))} +var Form={reset:function(a){$(a).reset();return a},serializeElements:function(a,b){if(typeof b!="object")b={hash:!!b};else if(Object.isUndefined(b.hash))b.hash=!0;var c,d,e=!1,f=b.submit,g=a.inject({},function(a,b){if(!b.disabled&&b.name&&(c=b.name,d=$(b).getValue(),d!=null&&(b.type!="submit"||!e&&f!==!1&&(!f||c==f)&&(e=!0))))c in a?(Object.isArray(a[c])||(a[c]=[a[c]]),a[c].push(d)):a[c]=d;return a});return b.hash?g:Object.toQueryString(g)}}; +Form.Methods={serialize:function(a,b){return Form.serializeElements(Form.getElements(a),b)},getElements:function(a){return $A($(a).getElementsByTagName("*")).inject([],function(a,c){Form.Element.Serializers[c.tagName.toLowerCase()]&&a.push(Element.extend(c));return a})},getInputs:function(a,b,c){a=$(a);a=a.getElementsByTagName("input");if(!b&&!c)return $A(a).map(Element.extend);for(var d=0,e=[],f=a.length;d=0}).sortBy(function(a){return a.tabIndex}).first();return b?b:a.find(function(a){return["input","select","textarea"].include(a.tagName.toLowerCase())})},focusFirstElement:function(a){a=$(a);a.findFirstElement().activate(); +return a},request:function(a,b){var a=$(a),b=Object.clone(b||{}),c=b.parameters,d=a.readAttribute("action")||"";if(d.blank())d=window.location.href;b.parameters=a.serialize(!0);c&&(Object.isString(c)&&(c=c.toQueryParams()),Object.extend(b.parameters,c));if(a.hasAttribute("method")&&!b.method)b.method=a.method;return new Ajax.Request(d,b)}};Form.Element={focus:function(a){$(a).focus();return a},select:function(a){$(a).select();return a}}; +Form.Element.Methods={serialize:function(a){a=$(a);if(!a.disabled&&a.name){var b=a.getValue();if(b!=void 0){var c={};c[a.name]=b;return Object.toQueryString(c)}}return""},getValue:function(a){var a=$(a),b=a.tagName.toLowerCase();return Form.Element.Serializers[b](a)},setValue:function(a,b){var a=$(a),c=a.tagName.toLowerCase();Form.Element.Serializers[c](a,b);return a},clear:function(a){$(a).value="";return a},present:function(a){return $(a).value!=""},activate:function(a){a=$(a);try{a.focus(),a.select&& +(a.tagName.toLowerCase()!="input"||!["button","reset","submit"].include(a.type))&&a.select()}catch(b){}return a},disable:function(a){a=$(a);a.blur();a.disabled=!0;return a},enable:function(a){a=$(a);a.disabled=!1;return a}};var Field=Form.Element,$F=Form.Element.Methods.getValue; +Form.Element.Serializers={input:function(a,b){switch(a.type.toLowerCase()){case "checkbox":case "radio":return Form.Element.Serializers.inputSelector(a,b);default:return Form.Element.Serializers.textarea(a,b)}},inputSelector:function(a,b){if(Object.isUndefined(b))return a.checked?a.value:null;else a.checked=!!b},textarea:function(a,b){if(Object.isUndefined(b))return a.value;else a.value=b},select:function(a,b){if(Object.isUndefined(b))return this[a.type=="select-one"?"selectOne":"selectMany"](a); +else for(var c,d,e=!Object.isArray(b),f=0,g=a.length;f=0?this.optionValue(a.options[b]):null},selectMany:function(a){var b,c=a.length;if(!c)return null;var d=0;for(b=[];d<\/script>"),$("__onDOMContentLoaded").onreadystatechange=function(){if(this.readyState=="complete")this.onreadystatechange= +null,a()})})();Hash.toQueryString=Object.toQueryString;var Toggle={display:Element.toggle};Element.Methods.childOf=Element.Methods.descendantOf; +var Insertion={Before:function(a,b){return Element.insert(a,{before:b})},Top:function(a,b){return Element.insert(a,{top:b})},Bottom:function(a,b){return Element.insert(a,{bottom:b})},After:function(a,b){return Element.insert(a,{after:b})}},$continue=Error('"throw $continue" is deprecated, use "return" instead'),Position={includeScrollOffsets:!1,prepare:function(){this.deltaX=window.pageXOffset||document.documentElement.scrollLeft||document.body.scrollLeft||0;this.deltaY=window.pageYOffset||document.documentElement.scrollTop|| +document.body.scrollTop||0},within:function(a,b,c){if(this.includeScrollOffsets)return this.withinIncludingScrolloffsets(a,b,c);this.xcomp=b;this.ycomp=c;this.offset=Element.cumulativeOffset(a);return c>=this.offset[1]&&c=this.offset[0]&&b= +this.offset[1]&&this.ycomp=this.offset[0]&&this.xcomp0})._each(a)},set:function(a){this.element.className=a},add:function(a){this.include(a)||this.set($A(this).concat(a).join(" "))},remove:function(a){this.include(a)&&this.set($A(this).without(a).join(" "))},toString:function(){return $A(this).join(" ")}};Object.extend(Element.ClassNames.prototype,Enumerable);Element.addMethods(); diff --git a/javascript/examples/Libraries/Box2D/simpleBox2D/magic.js b/javascript/examples/Libraries/Box2D/simpleBox2D/magic.js new file mode 100644 index 000000000..7355f8a8c --- /dev/null +++ b/javascript/examples/Libraries/Box2D/simpleBox2D/magic.js @@ -0,0 +1,167 @@ + +// add Prototype.js library +document.write(""); +// 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(); +} +