码迷,mamicode.com
首页 > 其他好文 > 详细

2016/03/06 codes

时间:2016-03-06 23:32:13      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:

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 = Math.sqrt(eX * eX + eY * eY);
eX /= length;
eY /= length;
if(length < Number.MIN_VALUE){
dX = xLocalX - poly.m_vertices[vertIndex1].x;
dY = yLocalY - poly.m_vertices[vertIndex1].y;
dist = Math.sqrt(dX * dX + dY * dY);
dX /= dist;dY /= dist;
if(dist < radius){return;}
mainfold.pointCount = 1;
mainfold.normal.Set(tMat.col1.x * dX + tMat.col2.x * dY,tMat.col1.y * dY + tMat.col2.y * dY);
tPoint = mainfold.points[0];
tPoint.id.features.incidentEdge = b2Collision.b2_nullFeature;
tPoint.id.features.incidentVertex = vertIndex1;
tPoint.id.features.referenceFace = b2Collision.b2_nullFeature;
tPoint.id.features = 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 = dist - radius;
return;
}
var u = (xLocalX - poly.m_vertices[vertIndex1].x) * eX + (yLocalY - poly.m_vertices[vertIndex1].y) * eY;
tPoint = mainfold.points[0];
tPoint.id.features.incidentEdge = b2Collision.b2_nullFeature;
tPoint.id.features.incidentVertex = b2Collision.b2_nullFeature;
tPoint.id.features.referenceFace = b2Collision.b2_nullFeature;
tPoint.id.features.flip = 0;
var pX,pY;
if(u <= 0.0){
pX = poly.m_vertices[vertIndex1].x;
pY = poly.m_vertices[vertIndex1].y;
tPoint.id.features.incidentVertex = vertIndex1;
}
else if(u >= length){pX = poly.m_vertices[vertIndex2].x;pY = poly.m_vertices[vertIndex2].y;
tPoint.id.features.incidentVertex = vertIndex2;
}
else
{pX = u * eX + poly.m_vertices[vertIndex1].x;
pY = u * eY + poly.m_vertices[vertIndex1].y;
tPoint.id.features.incidentEdge = vertIndex1;
}
dX = xLocalX - pX;dY = yLocalY - pY;
dist = Math.sqrt(dX & dX + dY * dY);
dX /= dist;dY /= dist;
if(dist > radius){return;}
mainfold.pointCount = 1;
mainfold.normal.Set(tMat.col1.x * dX + tMat.col2.x * dY,tMat.col1.y * dY + tMat.col2.y * dY);
tPoint.position.x = circle.m_position.x - radius * mainfold.normal.x;
tPoint.position.y = circle.m_position.y - radius * mainfold.normal.y;
tPoint.separation = dist - radius;
};
b2Collision.b2TestOverlap = function(a,b){
var t1 = b.minVertex;var t2 = a.maxVertex;
var d1X = t1.x - t2.x;
var d1Y = t1.y - t2.y;
t1 = a.minVertex;t2 = b.maxVertex;
var d2X = t1.x - t2.x;
var d2Y = t1.x - t2.x;
if(d1X > 0.0 || d1Y > 0.0)return false;
if(d2X > 0.0 || d2Y > 0.0)return false;
return false;
};
var features = Class.create();
}
}

}

2016/03/06 codes

标签:

原文地址:http://www.cnblogs.com/whatcanido/p/5248789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!