1.1 KiB
title | date | weight |
---|---|---|
GJK2D | 2019-09-14T22:47:55-07:00 | 10 |
Bonk uses the Gilbert-Johnson-Keerthi, or GJK, algorithm to perform narrow phase collision detection.
To accurately check a collision, you must pass two sets of shapes and transforms to the NarrowPhase.TestCollision method. Remember that a transform operates on the vertices of a shape: it moves, rotates, and scales them in 2D space.
var circleA = new Circle(2);
var transformA = new Transform2D(new Vector2(-1, -1));
var circleB = new Circle(2);
var transformB = new Transform2D(new Vector2(1, 1));
var result = NarrowPhase.TestCollision(circleA, transformA, circleB, transformB);
The GJK algorithm can also return a termination simplex. You can think of the termination simplex as a key that helps you find the penetration vector with NarrowPhase.Intersect. We have a related method, NarrowPhase.FindCollisionSimplex which returns two variables. The first is whether an overlap has occurred. The second is the termination simplex. Note that if there was no collision, the value of the simplex is irrelevant.