Safe Haskell | None |
---|---|
Language | Haskell2010 |
Separating Axis Test (SAT). A separating axis is a direction along which the projections of two shapes do not overlap. Alternately, a separating axis is a line between two shapes that do not intersect.
If no separating axis is found, use the axis of smallest overlap to determine which features of the objects are involved in the collision (e.g. calculate contact points and normals).
- data Overlap = Overlap {}
- overlapPenetrator :: Lens' Overlap Neighborhood
- overlapEdge :: Lens' Overlap Neighborhood
- overlapDepth :: Lens' Overlap Double
- data SATResult
- _MinOverlap :: Prism' SATResult Overlap
- _Separated :: Prism' SATResult Neighborhood
- type ContactPoints = Either Neighborhood (SP Neighborhood Neighborhood)
- data Contact = Contact {}
- contactPenetrator :: Lens' Contact ContactPoints
- contactPenetratingEdge :: Lens' Contact (SP Neighborhood Neighborhood)
- contactEdge :: Lens' Contact Neighborhood
- satToEither :: SATResult -> Either Neighborhood Overlap
- overlapTest :: Ord a => SP a a -> SP a a -> Bool
- overlapAmount :: (Ord a, Num a) => SP a a -> SP a a -> Maybe a
- overlapNormal :: Overlap -> V2
- overlap :: ConvexHull -> Neighborhood -> ConvexHull -> Maybe Overlap
- minOverlap :: ConvexHull -> [Neighborhood] -> ConvexHull -> SATResult
- minOverlap' :: ConvexHull -> ConvexHull -> SATResult
- penetratingEdge :: Overlap -> SP Neighborhood Neighborhood
- penetratedEdge :: Overlap -> SP Neighborhood Neighborhood
- contactPoints' :: ContactPoints -> Either P2 (SP P2 P2)
- flattenContactPoints :: ContactPoints -> Descending Neighborhood
- clipEdge :: SP Neighborhood Neighborhood -> V2 -> SP Neighborhood Neighborhood -> Maybe ContactPoints
- convertContactResult :: Flipping (Either Neighborhood (Maybe Contact)) -> Maybe (Flipping (Either Neighborhood Contact))
- contactDebug :: ConvexHull -> ConvexHull -> (Maybe (Flipping (Either Neighborhood Contact)), SATResult, SATResult)
- contact :: ConvexHull -> ConvexHull -> Maybe (Flipping (Either Neighborhood Contact))
- contact_ :: Overlap -> Maybe Contact
Documentation
An overlap between two shapes.
Overlap | |
|
Either the separating axis or the smallest overlap between two shapes.
Separated Neighborhood | the edge that forms a separating axis between the two shapes. |
MinOverlap Overlap | the smallest overlap |
type ContactPoints = Either Neighborhood (SP Neighborhood Neighborhood) Source #
A contact manifold can contain either a single point or a pair of points. For example, a pair of touching edges can be described by a pair of points. A vertex touching an edge can be described by a single point.
A contact manifold
Contact | |
|
satToEither :: SATResult -> Either Neighborhood Overlap Source #
One side of an isomorphism.
assumes pairs are (min, max)
:: (Ord a, Num a) | |
=> SP a a | an interval (e.g. the projection of a shape onto an axis) |
-> SP a a | another interval |
-> Maybe a | If the intervals overlap, by how much? |
assumes pairs are (min, max)
overlapNormal :: Overlap -> V2 Source #
get the normal from the overlap
:: ConvexHull | The receiving shape "sEdge". |
-> Neighborhood | An edge normal from the receiving shape. |
-> ConvexHull | The penetrating shape "sPen". |
-> Maybe Overlap | Any overlap from "sPen" into "sEdge". |
Check for overlap along a single axis (edge normal).
:: ConvexHull | The receiving shape "sEdge". |
-> [Neighborhood] | Edge normals from the receiving shape. |
-> ConvexHull | The penetrating shape "sPen". |
-> SATResult | Axis of smallest overlap or separating axis. |
Find the axis (edge normal) with the smallest overlap between the two shapes.
minOverlap' :: ConvexHull -> ConvexHull -> SATResult Source #
Wrapper for minOverlap
.
:: Overlap | |
-> SP Neighborhood Neighborhood | the two vertices that define the edge (in order) |
Choose the best edge to act as a penetrator. The overlap test yields a penetrating vertex, but this vertex belongs to two edges.
Choose the edge that is closest to perpendicular to the overlap normal vector. i.e. the edge that is closest to parallel with the penetrated edge
penetratedEdge :: Overlap -> SP Neighborhood Neighborhood Source #
Extract the endpoints of the penetrated edge.
contactPoints' :: ContactPoints -> Either P2 (SP P2 P2) Source #
Extract just the point data from ContactPoints
.
flattenContactPoints :: ContactPoints -> Descending Neighborhood Source #
Sort ContactPoints
by decreasing feature index.
:: SP Neighborhood Neighborhood | the penetrated edge |
-> V2 | the normal vector for the overlap |
-> SP Neighborhood Neighborhood | the penetrating edge ("incident" edge) |
-> Maybe ContactPoints |
Clip a pair of edges into a contact manifold.
convertContactResult :: Flipping (Either Neighborhood (Maybe Contact)) -> Maybe (Flipping (Either Neighborhood Contact)) Source #
Pull out the inner Maybe
.
:: ConvexHull | |
-> ConvexHull | |
-> (Maybe (Flipping (Either Neighborhood Contact)), SATResult, SATResult) |
|
Flipping
indicates the direction of the collision.
Same
means a
is penetrated by b
.
Flipped
means b
is penetrated by a
.
How it works:
- Find the smallest overlap along the axes of each shape's edges.
- Clip this overlap to a contact manifold.
The result should probably never be Nothing
, but I don't know if that's guaranteed.
:: ConvexHull | shape "a" |
-> ConvexHull | shape "b" |
-> Maybe (Flipping (Either Neighborhood Contact)) |
|