From 2891709536eb5a2f74277cdeae97fed006f00b58 Mon Sep 17 00:00:00 2001 From: Evan Hemsley Date: Fri, 25 Oct 2019 14:37:17 -0700 Subject: [PATCH] updates for bonk 2.0 --- content/_index.md | 2 +- content/api/EPA2D.md | 6 +++--- content/api/GJK2D.md | 24 ++++++++++++++++++++---- content/shapes/polygon.md | 4 +++- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/content/_index.md b/content/_index.md index 1adc916..baba24f 100644 --- a/content/_index.md +++ b/content/_index.md @@ -10,7 +10,7 @@ Bonk **is** designed to help you figure out if two shapes are overlapping and by Bonk **is not** a physics simulator and it will not help you execute collision responses. -Bonk is designed for performance and memory efficiency. Defining shapes and performing collision tests require no heap allocations and thus put no pressure on the garbage collector. If you reuse spatial hashes, Bonk will never cause garbage collection. +Bonk is designed for performance and memory efficiency. Defining most shapes and performing collision tests require no heap allocations and thus put no pressure on the garbage collector. If you reuse spatial hashes and avoid using arbitrary polygons, Bonk will never cause garbage collection. Bonk is available as a [NuGet package](https://www.nuget.org/packages/MoonTools.Core.Bonk/). diff --git a/content/api/EPA2D.md b/content/api/EPA2D.md index 171291c..bb9373c 100644 --- a/content/api/EPA2D.md +++ b/content/api/EPA2D.md @@ -4,11 +4,11 @@ date: 2019-09-15T11:23:43-07:00 weight: 30 --- -*EPA2D* is a static class containing a single public method which is used for computing the penetration vector of two overlapping shapes. +*EPA2D* is a static class containing a single method for computing the penetration vector of two overlapping shapes. ## Methods -##### **public static Vector2 Intersect(IShape2D shapeA, Transform2D Transform2DA, IShape2D shapeB, Transform2D Transform2DB, IEnumerable givenSimplexVertices)** +##### **public static Vector2 Intersect(IShape2D shapeA, Transform2D Transform2DA, IShape2D shapeB, Transform2D Transform2DB, Simplex simplex)** Given two sets of shapes and transforms and an initial simplex, computes a penetration vector. When motion along the penetration vector is applied, the shape-transforms are guaranteed to become separated. @@ -20,7 +20,7 @@ var transformA = Transform2D.DefaultTransform; var squareB = new Rectangle(-1, -1, 1, 1); var transformB = new Transform2D(new Vector2(1.5f, 0)); -var (result, simplex) = GJK2D.TestCollision(squareA, transformA, squareB, transformB); +var (result, simplex) = GJK2D.FindCollisionSimplex(squareA, transformA, squareB, transformB); if (result) { diff --git a/content/api/GJK2D.md b/content/api/GJK2D.md index b054e66..c6ee413 100644 --- a/content/api/GJK2D.md +++ b/content/api/GJK2D.md @@ -4,13 +4,29 @@ date: 2019-09-15T11:19:13-07:00 weight: 20 --- -*GJK2D* is a static class containing a single public method which is used for narrow-phase collision detection. +*GJK2D* is a static class containing methods for narrow-phase collision detection. ## Methods -##### **public static (bool, SimplexVertices) TestCollision(IShape2D shapeA, Transform2D transformA, IShape2D shapeB, Transform2D transformB)** +##### **public static bool TestCollision(IShape2D shapeA, Transform2D transformA, IShape2D shapeB, Transform2D transformB)** -Returns a tuple containing two values: the collision result and the simplex. If there is an overlap, the simplex will contain the termination simplex that can be used as a starting point for the Expanding Polytope Algorithm to compute a penetration vector. Otherwise, the simplex can be ignored. +Tests if the two shape-transform pairs are overlapping. + +**Example:** +```cs +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, 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:** ```cs @@ -22,4 +38,4 @@ 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 termination simplex. \ No newline at end of file +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. \ No newline at end of file diff --git a/content/shapes/polygon.md b/content/shapes/polygon.md index 0ce70d9..fc295e3 100644 --- a/content/shapes/polygon.md +++ b/content/shapes/polygon.md @@ -16,4 +16,6 @@ To define a polygon, pass a variable number of **Position2D** structs representi This polygon, for example, is a triangle. -Be careful not to define a concave Polygon, as this will cause the results of collision detection to be incorrect. \ No newline at end of file +Be careful not to define a concave Polygon, as this will cause the results of collision detection to be incorrect. + +Also note that because Polygon stores its vertices in an array, instantiating Polygons will cause GC pressure. It is best to use another kind of `IShape2D` if possible. \ No newline at end of file