2016/03/10 codes

b2shape.polyCentroid = function(vs,count,out){
var cX = 0.0;var cY = 0.0; var area = 0.0;var pRefX = 0.0;var pRefY = 0.0;var inv3 = 1.0 / 3.0;
for(var i = 0;i < count; ++i){
var p1X = pRefX;var p1Y = pRefY;var p2X = vs[i].x;var p2Y = vs[i].y;
var p3X = i + 1 < count ? vs[i + 1].x : vs[0].x;var p3Y = i + 1 < count ? vs[i + 1].y:vs[0].y;
var e1X = p2X - p1X;var e1Y = p2Y - p1Y;
var e2X = p3X - p1X;var e2Y = p3X - p1Y;
var D = (e1X * e2Y - e2X * e1Y);
var triangleArea = 0.5 * D;area += triangleArea;
cX += triangleArea * inv3 * (p1X + p2X + p3X);
cY += triangleArea * inv3 * (p1Y + p2Y + p3Y);
cX *= 1.0 / area; cY *= 1.0 / area;
out.Set(cX,cY);
};
var b2shapeDef = Class.create();
b2shapeDef.prototype = {
initialize:function(){
this.type = b2shapeDef.e_unknownShape;
this.userData = null;this.localPosition = new b2Vec2(0.0,0.0);
this.localRotation = 0.0;this.friction = 0.2;this.restitution = 0.0;
this.density = 0.0;this.categoryBits = 0x0001;this.maskBits = 0xffff;this.groupIndex = 0;
},
ComputeMass:function(massDate){
massDate.center = new b2Vec2(0.0,0.0);
};
switch (this.type){
case b2shape.e_circleShape:{var circle = this;massDate.mass = this.density * b2Settins.b2_pi * circle.radius * circle.radius;
massDate.center.Set(0.0,0.0);
massDate.I = 0.5 * (massDate.mass) * circle.radius * circle.radius;
}
break;
b2shape.e_boxShape : {var box = this;massDate.mass = 4.0 * this.density * box.extends.x * box.extends.y;
massDate.center.Set(0.0,0.0);
massDate.I = massDate.mass / 3.0 * b2Math.b2Dot(box.extents,box.extents);
}
break:case e_polyShape:{
var poly = this;b2shape.polyMass(massDate,poly.vertices,poly.vertexCount,this.density);}
break;default :massDate.mass = 0.0;massDate.center.Set(0.0,0.0);massDate.I = 0.0;break;
}},
type:0,userData:null,localPosition:null,friction:null,restitution:null,density:null,
categoryBits:0,maskBits:0,groupIndex:0
};
var b2BoxDef = Class.create();
Object.extend (b2BoxDef.prototype,b2BoxDef.prototype);
Object.extend(b2BoxDef.prototype,{initialize:function(){
this.type = b2shape.e_unknownShape;
this.UserData = null;this.localPosition = new b2Vec2();
this.localRotation = 0.0;this.friction = 0.2;
this.restitution = 0.0;this.density = 0.0;
this.categroupBits = 0x0001;this.maskBits = 0xFFFF;
this.groupIndex = 0;this.type = b2shape.e_boxShape;
this.extents = new b2Vec2(1.0,1.0);
}extents:null});
var b2CircleDef = Class.create();
Object.extend(b2CircleDef.prototype,b2ShapeDef.prototype);
Object.extents(b2CircleDef.prototype,{initialize:function(){
this.type = b2shape.e_unknownShape;this.userData = null;
this.localPosition = new b2Vec2(0.0,0.0);this.localRotation = 0.0;
this.categoryBits = 0x0001;this.maskBits = 0xFFFF;
this.groupIndex = 0;this.type = b2shape.e_circleShape;this.radius = 1.0;
},radius:null});
var b2CircleShape =Class.create();
Object.extents(b2CircleShape.prototype,b2ShapeDef.prototype);
Object.extents(b2CircleShape.prototype,{TestPoint:function(p){
var d = new b2Vec2();d,SetV(p);d.Substract(this.m_position);
return b2Math.b2Dot(d,d) <= this.m_radius * this.m_radius;
},
intialize:function(def,local,center){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_maskBits = def.maskBits;
this.m_groupIndex = def.groupIdex;this.m_localPosition = new b2Vec2();
var circle = this;this.m_localPosition.Set(def.localPosition.x-localCenter.x,def.localPosition.y-localCenter.y);
this.m_type = b2shape.e_circleShape;this.m_radius = circle.radius;this.m_R.SetM(this.m_body,m_R);
var rX = this.m_R.col1.x * this.m_localPosition.x + this.m_R.colo2.x + this.m_localPosition.x;
var rY = this.m_R.col1.y * this.m_localPosition.y + this.m_R.col2.y + this.m_localPosition.y;
this.m_position.x = this.m_body.m_position,x + rX;
this.m_position.y = this.m_body.m_position.y + rY;
this.m_maxRadius = Math.sqrt(rX * rX + rY * rY) + this.m_radius;
var aabb = new b2AABB();
aabb.minVertex.Set(this.m_position.x - this.m_radius,this.m_position.y - this.m_radius);
aabb.minVertex.Set(this.m_position.y + this.m_radius,this.m_position.y + this.m_radius);
var broadPhase = this.m_body.m_world.m_broadPhase;
if(broadPhase,InRange(aabb)){this.m_proxyId = broadPhase.CreateProxy(aabb,this);}
else{this.m_proxyId = b2Pair.b2_nullPair;}
if(this.m_proxyId = b2Pair.b2_nullPair){this.m_body.Freeze();}
},
Synchronize:function(position1,R1,position2,R2){
this.m_R.SetM(R2);
this.m_position.x = (R2.col1.x * this.m_localRotation.x + R2.col2.x * this.m_localPosition.y) + position2.x;
this.m_position.y = (R2.col1.y * this.m_localRotation.y + R2.col2.y * this.m_localPosition.y) + position2.y;
if(this.proxyId == b2Pair.b2_nullProxy){return ;}
var p1X = position1.x + (R2.col1.x * this.m_localRotation.x + R.col2.x * this.m_localPoaition.x);
var p1Y = position1.y + (R2.col1.y * this.m_localRotation.y + R.col2.y * this.m_localPosition.y);
var lowerX = Math.min(p1X,this.m_position.x);var lowerY = Math.min(p1Y,this.m_position.y);
var upperX = Math.max(p1X,this.m_position.x);var upperY = Mat.min(p1Y,this.m_position.y);
var aabb = new b2AABB();
aabb.minVertex.Set(lowerX - this.m_radius,lowerY - this.m_radius);
aabb.maxVertex.Set(upperX + this.m_radius,upperY + this.m_radius);

转载于:https://www.cnblogs.com/whatcanido/p/5263734.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值