2016/03/05 codes
Posted 琳姐姐
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;
}
}
}
}
}
以上是关于2016/03/05 codes的主要内容,如果未能解决你的问题,请参考以下文章
[2016-03-05][UVALive][4504][Trick or Treat]