2016/03/08 codes

if(pointCount = 3){b2Distance.g_GJK_Iterations = iter;return 0.0;}
var maxSqr = -Number.MAX_VALUE;
for(var i = 0; i < pointCount; ++i){maxSqr = b2Math.b2Max(maxSqr,points[i].x * points[i].x + points[i].y * points[i].y)}
if(pointCount == 3 || vSqr <= 100 * Number.MIN_VALUE * maxSqr){b2Distance.g_GJK_Iterations = iter;return Math.sqrt(vSqr);}
}
b2Distance.g_GJK_Iterations = maxInterations;return Math.sqrt(vSqr);
};
b2Distance.g_GJK_Iterations = 0;
var b2Manifold = Class.create();
b2Manifold.prototype = {
initialize:function(){this.points = new Array(b2Settins.b2_maxManifoldPoints);
for(var i = 0;i < b2Settins.b2_maxManifoldPoints;i ++){this.points[i] = new b2ContactPoint();}
this.normal = new b2Vec2();},points:null,noraml:null,pointCount:0;};
var b2OBB = Class.create();
b2OBB.prototype = {R:new b2Matt22(),center:new b2Vec2(),extends:new b2Vec2(),
initialize:function(){this.R = new b2Matt22();this.center = new b2Vec2();this.extends = new b2Vec2();}};
var b2Proxy = Class.create();
b2Proxy.prototype = {
GetNext:function(){return this.lowerBounds[0];},
SetNext:function(next){return this.lowerBounds[0] = next;},
IsValid:function(){return this.overlapCount != b2BroadPhase.b2_invalid;},
lowerBounds:[(0),(0)],upperBounds:[(0),(0)],
overlapCount:0,timeStamp:0,userData:null,
initialize:function(){this.lowerBounds = [(0),(0)];this.upperBounds = [(0),(0)];}}
var ClipVertex = Class.create();
ClipVertex.prototype = {
v:new b2Vec2(),id:new b2ContactID,
initialize:function(){this.v = new b2Vec2(),this.id = new b2ContactID();}
};
var b2shape = Class.create();
b2shape.prototype = {
TestPoint:function(p){return false;},
GetUserData:function(){return this.m_userData;},
GetType:function(){return this.m_type;},
GetBody:function(){return this.m_body;},
GetPosition:function(){return this.m_position},
Get_rotationMatrix:function(){return this.m_R;},
ResetProxy:function(broadPhase){},
GetNext:function(){return this.m_next},
initialize:function(def,body){
this.m_R = new b2Matt22(); this.m_position = new b2Vec2();
this.m_userData = def.userData; this.m_friction = def.friction;
this.m_restitution = def.restitution; this.m_body = body;
this.m_proxyId = b2Pair.b2_nullPair;this.m_maxRadius = 0.0;
this.m_categoryBits = def.categoryBits;
this.m_groupIndex = def.groupIndex;
},
DestoryProxy:function(){if(this.m_proxyId != b2Pair.b2_nullPair){
this.m_body.m_world.m_broadPhase.DestoryProxy(this.proxyId);
this.m_proxyId = b2Pair.b2_nullPair;
}},
Synchronize:function(position1,R1,position2,R2){};
QuickSync:function(position,R){},
support:function(dX,dY,out){},
GetMaxRadius:function(){return this.m_radius;},
m_next:null,m_R:b2Matt22(),m_position:new b2Vec2(),
m_type:0,m_userData:null,m_body:null,m_friction:null,
m_restitution:null,m_maxRadius:null,m_proxyId:0,
m_categoryBits:0,m_maskBits:0,m_groupIndex:0
};
b2shape.Create = function(def,body,center){
switch (def,type){case b2shape.e_circleShape:{return new b2CircleShape(def,body,center);}
case b2shape.e_boxShape:case b2shape.e_polyShape:{return new b2PolyShape(def,body,center);}
}
return null;
};
b2shape.Destroy = function(shape){
if(shape.m_proxyId != b2Pair.b2_nullPair){shape.m_body.m_world.m_broadPhase.DestoryProxy(shape.m_proxyId);};
b2shape.e_unknownShape = -1;b2shape.e_circleShape = 0;b2shape.e_boxShape = 1;
b2shape.e_polyShape = 2;b2shape.e_meshShape = 3;b2shape.e_shapeTypeCount = 4;
b2shape.PolyMass = function(massData,vs,count,rho){
var center = new b2Vec2();center.SetZero();var area = 0.0;var I = 0.0;
var pRef = new b2Vec2(0.0,0.0);var inv3 = 1.0 / 3.0;
for(var i = 0; i < count; ++i){
var p1 = pRef;var p2 = vs[i];var p3 = i + 1 < count ? vs[i + 1]:vs[0];
var e1 = b2Math.SubtractVV(p2,p1);var e2 = b2Math.SubtractVV(p3,p1);
var D = b2Math.b2CrossVV(e1,e2);var triangleArea = 0.5 * D;area += triangleArea;
var tVec = new b2Vec2();tVec.SetV(p1);tVec.Add(p3);tVec.Multiply(inv3 * triangleArea);center.Add(tVec);
var px = p1.x;var py = p1.y;var ex1 = e1.x;var ey1 = e1.y;var ex2 = e2.x;var ey2 = e2.y;
var intx2 = inv3 * (0.25 * (ex1 * ex1 + ex2 * ex1 + ex2 * ex2) + (px * ex1 + px * ex2)) + 0.5 * px * px;
var inty2 = inv3 * (0.25 * (ey1 * ey1 + ey2 * ey1 + ey2 * ey2) + (py * ey1 + py * ey2)) + 0.5 * py * py;
I += D * (intx2 + inty2);
}
massData.mass = rho * area;center.Multiply(1.0 / area);
massData.center = center;I = rho * (I - area * b2Math.b2Dot(center,center));
massData.I = I;
}
}
}

}

posted on 2016-03-08 11:47  琳姐姐  阅读(267)  评论(0)    收藏  举报

导航