top of page
Search
cedarcantab

Studying Box2D-Lite in Javascript, Part 7.1: Collision Detection - Circle vs Circle

Updated: Mar 1




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;

}

5 views0 comments

Recent Posts

See All

p2 naive broadphase

var Broadphase = require('../collision/Broadphase'); module.exports = NaiveBroadphase; /** * Naive broadphase implementation. Does N^2...

sopiro motor constranit

import { Matrix2, Vector2 } from "./math.js"; import { RigidBody } from "./rigidbody.js"; import { Settings } from "./settings.js";...

Comments


記事: Blog2_Post
bottom of page