1 line
158 KiB
JavaScript
1 line
158 KiB
JavaScript
|
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=.005*b2Settings.b2_lengthUnitsPerMeter,b2Settings.b2_angularSlop=2/180*b2Settings.b2_pi,b2Settings.b2_velocityThreshold=1*b2Settings.b2_lengthUnitsPerMeter/b2Settings.b2_timeUnitsPerSecond,b2Settings.b2_maxLinearCorrection=.2*b2Settings.b2_lengthUnitsPerMeter,b2Settings.b2_maxAngularCorrection=8/180*b2Settings.b2_pi,b2Settings.b2_contactBaumgarte=.2,b2Settings.b2_timeToSleep=.5*b2Settings.b2_timeUnitsPerSecond,b2Settings.b2_linearSleepTolerance=.01*b2Settings.b2_lengthUnitsPerMeter/b2Settings.b2_timeUnitsPerSecond,b2Settings.b2_angularSleepTolerance=2/180/b2Settings.b2_timeUnitsPerSecond,b2Settings.b2Assert=function(a){a||undefined.x++};var b2Vec2=Class.create();b2Vec2.prototype={initialize:function(x_,y_){this.x=x_,this.y=y_},SetZero:function(){this.x=0,this.y=0},Set:function(x_,y_){this.x=x_,this.y=y_},SetV:function(v){this.x=v.x,this.y=v.y},Negative:function(){return new b2Vec2(-this.x,-this.y)},Copy:function(){return new b2Vec2(this.x,this.y)},Add:function(v){this.x+=v.x,this.y+=v.y},Subtract:function(v){this.x-=v.x,this.y-=v.y},Multiply:function(a){this.x*=a,this.y*=a},MulM:function(A){var tX=this.x;this.x=A.col1.x*tX+A.col2.x*this.y,this.y=A.col1.y*tX+A.col2.y*this.y},MulTM:function(A){var tX=b2Math.b2Dot(this,A.col1);this.y=b2Math.b2Dot(this,A.col2),this.x=tX},CrossVF:function(s){var tX=this.x;this.x=s*this.y,this.y=-s*tX},CrossFV:function(s){var tX=this.x;this.x=-s*this.y,this.y=s*tX},MinV:function(b){this.x=this.x<b.x?this.x:b.x,this.y=this.y<b.y?this.y:b.y},MaxV:function(b){this.x=this.x>b.x?this.x:b.x,this.y=this.y>b.y?this.y:b.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 length=this.Length();if(length<Number.MIN_VALUE)return 0;var invLength=1/length;return this.x*=invLength,this.y*=invLength,length},IsValid:function(){return b2Math.b2IsValid(this.x)&&b2Math.b2IsValid(this.y)},x:null,y:null},b2Vec2.Make=function(x_,y_){return new b2Vec2(x_,y_)};var b2Mat22=Class.create();b2Mat22.prototype={initialize:function(angle,c1,c2){if(null==angle&&(angle=0),this.col1=new b2Vec2,this.col2=new b2Vec2,null!=c1&&null!=c2)this.col1.SetV(c1),this.col2.SetV(c2);else{var c=Math.cos(angle),s=Math.sin(angle);this.col1.x=c,this.col2.x=-s,this.col1.y=s,this.col2.y=c}},Set:function(angle){var c=Math.cos(angle),s=Math.sin(angle);this.col1.x=c,this.col2.x=-s,this.col1.y=s,this.col2.y=c},SetVV:function(c1,c2){this.col1.SetV(c1),this.col2.SetV(c2)},Copy:function(){return new b2Mat22(0,this.col1,this.col2)},SetM:function(m){this.col1.SetV(m.col1),this.col2.SetV(m.col2)},AddM:function(m){this.col1.x+=m.col1.x,this.col1.y+=m.col1.y,this.col2.x+=m.col2.x,this.col2.y+=m.col2.y},SetIdentity:function(){this.col1.x=1,this.col2.x=0,this.col1.y=0,this.col2.y=1},SetZero:function(){this.col1.x=0,this.col2.x=0,this.col1.y=0,this.col2.y=0},Invert:function(out){var a=this.col1.x,b=this.col2.x,c=this.col1.y,d=this.col2.y,det=a*d-b*c;return det=1/det,out.col1.x=det*d,out.col2.x=-det*b,out.col1.y=-det*c,out.col2.y=det*a,out},Solve:function(out,bX,bY){var a11=this.col1.x,a12=this.col2.x,a21=this.col1.y,a22=this.col2.y,det=a11*a22-a12*a21;return det=1/det,out.x=det*(a22*bX-a12*bY),out.y=det*(a11*bY-a21*bX),out},Abs:function(){this.col1.Abs(),this.col2.Abs()},col1:new b2Vec2,col2:new b2Vec2};var b2Math=Class.create();b2Math.prototype={initialize:function(){}},b2Math.b2IsValid=function(x){return isFinite(x)},b2Math.b2Dot=function(a,b){return a.x*b.x+a.y*b.y},b2Math.b2CrossVV=function(a,b){return a.x*b.y-a.y*b.x},b2Math.b2CrossVF=function(a,s){return new b2Vec2(s*a.y,-s*a.x)},b2Math.b2CrossFV=function(s,a){return
|