updates for bonk 2.0

main
Evan Hemsley 2019-10-25 14:37:17 -07:00
parent 87d859138f
commit 2891709536
4 changed files with 27 additions and 9 deletions

View File

@ -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 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/). Bonk is available as a [NuGet package](https://www.nuget.org/packages/MoonTools.Core.Bonk/).

View File

@ -4,11 +4,11 @@ date: 2019-09-15T11:23:43-07:00
weight: 30 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 ## Methods
##### **public static Vector2 Intersect(IShape2D shapeA, Transform2D Transform2DA, IShape2D shapeB, Transform2D Transform2DB, IEnumerable<Vector2> 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. 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 squareB = new Rectangle(-1, -1, 1, 1);
var transformB = new Transform2D(new Vector2(1.5f, 0)); 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) if (result)
{ {

View File

@ -4,13 +4,29 @@ date: 2019-09-15T11:19:13-07:00
weight: 20 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 ## 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:** **Example:**
```cs ```cs
@ -22,4 +38,4 @@ var transformB = new Transform2D(new Vector2(1, 1));
var (result, simplex) = GJK2D.TestCollision(circleA, transformA, circleB, transformB); 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. 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.

View File

@ -17,3 +17,5 @@ To define a polygon, pass a variable number of **Position2D** structs representi
This polygon, for example, is a triangle. 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. 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.