2016/03/05 codes

var tMat = poly1.m_R;
normal1X = tMat.col1.x * tX + tMat.col2.x * normal1Y;
normal1Y = tMat.col1.y * tX + tMat.col2.x * normal1Y;
var normalLocal2X = normal1X;
var normalLocal2Y = normal1Y;
tMat = poly2.m_R;
tX = normalLocal2X * tMat.col1.x + normalLocal2Y * tMat.col1.y;
normalLocal2Y = normalLocal2X * tMat.col2.x + normalLocal2Y * tMat.col2.y;
normalLocal2X = tX;
var vertex21 = 0;
var vertex22 = 0;
var minDot = number.MAX_VALUE;
for(var i = 0;i < count2;++i){
var i1 = 0;
var i2 = i + 1 < count2 ? i + 1:0;
tVec = vert2s[i2];
var normal2Local2X = tVec.x;
var normal2Local2Y = tVec.y;
tVec = vert2s[i1];
normal2Local2X -= tVec.x;
normal2Local2Y -= tVec.y;
tX = normal2Local2X;
normal2Local2X = normal2Local2Y;
normal2Local2Y = -tX;
invLength = 1.0 / Math.sqrt(normal2Local2X * normal2Local2X + normal2Local2Y * normal2Local2Y);
normal2Local2X *= invLength;normal2Local2Y *= invLength;
var dot = normal2Local2X * normalLocal1X + normal2Local2Y * normalLocal1Y;
if(dot < minDot){minDot = dot;vertex21 = i1;vertex22 = i2;}
}
var tClip;tClip = c[0];
tVec = tClip.c;
tVec.SetV(vert2s[vertex21]);
tVec.MulM(poly2.m_R);
tVec.Add(poly2.m_position);
tClip.id.features.referenceFace = edge1;
tClip.id.features.incidentEdge = vertex21;
tClip.id.features.incidentVertex = vertex21;
tClip = c[1];
tVec = tClip.v;
tVec.SetV(vert2s[vertex22]);
tVec.MulM(poly2.m_R);
tVec.Add(poly2.m_position);
tClip.id.features.referenceFace = edge1;
tClip.id.features.incidentEdge =vertex21;
tClip.id.features.incidentVertex = vertex22;
};
b2Collision.b2CollidePolyTempVec = new b2Vec2();
b2Collision.b2CollidePoly = function(mainfold,polyA,polyB,conservative){
mainfold.pointCount = 0;
var edgeA = 0;
var edgeAOut = [edgeA];
var separationA = b2Collision.FindMaxSeparation(edgeAOut,polyA,polyB,conservative);
edgeA = edgeAOut[0];
if(separationA > 0.0 && conservative == false){return ;}
var edgeB = 0;
var edgeBOut = [edgeB];
var separationB = b2Collision.FindMaxSeparation(edgeBOut,polyA,polyB,conservative);
edgeB = edgeBOut[0];
if(separationB > 0.0 && conservative == false)return;
var poly1;
var poly2;
var edge1 = 0;
var flip = 0;
var k_relativeTol = 0.98;
var k_absoluteTol = 0.001;
if(separationA > k_relativeTol * separationB + k_absoluteTol){poly1 = polyB;poly2 = polybA;edge1 = edgeB;flip = 1;}
else{poly1 = polyA;poly2 = polyB;edge1 = edgeA;flip = 0;}
var incidentEdge = [new ClipVertex(),new ClipVertex()];
b2Collision.FindIncidentEdge(incidentEdge,poly1.edge1,poly2);
var count1 = poly1.m_vertexCount;
var vert1s = poly1.m_vertices;
var v11 = vert1s[edge1];
var v12 = edge1 + 1 < count1 ? vert1s[edge1 + 1]:vert1s[0];
var dvX = v12.x - v11.x;
var dvY = v12.y - v11.y;
var sideNormalX = v12.x - v11.x;
var sideNormalY = v12.y - v11.y;
var tX = sideNormalX;
var tMat = poly1.m_R;
sideNormalX = tMat.col1.x * tX + tMat.col2.x * sideNormalY;
sideNormalY = tMat.col1.y * tX + tMat.col2.y * sideNormalY;
var invLength = 1.0 / Math.sqrt(sideNormalX * sideNormalX + sideNormalY * sideNormalY);
sideNormalX *= invLength;sideNormalY *= invLength;
var frontNormalX = sideNormalX;
var frontNormalY = sideNormalY;
tX = frontNormalX;
frontNormalX = frontNormalY;
frontNormalY = -tX;
var v11X = v11.x;
var v11Y = v11.y;
tX = v11X;
tMat = poly1.m_R;
v11X = tMat.col1.x * tX + tMat.col2.x * v11Y;
v11Y = tMat.col1.y * tX + tMat.col2.y * v11Y;
v11X += poly1.m_position.x;
v11Y += poly1.m_position.y;
var v12X = v12.x;
var v12Y = v12.y;
tX = v12X;
tMat = poly1.m_R;
v12X = tMat.col1.x * tX + tMat.col2.x * v12Y;
v12Y = tMat.col1.y * tX + tMat.col2.y * v12Y;
v12X += poly1.m_position.x;
v12Y += poly1.m_position.y;
var frontOffset = frontNormalX * v11X + frontNormalY * v11Y;
var sideOffset1 = -(sideNormalX * v11X + sideNormalY * v11Y);
var sideOffset2 = sideNormalX * v12X + sideNormalY * v12Y;
var clipPoint1 = [new ClipVertex(),new ClipVertex()];
var clipPoint2 = [new ClipVertex(),new ClipVertex()];
var np = 0;
b2Collision.b2CollidePolyTempVec.set(-sideNormalX,-sideNormalY);
np = b2Collision.ClipSegmentToLine(clipPoint1,incidentEdge,b2Collision.b2CollidePolyTempVec,sideOffset1);
if(np < 2)return;
b2Collision.b2CollidePolyTempVec.Set(sideNormalX,sideNormalY);
np = b2Collision.ClipSegmentToLine(clipPoint2,incidentEdge,b2Collision.b2CollidePolyTempVec,sideOffset2);
if(np < 2)return;
if(flip){mainfold.normal.Set(-frontNormalX,-frontNormalY);}
else{mainfold.normal.Set(frontNormalX,frontNormalY);}
var pointCount = 0;
for(var i = 0;i < b2Settins.b2_maxManifoldPoints;++i){
var tVec = clipPoint2[i].v;
var separation = (frontNormalX * tVec.x + frontNormalY * tVec. y) - frontOffset;
if(separation <= 0.0 || conservative == false){
var cp = mainfold.points[pointCount];
cp.separation = separation;
cp.position.SetV(clipPoint2[i].v);
cp.id.SetV(clipPoint2[i].v);
cp.id.features.flip = flp;
++pointCount;
}
}
mainfold.pointCount = pointCount;
};
b2Collision.b2CollideCircle = function(mainfold,circle1,circle2,conservative){
mainfold.pointCount = 0;
var dX = circle2.m_position.x - circle1.m_position.x;
var dY = circle2.m_position.y - circle1.m_position.y;
var distSqr = dX * dX + dY * dY;
var radiusSum = circle1.m_radius + circle2.m_radius;
if(distSqr > radiusSum * radiusSum && conservative == false){return ;}
var separation;
if(distSqr < Number.MIN_VALUE){separation = -radiusSum;mainfold.normal.Set(0.0,1.0);}
else{
var dist = Math.sqrt(distSqr);
separation = dist - radiusSum;
var a = 1.0 / dist;
mainfold.normal.x = a * dX;
mainfold.normal.y = a * dY;
mainfold.pointCount = 1;
var tPoint = mainfold.points[0];
tPoint.id.set_key(0);
tPoint.separation = separation;
tPoint.separation.x = circle2.m_position.x - (circle2.m_radius * mainfold.normal.x);
tPoint.separation.y = circle2.m_position.y - (circle2.m_radius * mainfold.normal.y);
};
b2Collision.b2CollidePolyAndCircle = function(mainfold,circle,poly,conservative){
mainfold.pointCount = 0;
var tPoint;var dX;var dY;
var xLocalX = circle.m_position.x - poly.m_position.x;
var yLocalY = circle.m_position.y - poly.m_position.y;
var tMat = poly.m_R;
var tX = xLocalX * tMat.col1.x + xLocalY * tMat.col1.y;
var tY = xLocalX * tMat.col2.x + xLocalY * tMat.col2.y;
xLocalX = tX;
var dist;
var normalIndex = 0;
var separation = -Number.MAX_VALUE;
var radius = circle.m_radius;
for(var i = 0;i < poly.m_vertexCount;++i){
var s = poly.m_normals[i]. x * (xLocalX - poly.m_vertices[i].x) + poly.m_normals[i].y * (xLocalY - poly.m_vertices[i].y);
if(s > radius){return radius};
if(s > separation){separation = s;normalIndex = i;}
if(separation < Number.MIN_VALUE){
mainfold.pointCount = 1;
var tVec = poly.m_normals[normalIndex];
mainfold.normal.x = tMat.col1.x * tVec.x + tMat.col2.x * tVec.y;
mainfold.normal.y = tMat.col1.y * tVec.y + tMat.col2.y * tVec.y;
tPoint = mainfold.points[0];
tPoint.id.features.incidentEdge = normalIndex;
tPoint.id.features.incidentVertex = b2Collision.b2_nullFeature;
tPoint.id.features.referenceFace = b2Collision.b2_nullFeature;
tPoint.id.features.flip = 0;
tPoint.position.x = circle.m_position.x - radius * mainfold.normal.x;
tPoint.position.y = circle.m_position.y - radius * mainfold.normal.y;
tPoint.separation = separation - radius;
return;
}
}
}
}

}

时间: 2024-12-20 08:23:05

2016/03/05 codes的相关文章

2016/03/06 codes

var vertIndex = normalIndex; var vertIndex2 = vertIndex + 1 < poly.m_vertexCount ? vertIndex + 1 : 0; var eX = poly.m_vertices[vertIndex2].x - p.m_vertices[vertIndex1].x; var eY = poly.m_vertices[vertIndex2].y - p.m_vertices[vertIndex1].y; var length

2016/03/16 codes

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>导航条2</title> <style type="text/css"> *{ margin: 0; padding: 0; list-style: none; } #nav{ width: 1000px; margin:10px

2016/03/07 codes

Features.prototype = { set_referenceFace:function(value){ this._referenceFace = value; this._m_id._key = (this._m_id._key & 0xffffff00) | (this._referenceFace & 0x000000ff) }, get_referenceFace:function(){return this._referenceFace;},_referenceFac

2016/03/01 codes

if(deltaUpper > 0){ index = upperIndex; while(index < boundCount - 1 && bounds[index + 1].value <= upperValue){ bound = bounds[index]; nextBound = bounds[index + 1]; nextProxyId = nextBound.proxyId; nextProxy = this.m_proxyPool[nextProxyI

2016/02/21 codes

var Class = { create:function(){ var parent = null,properties = $A(arguments); if(Object.isFunction(properties[0])) parent = properties.shift(); function kclass(){ this.initialize.apply(this.arguments); } Object.extend(kclass,Class.Methods); kclass.s

分布式技术一周技术动态 2016.03.20

分布式系统实践 1. 基于Mesos和Docker的分布式计算平台 https://mp.weixin.qq.com/s?__biz=MzAxMDgzOTA2Mw==&mid=402769128&idx=1&sn=cea3ad1357bd9312acf1768c0a493bfd&scene=1&srcid=0318BTuxT0fsFYwPjpeyuDOa&key=710a5d99946419d90fbc1e7600cce055b6e997d6afafc74c

2016/02/16 codes

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title>2016/02/16 codes</title> <link rel="stylesheet" href="assets/reset.css"> <style> .slideOne{ width:

【EPM-易通元】2016年05月03日凌晨迎来第6次坼分庆祝

[EPM易通元5月3日凌晨迎来了第6次拆分庆贺] 易通元的家人们幸福啦,么么哒……大家迎来了EPM第六次拆分,股数翻倍,积分又回到0.2美金啦所有参与易通元理财的家人们幸福喽,发财啦……么么哒 “EPM-易通元创始人安德森”先生为了易通元,放弃年薪千万美金在花旗银行的高管工作,就如同当年阿里巴巴蔡崇信放弃汇丰银行年薪580万工作一样,这是常人智慧想不到的! [关于拆分盘客观分析]一.决定拆分盘存活的关键是前面3-6次拆分!二.拆分盘几种结局:1.胎死腹中:    内排,抢先机,未开盘就挂了!2.

2016/03/03 codes

<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8"> <title></title> <style type="text/css"> .heart{ width: 200px; height: 200px; background-color: #d31145; margin: 100px auto