adds documentation for AABB and revised IShape2D
parent
f8354b9970
commit
c5ad88074c
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
title: "AABB"
|
||||
date: 2019-12-31T14:36:00-07:00
|
||||
weight: 6
|
||||
---
|
||||
|
||||
*AABB*, or axis-aligned bounding box, is defined by a minimum point and a maximum point. It is used for broad-phase collision detection. It represents a rectangular outline of the shape so we can quickly insert shapes into a *SpatialHash*.
|
||||
|
||||
## Properties
|
||||
|
||||
##### **public Vector2 Min { get; private set; }**
|
||||
|
||||
The minimum point of the AABB.
|
||||
|
||||
##### **public Vector2 Max { get; private set; }**
|
||||
|
||||
The maximum point of the AABB.
|
||||
|
||||
## Methods
|
||||
|
||||
##### **public static AABB FromVertices(IEnumerable<Position2D> vertices)**
|
||||
|
||||
Can be used to generate an AABB from an arbitrary collection of vertices. It is generally better to define a more efficient AABB generation method based on the properties of a particular shape, but this can be used for an arbitrary collection of vertices, like a polygon.
|
||||
|
||||
##### **public static AABB Transformed(AABB aabb, Transform2D transform)**
|
||||
|
||||
Efficiently transforms an AABB. Used internally by SpatialHash to quickly transform a shape's AABB.
|
|
@ -8,6 +8,12 @@ An *IShape2D* is an interface that, when implemented, allows for spatial hashing
|
|||
|
||||
Your *IShape2D* implementations should be structs for memory efficiency purposes.
|
||||
|
||||
## Properties
|
||||
|
||||
##### **public AABB { get; }**
|
||||
|
||||
An axis-aligned bounding box for the shape. This is stored so we can efficiently transform the AABB when necessary.
|
||||
|
||||
## Methods
|
||||
|
||||
##### **Vector2 Support(Vector2 direction, Transform2D transform)**
|
||||
|
@ -34,13 +40,8 @@ A method which returns the axis-aligned bounding box for the transformed shape.
|
|||
For example, the AABB method for Bonk's *Circle* implementation:
|
||||
|
||||
```cs
|
||||
public AABB AABB(Transform2D Transform2D)
|
||||
public AABB TransformedAABB(Transform2D Transform2D)
|
||||
{
|
||||
return new AABB(
|
||||
Transform2D.Position.X - Radius,
|
||||
Transform2D.Position.Y - Radius,
|
||||
Transform2D.Position.X + Radius,
|
||||
Transform2D.Position.Y + Radius
|
||||
);
|
||||
return AABB.Transformed(AABB, transform2D);
|
||||
}
|
||||
```
|
||||
|
|
Loading…
Reference in New Issue