PlayRho  2.0.0
An interactive physics engine & library.
playrho::d2::Manifold Class Reference

A collision response oriented description of the intersection of two convex shapes. More...

#include <playrho/d2/Manifold.hpp>

Classes

struct  Conf
 Configuration data for manifold calculation. More...
 
struct  Point
 Data for a point of collision in a Manifold. More...
 

Public Types

using CfIndex = ContactFeature::Index
 The contact feature index.
 
using size_type = std::remove_const_t< decltype(MaxManifoldPoints)>
 Size type.
 
enum  Type : std::uint8_t { e_unset , e_circles , e_faceA , e_faceB }
 Manifold type. More...
 

Public Member Functions

 Manifold ()=default
 
void AddPoint (const Point &mp) noexcept
 
constexpr ContactFeature GetContactFeature (size_type index) const noexcept
 Gets the contact feature for the given index. More...
 
constexpr Momentum2 GetImpulses (size_type index) const noexcept
 Gets the impulses for the given index. More...
 
constexpr UnitVec GetLocalNormal () const noexcept
 Gets the local normal for a face-type manifold. More...
 
constexpr Length2 GetLocalPoint () const noexcept
 Gets the local point. More...
 
constexpr Length2 GetOpposingPoint (size_type index) const noexcept
 Gets the opposing point. More...
 
const PointGetPoint (size_type index) const noexcept
 Gets the point identified by the given index. More...
 
constexpr size_type GetPointCount () const noexcept
 
constexpr Type GetType () const noexcept
 
void SetImpulses (size_type index, const Momentum2 &value) noexcept
 Sets the impulses for the given index. More...
 
void SetImpulses (size_type index, Momentum n, Momentum t) noexcept
 Sets the impulses for the given index. More...
 

Static Public Member Functions

static Manifold GetForCircles (const Length2 &vA, CfIndex iA, const Length2 &vB, CfIndex iB) noexcept
 
static Manifold GetForFaceA (const UnitVec &ln, const Length2 &lp, const Point &mp1) noexcept
 
static Manifold GetForFaceA (const UnitVec &ln, const Length2 &lp, const Point &mp1, const Point &mp2) noexcept
 
static Manifold GetForFaceA (const UnitVec &normalA, const Length2 &faceA) noexcept
 
static Manifold GetForFaceB (const UnitVec &ln, const Length2 &lp) noexcept
 
static Manifold GetForFaceB (const UnitVec &ln, const Length2 &lp, const Point &mp1) noexcept
 
static Manifold GetForFaceB (const UnitVec &ln, const Length2 &lp, const Point &mp1, const Point &mp2) noexcept
 

Related Functions

(Note that these are not member functions.)

Manifold CollideShapes (const DistanceProxy &shapeA, const Transformation &xfA, const DistanceProxy &shapeB, const Transformation &xfB, const Manifold::Conf &conf=GetDefaultManifoldConf())
 Calculates the relevant collision manifold. More...
 
WorldManifold GetWorldManifold (const Manifold &manifold, const Transformation &xfA, Length radiusA, const Transformation &xfB, Length radiusB)
 Gets the world manifold for the given data. More...
 
constexpr auto IsValid (const d2::Manifold &value) noexcept -> bool
 Gets whether the given manifold is valid.
 
bool operator!= (const Manifold &lhs, const Manifold &rhs) noexcept
 Manifold inequality operator. More...
 
bool operator== (const Manifold &lhs, const Manifold &rhs) noexcept
 Manifold equality operator. More...
 

Detailed Description

A collision response oriented description of the intersection of two convex shapes.

This describes zero, one, or two points of contact for which impulses should be applied to most naturally resolve those contacts. Ideally the manifold is calculated at the earliest point in time of contact occurring. The further past that time, the less natural contact resolution of solid bodies will be - eventually resulting in oddities like tunneling.

Multiple types of contact are supported: clip point versus plane with radius, point versus point with radius (circles). Contacts are stored in this way so that position correction can account for movement, which is critical for continuous physics. All contact scenarios must be expressed in one of these types.

Conceptually, a manifold represents the intersection of two convex sets (which is itself a convex set) and a solution for moving the sets away from each other to eliminate the intersection.

Note
The local point and local normal usage depends on the manifold type. For details, see the documentation associated with the different manifold types.
Every point adds computational overhead to the collision response calculation - so express collision manifolds with one point if possible instead of two.
See also
Contact, PositionConstraint, VelocityConstraint
https://en.wikipedia.org/wiki/Convex_set
http://box2d.org/files/GDC2007/GDC2007_Catto_Erin_Physics2.ppt

Member Enumeration Documentation

◆ Type

enum playrho::d2::Manifold::Type : std::uint8_t

Manifold type.

Enumerator
e_unset 

Unset type.

Manifold is unset. For manifolds of this type: the point count is zero, point data is not defined, and all other properties are invalid.

e_circles 

Circles type.

Manifold is for circle-to-circle like collisions.

Note
For manifolds of this type: the local point is local center of "circle-A" (where shape A wasn't necessarily a circle but treating it as such is useful), the local normal is invalid (and unused) and, the point count will be zero or one where the contact feature will be ContactFeature{e_vertex, i, e_vertex, j} where i and j are indexes of the vertexes of shapes A and B respectively.
e_faceA 

Face-A type.

Indicates: local point is center of face A, local normal is normal on shape A, and the local points of Point instances are the local center of circle B or a clip point of polygon B where the contact feature will be ContactFeature{e_face, i, e_vertex, j} or ContactFeature{e_face, i, e_face, j} where i and j are indexes for the vertex or edge of shapes A and B respectively..

e_faceB 

Face-B type.

Indicates: local point is center of face B, local normal is normal on shape B, and the local points of Point instances are the local center of circle A or a clip point of polygon A where the contact feature will be ContactFeature{e_face, i, e_vertex, j} or ContactFeature{e_face, i, e_face, j} where i and j are indexes for the vertex or edge of shapes A and B respectively..

Constructor & Destructor Documentation

◆ Manifold()

playrho::d2::Manifold::Manifold ( )
default

Default constructor.

Constructs an unset-type manifold. For an unset-type manifold: point count is zero, point data is not defined, and all other properties are invalid.

Member Function Documentation

◆ AddPoint()

void playrho::d2::Manifold::AddPoint ( const Point mp)
inlinenoexcept

Adds a new point.

This can be called once for circle type manifolds, and up to twice for face-A or face-B type manifolds. GetPointCount() can be called to find out how many points have already been added.

Precondition
GetType() is not e_unset.
GetPointCount() is less than MaxManifoldPoints.

◆ GetContactFeature()

constexpr ContactFeature playrho::d2::Manifold::GetContactFeature ( size_type  index) const
inlineconstexprnoexcept

Gets the contact feature for the given index.

Precondition
index is less than GetPointCount().

◆ GetForCircles()

static Manifold playrho::d2::Manifold::GetForCircles ( const Length2 vA,
CfIndex  iA,
const Length2 vB,
CfIndex  iB 
)
inlinestaticnoexcept

Gets a circles-typed manifold with one point.

Parameters
vALocal center of "circle" A.
iAIndex of vertex from shape A representing the local center of "circle" A.
vBLocal center of "circle" B.
iBIndex of vertex from shape B representing the local center of "circle" B.

Referenced by playrho::d2::GetManifold().

◆ GetForFaceA() [1/3]

static Manifold playrho::d2::Manifold::GetForFaceA ( const UnitVec ln,
const Length2 lp,
const Point mp1 
)
inlinestaticnoexcept

Gets a face A typed manifold.

Parameters
lnNormal on polygon A.
lpCenter of face A.
mp1Manifold point 1 (of 1).

◆ GetForFaceA() [2/3]

static Manifold playrho::d2::Manifold::GetForFaceA ( const UnitVec ln,
const Length2 lp,
const Point mp1,
const Point mp2 
)
inlinestaticnoexcept

Gets a face A typed manifold.

Parameters
lnNormal on polygon A.
lpCenter of face A.
mp1Manifold point 1 (of 2).
mp2Manifold point 2 (of 2).

◆ GetForFaceA() [3/3]

static Manifold playrho::d2::Manifold::GetForFaceA ( const UnitVec normalA,
const Length2 faceA 
)
inlinestaticnoexcept

Gets a face A typed manifold.

Parameters
normalALocal normal of the face from polygon A.
faceAAny point in local coordinates on the face whose normal was provided.

Referenced by playrho::d2::GetManifold().

◆ GetForFaceB() [1/3]

static Manifold playrho::d2::Manifold::GetForFaceB ( const UnitVec ln,
const Length2 lp 
)
inlinestaticnoexcept

Gets a face B typed manifold.

Parameters
lnNormal on polygon B.
lpCenter of face B.

Referenced by playrho::d2::GetManifold().

◆ GetForFaceB() [2/3]

static Manifold playrho::d2::Manifold::GetForFaceB ( const UnitVec ln,
const Length2 lp,
const Point mp1 
)
inlinestaticnoexcept

Gets a face B typed manifold.

Parameters
lnNormal on polygon B.
lpCenter of face B.
mp1Manifold point 1.

◆ GetForFaceB() [3/3]

static Manifold playrho::d2::Manifold::GetForFaceB ( const UnitVec ln,
const Length2 lp,
const Point mp1,
const Point mp2 
)
inlinestaticnoexcept

Gets a face B typed manifold.

Parameters
lnNormal on polygon B.
lpCenter of face B.
mp1Manifold point 1 (of 2).
mp2Manifold point 2 (of 2).

◆ GetImpulses()

constexpr Momentum2 playrho::d2::Manifold::GetImpulses ( size_type  index) const
inlineconstexprnoexcept

Gets the impulses for the given index.

Precondition
index is less than GetPointCount().
Returns
Pair of impulses where the first impulse is the "normal impulse" and the second impulse is the "tangent impulse".

◆ GetLocalNormal()

constexpr UnitVec playrho::d2::Manifold::GetLocalNormal ( ) const
inlineconstexprnoexcept

Gets the local normal for a face-type manifold.

Note
Only valid for face-A or face-B type manifolds.
Precondition
This is a face manifold, i.e.: GetType() == e_faceA || GetType() == e_faceB.
Returns
Local normal if the manifold type is face A or face B, else invalid value.

Referenced by playrho::d2::GetPSM().

◆ GetLocalPoint()

constexpr Length2 playrho::d2::Manifold::GetLocalPoint ( ) const
inlineconstexprnoexcept

Gets the local point.

This is the: local center of "circle" A for circles-type manifolds; the center of face A for face-A-type manifolds; or the center of face B for face-B-type manifolds.

Note
Only valid for circle, face-A, or face-B type manifolds.
Precondition
This is not an unset manifold, i.e. GetType() != e_unset.
Returns
Local point.

Referenced by playrho::d2::GetPSM().

◆ GetOpposingPoint()

constexpr Length2 playrho::d2::Manifold::GetOpposingPoint ( size_type  index) const
inlineconstexprnoexcept

Gets the opposing point.

Precondition
index is less than GetPointCount().

◆ GetPoint()

const Point& playrho::d2::Manifold::GetPoint ( size_type  index) const
inlinenoexcept

Gets the point identified by the given index.

Precondition
index is less than GetPointCount().

Referenced by playrho::d2::GetPSM().

◆ GetPointCount()

constexpr size_type playrho::d2::Manifold::GetPointCount ( ) const
inlineconstexprnoexcept

Gets the manifold point count.

This is the count of contact points for this manifold. Only up to this many points can be validly accessed using the GetPoint() function.

Note
Non-zero values indicate that the two shapes are touching.
Returns
Value between 0 and MaxManifoldPoints.
See also
MaxManifoldPoints, AddPoint(), GetPoint().

Referenced by GetContactFeature(), GetImpulses(), GetOpposingPoint(), GetPoint(), SetImpulses(), and playrho::GaussSeidel::SolvePositionConstraint().

◆ GetType()

constexpr Type playrho::d2::Manifold::GetType ( ) const
inlineconstexprnoexcept

Gets the type of this manifold.

Note
This must be a constant expression in order to use it in the context of the IsValid specialized template function for it.

Referenced by GetLocalNormal(), GetLocalPoint(), playrho::d2::GetPSM(), and GetWorldManifold().

◆ SetImpulses() [1/2]

void playrho::d2::Manifold::SetImpulses ( size_type  index,
const Momentum2 value 
)
inlinenoexcept

Sets the impulses for the given index.

Sets the contact impulses for the given index where the first impulse is the "normal impulse" and the second impulse is the "tangent impulse".

Precondition
index is less than GetPointCount().

◆ SetImpulses() [2/2]

void playrho::d2::Manifold::SetImpulses ( size_type  index,
Momentum  n,
Momentum  t 
)
inlinenoexcept

Sets the impulses for the given index.

Precondition
index is less than GetPointCount().

Friends And Related Function Documentation

◆ CollideShapes()

Manifold CollideShapes ( const DistanceProxy shapeA,
const Transformation xfA,
const DistanceProxy shapeB,
const Transformation xfB,
const Manifold::Conf conf = GetDefaultManifoldConf() 
)
related

Calculates the relevant collision manifold.

Note
The returned touching state information typically agrees with that returned from the distance-proxy-based TestOverlap function. This is not always the case however especially when the separation or overlap distance is closer to zero.

◆ GetWorldManifold()

WorldManifold GetWorldManifold ( const Manifold manifold,
const Transformation xfA,
Length  radiusA,
const Transformation xfB,
Length  radiusB 
)
related

Gets the world manifold for the given data.

Precondition
The given manifold input has between 0 and 2 points.
Parameters
manifoldManifold to use. Uses the manifold's type, local point, local normal, point-count, and the indexed-points' local point data.
xfATransformation A.
radiusARadius of shape A.
xfBTransformation B.
radiusBRadius of shape B.
Returns
World manifold value for the given inputs which will have the same number of points as the given manifold has. The returned world manifold points will be the mid-points of the manifold intersection.

◆ operator!=()

bool operator!= ( const Manifold lhs,
const Manifold rhs 
)
related

Manifold inequality operator.

Determines whether the two given manifolds are not equal.

◆ operator==()

bool operator== ( const Manifold lhs,
const Manifold rhs 
)
related

Manifold equality operator.

Note
In-so-far as manifold points are concerned, order doesn't matter; only whether the two manifolds have the same point set.

The documentation for this class was generated from the following files: