PlayRho  1.1.0
An Interactive Real-Time-Oriented C++ Physics Engine & Library
playrho::d2::Manifold Class Reference

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

#include <Manifold.hpp>

Collaboration diagram for playrho::d2::Manifold:
[legend]

Classes

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

Public Types

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

Public Member Functions

 Manifold ()=default
 Default constructor. More...
 
 Manifold (const Manifold &copy)=default
 Copy constructor.
 
constexpr Type GetType () const noexcept
 Gets the type of this manifold. More...
 
constexpr size_type GetPointCount () const noexcept
 Gets the manifold point count. More...
 
constexpr ContactFeature GetContactFeature (size_type index) const noexcept
 Gets the contact feature for the given index.
 
constexpr Momentum2 GetContactImpulses (size_type index) const noexcept
 Gets the contact impulses for the given index. More...
 
void SetContactImpulses (size_type index, Momentum2 value) noexcept
 Sets the contact impulses for the given index. More...
 
const PointGetPoint (size_type index) const noexcept
 Gets the point identified by the given index.
 
void SetPointImpulses (size_type index, Momentum n, Momentum t)
 Sets the point impulses for the given index.
 
void AddPoint (const Point &mp) noexcept
 Adds a new point. More...
 
void AddPoint (CfType type, CfIndex index, Length2 point) noexcept
 Adds a new point with the given data.
 
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.
 

Static Public Member Functions

static Manifold GetForCircles (Length2 vA, CfIndex iA, Length2 vB, CfIndex iB) noexcept
 Gets a circles-typed manifold with one point. More...
 
static Manifold GetForFaceA (UnitVec normalA, Length2 faceA) noexcept
 Gets a face A typed manifold. More...
 
static Manifold GetForFaceA (UnitVec ln, Length2 lp, const Point &mp1) noexcept
 Gets a face A typed manifold. More...
 
static Manifold GetForFaceA (UnitVec ln, Length2 lp, const Point &mp1, const Point &mp2) noexcept
 Gets a face A typed manifold. More...
 
static Manifold GetForFaceB (UnitVec ln, Length2 lp) noexcept
 Gets a face B typed manifold. More...
 
static Manifold GetForFaceB (UnitVec ln, Length2 lp, const Point &mp1) noexcept
 Gets a face B typed manifold. More...
 
static Manifold GetForFaceB (UnitVec ln, Length2 lp, const Point &mp1, const Point &mp2) noexcept
 Gets a face B typed manifold. More...
 
static Manifold GetForFaceA (UnitVec na, CfIndex ia, Length2 pa) noexcept
 Gets the face A manifold for the given data.
 
static Manifold GetForFaceB (UnitVec nb, CfIndex ib, Length2 pb) noexcept
 Gets the face B manifold for the given data.
 
static Manifold GetForFaceA (UnitVec na, CfIndex ia, Length2 pa, CfType tb0, CfIndex ib0, Length2 pb0) noexcept
 Gets the face A manifold for the given data.
 
static Manifold GetForFaceB (UnitVec nb, CfIndex ib, Length2 pb, CfType ta0, CfIndex ia0, Length2 pa0) noexcept
 Gets the face B manifold for the given data.
 
static Manifold GetForFaceA (UnitVec na, CfIndex ia, Length2 pa, CfType tb0, CfIndex ib0, Length2 pb0, CfType tb1, CfIndex ib1, Length2 pb1) noexcept
 Gets the face A manifold for the given data.
 
static Manifold GetForFaceB (UnitVec nb, CfIndex ib, Length2 pb, CfType ta0, CfIndex ia0, Length2 pa0, CfType ta1, CfIndex ia1, Length2 pa1) noexcept
 Gets the face B manifold for the given data.
 

Private Member Functions

constexpr Manifold (Type t, UnitVec ln, Length2 lp, size_type n, const PointArray &mpa) noexcept
 Constructs manifold with array of points using the given values. More...
 

Private Attributes

Type m_type = e_unset
 Type of collision this manifold is associated with (1-byte).
 
size_type m_pointCount = 0
 Number of defined manifold points (1-byte).
 
UnitVec m_localNormal = GetInvalid<decltype(m_localNormal)>()
 Local normal. More...
 
Length2 m_localPoint = GetInvalid<Length2>()
 Local point. More...
 
PointArray m_points
 Points of contact (at least 40-bytes). More...
 

Related Functions

(Note that these are not member functions.)

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

Member Enumeration Documentation

◆ Type

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

Manifold type.

Note
This is by design a 1-byte sized type.
Enumerator
e_unset 

Unset type.

Manifold is unset. For manifolds of this type: the point count is zero, point data is undefined, 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() [1/2]

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

Default constructor.

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

◆ Manifold() [2/2]

constexpr playrho::d2::Manifold::Manifold ( Type  t,
UnitVec  ln,
Length2  lp,
size_type  n,
const PointArray mpa 
)
constexprprivatenoexcept

Constructs manifold with array of points using the given values.

Parameters
tManifold type.
lnLocal normal.
lpLocal point.
nnumber of points defined in array.
mpaManifold point array.

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.

Warning
Behavior is undefined if this object's type is e_unset.
Behavior is undefined if this is called more than twice.

◆ GetContactImpulses()

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

Gets the contact impulses for the given index.

Returns
Pair of impulses where the first impulse is the "normal impulse" and the second impulse is the "tangent impulse".

◆ GetForCircles()

static Manifold playrho::d2::Manifold::GetForCircles ( Length2  vA,
CfIndex  iA,
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 ( UnitVec  ln,
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 ( UnitVec  ln,
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 ( UnitVec  normalA,
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 ( UnitVec  ln,
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 ( UnitVec  ln,
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 ( UnitVec  ln,
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).

◆ 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.
Warning
Behavior is undefined for unset (e_unset) type manifolds.
Behavior is undefined for circles (e_circles) type manifolds.
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.
Warning
Behavior is undefined for unset (e_unset) type manifolds.
Returns
Local point.
Examples
World.cpp.

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() method.

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

◆ 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.
Examples
World.cpp.

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

◆ SetContactImpulses()

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

Sets the contact 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".

Friends And Related Function Documentation

◆ CollideShapes()

Manifold CollideShapes ( const DistanceProxy shapeA,
const Transformation xfA,
const DistanceProxy shapeB,
const Transformation xfB,
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,
Transformation  xfA,
Length  radiusA,
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.

Member Data Documentation

◆ m_localNormal

UnitVec playrho::d2::Manifold::m_localNormal = GetInvalid<decltype(m_localNormal)>()
private

Local normal.

Exact usage depends on manifold type (8-bytes).

Note
Invalid for the unset and circle manifold types.

Referenced by GetLocalNormal().

◆ m_localPoint

Length2 playrho::d2::Manifold::m_localPoint = GetInvalid<Length2>()
private

Local point.

Exact usage depends on manifold type (8-bytes).

Note
Invalid for the unset manifold type.

Referenced by GetLocalPoint().

◆ m_points

PointArray playrho::d2::Manifold::m_points
private

Points of contact (at least 40-bytes).

See also
pointCount.

Referenced by GetContactFeature(), GetContactImpulses(), GetOpposingPoint(), GetPoint(), SetContactImpulses(), and SetPointImpulses().


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