3.5 KiB
title | date | weight |
---|---|---|
NarrowPhase | 2019-09-15T11:19:13-07:00 | 20 |
NarrowPhase is a static class containing methods for narrow-phase collision detection.
Note that all the TestCollision overloads automatically employ fast path checks.
Methods
public static bool TestCollision(IShape2D shapeA, Transform2D transformA, IShape2D shapeB, Transform2D transformB)
Tests if the two shape-transform pairs are overlapping.
Example:
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 = GJK2D.TestCollision(circleA, transformA, circleB, transformB);
In this example, these transformed circles are indeed overlapping, so result will be true.
public static bool TestCollision(IHasAABB2D hasBoundingBoxA, Transform2D transformA, IHasAABB2D hasBoundingBoxB, Transform2D transformB)
Detects whether two AABB-transform pairs are overlapping.
public static bool TestCollision(MultiShape multiShape, Transform2D multiShapeTransform, IShape2D shape, Transform2D shapeTransform)
Tests if a multishape-transform and shape-transform pair are overlapping.
public static bool TestCollision(IShape2D shape, Transform2D shapeTransform, MultiShape multiShape, Transform2D multiShapeTransform)
Tests if a multishape-transform and shape-transform pair are overlapping.
public static bool TestCollision(MultiShape multiShapeA, Transform2D transformA, MultiShape multiShapeB, Transform2D transformB)
Tests if two multishape-transform pairs are overlapping.
public static bool TestRectangleOverlap(Rectangle rectangleA, Transform2D transformA, Rectangle rectangleB, Transform2D transformB)
Fast path for axis-aligned rectangles. Assumes that the transforms have zero rotation. If the transforms have non-zero rotation this will be inaccurate.
public static bool TestPointRectangleOverlap(Point point, Transform2D pointTransform, Rectangle rectangle, Transform2D rectangleTransform)
Fast path for overlapping point and axis-aligned rectangle. The rectangle transform must have non-zero rotation.
public static bool TestCircleOverlap(Circle circleA, Transform2D transformA, Circle circleB, Transform2D transformB)
Fast path for overlapping circles. The circles must have uniform scaling.
public static (bool, Simplex) FindCollisionSimplex(IShape2D shapeA, Transform2D transformA, IShape2D shapeB, Transform2D transformB)
Tests if the two shape-transform pairs are overlapping, and if so returns a Simplex that can be used by the EPA algorithm to determine a minimum separating vector.
Example:
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, simplex) = GJK2D.TestCollision(circleA, transformA, circleB, transformB);
In this example, these transformed circles are indeed overlapping, so result will be true and simplex will contain the Simplex that can be used by EPA to determine a minimum separating vector.
public unsafe static Vector2 Intersect(IShape2D shapeA, Transform2D Transform2DA, IShape2D shapeB, Transform2D Transform2DB, Simplex2D simplex)
Returns a minimum separating vector in the direction from A to B. This information can be used to push two overlapping shape-transforms apart.