box2d.b2EdgeShape.prototype.ComputeDistance = function(xf, p, normal, childIndex) {
var v1 = box2d.b2Mul_X_V2(xf, this.m_vertex1, box2d.b2EdgeShape.prototype.ComputeDistance.s_v1);
var v2 = box2d.b2Mul_X_V2(xf, this.m_vertex2, box2d.b2EdgeShape.prototype.ComputeDistance.s_v2);
var d = box2d.b2Sub_V2_V2(p, v1, box2d.b2EdgeShape.prototype.ComputeDistance.s_d);
var s = box2d.b2Sub_V2_V2(v2, v1, box2d.b2EdgeShape.prototype.ComputeDistance.s_s);
var ds = box2d.b2Dot_V2_V2(d, s);
if (ds > 0) {
var s2 = box2d.b2Dot_V2_V2(s, s);
if (ds > s2) {
box2d.b2Sub_V2_V2(p, v2, d);
} else {
d.SelfMulSub(ds / s2, s);
}
}
normal.Copy(d);
return normal.Normalize();
}
Comentários