Detecting Collision and identifying the contact point
function b2CollideCircles( manifold, circleA, xfA, circleB, xfB) {
manifold.pointCount = 0;
let pA = Transform.MulTV(xfA, circleA.p);
let pB = Transform.MulTV(xfB, circleB.p);
let d = Vec2.Subtract(pB, pA);
let distSqr = Vec2.b2Dot(d, d);
let rA = circleA.radius;
let rB = circleB.radius;
let radius = rA + rB;
if (distSqr > radius * radius) {
return;
}
manifold.type = b2Manifold.e_circles;
manifold.localPoint = circleA.p;
manifold.localNormal.reset();
manifold.pointCount = 1;
manifold.points[0].localPoint = circleB.p;
manifold.points[0].id.key = 0;
}
Comments