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

A potential contact between the children of two body associated shapes. More...

#include <playrho/Contact.hpp>

Public Types

using substep_type = TimestepIters
 Substep type.
 

Public Member Functions

constexpr Contact () noexcept=default
 Default constructor.
 
constexpr Contact (const Contactable &a, const Contactable &b) noexcept
 Initializing constructor. More...
 
constexpr void FlagForFiltering () noexcept
 Flags the contact for filtering. More...
 
constexpr void FlagForUpdating () noexcept
 Flags the contact for updating. More...
 
constexpr const ContactableGetContactableA () const noexcept
 Gets contactable A.
 
constexpr const ContactableGetContactableB () const noexcept
 Gets contactable B.
 
constexpr NonNegativeFF< RealGetFriction () const noexcept
 Gets the coefficient of friction. More...
 
constexpr Real GetRestitution () const noexcept
 Gets the restitution.
 
constexpr LinearVelocity GetTangentSpeed () const noexcept
 Gets the desired tangent speed.
 
constexpr std::optional< UnitIntervalFF< Real > > GetToi () const noexcept
 Gets the time of impact (TOI) as a fraction. More...
 
constexpr substep_type GetToiCount () const noexcept
 Gets the time of impact count. More...
 
constexpr bool HasValidToi () const noexcept
 Gets whether a TOI is set. More...
 
constexpr void IncrementToiCount () noexcept
 Increments the TOI count. More...
 
constexpr bool IsDestroyed () const noexcept
 Whether or not this contact was destroyed. More...
 
constexpr bool IsEnabled () const noexcept
 Has this contact been disabled?
 
constexpr bool IsImpenetrable () const noexcept
 Whether or not this contact is "impenetrable". More...
 
constexpr bool IsSensor () const noexcept
 Whether or not this contact is a "sensor". More...
 
constexpr bool IsTouching () const noexcept
 Is this contact touching? More...
 
constexpr bool NeedsFiltering () const noexcept
 Whether or not the contact needs filtering.
 
constexpr bool NeedsUpdating () const noexcept
 Whether or not the contact needs updating.
 
constexpr void SetDestroyed () noexcept
 Sets the destroyed property of this contact. More...
 
constexpr void SetEnabled () noexcept
 Enables this contact. More...
 
constexpr void SetFriction (NonNegative< Real > friction) noexcept
 Sets the friction value for this contact. More...
 
constexpr void SetImpenetrable () noexcept
 Sets the impenetrability of this contact. More...
 
constexpr void SetRestitution (Real restitution) noexcept
 Sets the restitution. More...
 
constexpr void SetSensor () noexcept
 Sets the sensor state of this contact. More...
 
constexpr void SetTangentSpeed (LinearVelocity speed) noexcept
 Sets the desired tangent speed for a conveyor belt behavior. More...
 
constexpr void SetToi (const std::optional< UnitIntervalFF< Real >> &toi) noexcept
 Sets the time of impact (TOI). More...
 
constexpr void SetToiCount (substep_type value) noexcept
 Sets the TOI count to the given value. More...
 
constexpr void SetTouching () noexcept
 Sets the touching flag state. More...
 
constexpr void UnflagForFiltering () noexcept
 Unflags this contact for filtering. More...
 
constexpr void UnflagForUpdating () noexcept
 Unflags this contact for updating. More...
 
constexpr void UnsetDestroyed () noexcept
 Unsets the destroyed property of this contact. More...
 
constexpr void UnsetEnabled () noexcept
 Disables this contact. More...
 
constexpr void UnsetImpenetrable () noexcept
 Unsets the impenetrability of this contact. More...
 
constexpr void UnsetSensor () noexcept
 Unsets the sensor state of this contact. More...
 
constexpr void UnsetTouching () noexcept
 Unsets the touching flag state. More...
 

Static Public Attributes

static constexpr auto DefaultContactable = Contactable{InvalidBodyID, InvalidShapeID, 0}
 Default contactable value.
 

Related Functions

(Note that these are not member functions.)

constexpr void FlagForFiltering (Contact &contact) noexcept
 Flags the contact for filtering. More...
 
constexpr void FlagForUpdating (Contact &contact) noexcept
 Flags the contact for updating. More...
 
constexpr BodyID GetBodyA (const Contact &contact) noexcept
 Gets the body A ID of the given contact.
 
constexpr BodyID GetBodyB (const Contact &contact) noexcept
 Gets the body B ID of the given contact.
 
constexpr ChildCounter GetChildIndexA (const Contact &contact) noexcept
 Gets the child index A of the given contact.
 
constexpr ChildCounter GetChildIndexB (const Contact &contact) noexcept
 Gets the child index B of the given contact.
 
constexpr auto GetFriction (const Contact &contact) noexcept
 Gets the coefficient of friction. More...
 
constexpr auto GetOtherBody (const Contact &c, BodyID bodyID) noexcept
 Gets the other body ID for the contact than the one given.
 
constexpr auto GetRestitution (const Contact &contact) noexcept
 Gets the coefficient of restitution. More...
 
constexpr ShapeID GetShapeA (const Contact &contact) noexcept
 Gets the shape A associated with the given contact.
 
constexpr ShapeID GetShapeB (const Contact &contact) noexcept
 Gets the shape B associated with the given contact.
 
constexpr auto GetTangentSpeed (const Contact &contact) noexcept
 Gets the desired tangent speed. More...
 
constexpr auto GetToi (const Contact &contact) noexcept
 Gets the time of impact (TOI) as a fraction. More...
 
constexpr auto GetToiCount (const Contact &contact) noexcept
 Gets the time of impact count. More...
 
WorldManifold GetWorldManifold (const World &world, const Contact &contact, const Manifold &manifold)
 
constexpr auto HasValidToi (const Contact &contact) noexcept
 Gets whether a TOI is set. More...
 
constexpr auto IsDestroyed (const Contact &c) noexcept -> bool
 Whether or not the given contact was destroyed. More...
 
constexpr bool IsEnabled (const Contact &contact) noexcept
 Gets whether the given contact is enabled or not.
 
constexpr bool IsFor (const Contact &c, BodyID bodyID, ShapeID shapeID) noexcept
 Is-for convenience function. More...
 
constexpr bool IsFor (const Contact &c, ShapeID shapeID) noexcept
 Is-for convenience function. More...
 
constexpr bool IsImpenetrable (const Contact &contact) noexcept
 Whether the given contact is "impenetrable". More...
 
constexpr bool IsSensor (const Contact &contact) noexcept
 Gets whether the given contact is for sensors or not.
 
constexpr bool IsTouching (const Contact &contact) noexcept
 Gets whether the given contact is touching or not.
 
constexpr auto NeedsFiltering (const Contact &contact) noexcept
 Whether or not the contact needs filtering.
 
constexpr auto NeedsUpdating (const Contact &contact) noexcept
 Whether or not the contact needs updating.
 
constexpr bool operator!= (const Contact &lhs, const Contact &rhs) noexcept
 Operator not-equals.
 
constexpr bool operator== (const Contact &lhs, const Contact &rhs) noexcept
 Operator equals.
 
constexpr void SetDestroyed (Contact &c) noexcept
 Sets the destroyed property of the given contact. More...
 
constexpr void SetEnabled (Contact &contact) noexcept
 Enables the contact. More...
 
constexpr void SetFriction (Contact &contact, NonNegative< Real > value) noexcept
 Sets the friction value for the identified contact. More...
 
constexpr void SetImpenetrable (Contact &contact) noexcept
 Sets the impenetrability of the given contact. More...
 
constexpr void SetRestitution (Contact &contact, Real value)
 Sets the restitution value for the identified contact. More...
 
constexpr void SetSensor (Contact &contact) noexcept
 Sets the sensor state of the given contact. More...
 
constexpr void SetTangentSpeed (Contact &contact, LinearVelocity value) noexcept
 Sets the desired tangent speed for a conveyor belt behavior. More...
 
constexpr void SetToi (Contact &contact, const std::optional< UnitIntervalFF< Real >> &toi) noexcept
 Sets the time of impact (TOI). More...
 
constexpr void SetToiCount (Contact &contact, Contact::substep_type value) noexcept
 Sets the TOI count to the given value. More...
 
constexpr void UnflagForFiltering (Contact &contact) noexcept
 Unflags this contact for filtering. More...
 
constexpr void UnflagForUpdating (Contact &contact) noexcept
 Unflags this contact for updating. More...
 
constexpr void UnsetDestroyed (Contact &c) noexcept
 Unsets the destroyed property of the given contact. More...
 
constexpr void UnsetImpenetrable (Contact &contact) noexcept
 Unsets the impenetrability of the given contact. More...
 
constexpr void UnsetSensor (Contact &contact) noexcept
 Unsets the sensor state of the given contact. More...
 

Detailed Description

A potential contact between the children of two body associated shapes.

The class manages contact between two shapes. A contact exists for each overlapping AABB in the broad-phase (except if filtered). Therefore a contact object may exist that has no actual contact points.

Constructor & Destructor Documentation

◆ Contact()

constexpr playrho::Contact::Contact ( const Contactable a,
const Contactable b 
)
constexprnoexcept

Initializing constructor.

Parameters
aThe "a" contactable value.
bThe "b" contactable value.
Postcondition
If either a or b is not the value of DefaultContactable then: IsEnabled() and NeedsUpdating() return true, else they return false.

Member Function Documentation

◆ FlagForFiltering()

constexpr void playrho::Contact::FlagForFiltering ( )
constexprnoexcept

Flags the contact for filtering.

Postcondition
NeedsFiltering() returns true.
See also
NeedsFiltering.

◆ FlagForUpdating()

constexpr void playrho::Contact::FlagForUpdating ( )
constexprnoexcept

Flags the contact for updating.

Postcondition
NeedsUpdating() returns true.
See also
NeedsUpdating.

◆ GetFriction()

constexpr NonNegativeFF< Real > playrho::Contact::GetFriction ( ) const
constexprnoexcept

Gets the coefficient of friction.

Gets combined friction of two shapes associated with this.

See also
SetFriction.

◆ GetToi()

constexpr std::optional< UnitIntervalFF< Real > > playrho::Contact::GetToi ( ) const
constexprnoexcept

Gets the time of impact (TOI) as a fraction.

Note
This is a non-essential part - it doesn't participate in equality.
Returns
Time of impact fraction in the range of 0 to 1 if set (where 1 means no actual impact in current time slot), otherwise empty.
See also
SetToi(const std::optional<UnitIntervalFF<Real>>&).

◆ GetToiCount()

constexpr Contact::substep_type playrho::Contact::GetToiCount ( ) const
constexprnoexcept

Gets the time of impact count.

Note
This is a non-essential part - it doesn't participate in equality.
See also
SetToiCount.

◆ HasValidToi()

constexpr bool playrho::Contact::HasValidToi ( ) const
constexprnoexcept

Gets whether a TOI is set.

Note
This is a non-essential part - it doesn't participate in equality.
Returns
true if this object has a TOI set for it, false otherwise.

Referenced by GetToi().

◆ IncrementToiCount()

constexpr void playrho::Contact::IncrementToiCount ( )
constexprnoexcept

Increments the TOI count.

Precondition
GetToiCount() is less than numeric_limits<substep_type>::max().
Postcondition
GetToiCount() returns one more than before.
See also
GetToiCount, SetToiCount.

◆ IsDestroyed()

constexpr bool playrho::Contact::IsDestroyed ( ) const
constexprnoexcept

Whether or not this contact was destroyed.

See also
SetDestroyed, UnsetDestroyed.

◆ IsImpenetrable()

constexpr bool playrho::Contact::IsImpenetrable ( ) const
constexprnoexcept

Whether or not this contact is "impenetrable".

Note
This should be true whenever body A or body B are impenetrable.

◆ IsSensor()

constexpr bool playrho::Contact::IsSensor ( ) const
constexprnoexcept

Whether or not this contact is a "sensor".

Note
This should be true whenever shape A or shape B is a sensor.

◆ IsTouching()

constexpr bool playrho::Contact::IsTouching ( ) const
constexprnoexcept

Is this contact touching?

Touching is defined as either:

  1. This contact's manifold has more than 0 contact points, or
  2. This contact has sensors and the two shapes of this contact are found to be overlapping.
    Returns
    true if this contact is said to be touching, false otherwise.

◆ SetDestroyed()

constexpr void playrho::Contact::SetDestroyed ( )
constexprnoexcept

Sets the destroyed property of this contact.

Note
This is only meaningfully used by the world implementation.

◆ SetEnabled()

constexpr void playrho::Contact::SetEnabled ( )
constexprnoexcept

Enables this contact.

Postcondition
IsEnabled() returns true.
See also
IsEnabled.

◆ SetFriction()

constexpr void playrho::Contact::SetFriction ( NonNegative< Real friction)
constexprnoexcept

Sets the friction value for this contact.

Override the default friction mixture.

Note
You can call this in "pre-solve" listeners.
This value persists until set or reset.
Parameters
frictionCo-efficient of friction value of zero or greater.
Postcondition
GetFriction() returns the value set.
See also
GetFriction.

◆ SetImpenetrable()

constexpr void playrho::Contact::SetImpenetrable ( )
constexprnoexcept

Sets the impenetrability of this contact.

Attention
Call this if body A or body B are impenetrable.
Postcondition
IsImpenetrable() returns true.
See also
IsImpenetrable().

◆ SetRestitution()

constexpr void playrho::Contact::SetRestitution ( Real  restitution)
constexprnoexcept

Sets the restitution.

This override the default restitution mixture.

Note
You can call this in "pre-solve" listeners.
The value persists until you set or reset.
Postcondition
GetRestitution() returns the value set.
See also
GetRestitution.

Referenced by SetRestitution().

◆ SetSensor()

constexpr void playrho::Contact::SetSensor ( )
constexprnoexcept

Sets the sensor state of this contact.

Attention
Call this if shape A or shape B is a sensor.
Postcondition
IsSensor() returns true.
See also
IsSensor().

◆ SetTangentSpeed()

constexpr void playrho::Contact::SetTangentSpeed ( LinearVelocity  speed)
constexprnoexcept

Sets the desired tangent speed for a conveyor belt behavior.

Postcondition
GetTangentSpeed() returns the value set.
See also
GetTangentSpeed.

◆ SetToi()

constexpr void playrho::Contact::SetToi ( const std::optional< UnitIntervalFF< Real >> &  toi)
constexprnoexcept

Sets the time of impact (TOI).

Note
This is a non-essential part. So changing this doesn't effect equality!
Parameters
toiTime of impact as a fraction between 0 and 1 where 1 indicates no actual impact in the current time slot, or empty.
Postcondition
GetToi() returns the value set and HasValidToi() returns toi.has_value().
See also
Real GetToi() const, HasValidToi.

◆ SetToiCount()

constexpr void playrho::Contact::SetToiCount ( substep_type  value)
constexprnoexcept

Sets the TOI count to the given value.

Note
This is a non-essential part. So changing this doesn't effect equality!
Postcondition
GetToiCount() returns the value set.
See also
GetToiCount.

◆ SetTouching()

constexpr void playrho::Contact::SetTouching ( )
constexprnoexcept

Sets the touching flag state.

Note
This should only be called if either:
  1. The contact's manifold has more than 0 contact points, or
  2. The contact has sensors and the two shapes of this contact are found to be overlapping.
Postcondition
IsTouching() returns true.
See also
IsTouching().

◆ UnflagForFiltering()

constexpr void playrho::Contact::UnflagForFiltering ( )
constexprnoexcept

Unflags this contact for filtering.

Postcondition
NeedsFiltering() returns false.
See also
NeedsFiltering.

◆ UnflagForUpdating()

constexpr void playrho::Contact::UnflagForUpdating ( )
constexprnoexcept

Unflags this contact for updating.

Postcondition
NeedsUpdating() returns false.
See also
NeedsUpdating.

◆ UnsetDestroyed()

constexpr void playrho::Contact::UnsetDestroyed ( )
constexprnoexcept

Unsets the destroyed property of this contact.

Note
This is only meaningfully used by the world implementation.

◆ UnsetEnabled()

constexpr void playrho::Contact::UnsetEnabled ( )
constexprnoexcept

Disables this contact.

Postcondition
IsEnabled() returns false.
See also
IsEnabled.

◆ UnsetImpenetrable()

constexpr void playrho::Contact::UnsetImpenetrable ( )
constexprnoexcept

Unsets the impenetrability of this contact.

Postcondition
IsImpenetrable() returns false.
See also
IsImpenetrable().

◆ UnsetSensor()

constexpr void playrho::Contact::UnsetSensor ( )
constexprnoexcept

Unsets the sensor state of this contact.

Postcondition
IsSensor() returns false.
See also
IsSensor().

◆ UnsetTouching()

constexpr void playrho::Contact::UnsetTouching ( )
constexprnoexcept

Unsets the touching flag state.

Postcondition
IsTouching() returns false.
See also
IsTouching().

Friends And Related Function Documentation

◆ FlagForFiltering()

constexpr void FlagForFiltering ( Contact contact)
related

Flags the contact for filtering.

Postcondition
NeedsFiltering(contact) returns true.
See also
NeedsFiltering(const Contact &).

◆ FlagForUpdating()

constexpr void FlagForUpdating ( Contact contact)
related

Flags the contact for updating.

Postcondition
NeedsUpdating(contact) returns true.
See also
NeedsUpdating(const Contact &).

◆ GetFriction()

constexpr auto GetFriction ( const Contact contact)
related

Gets the coefficient of friction.

See also
SetFriction.

◆ GetRestitution()

constexpr auto GetRestitution ( const Contact contact)
related

Gets the coefficient of restitution.

See also
SetRestitution.

◆ GetTangentSpeed()

constexpr auto GetTangentSpeed ( const Contact contact)
related

Gets the desired tangent speed.

See also
SetTangentSpeed.

◆ GetToi()

constexpr auto GetToi ( const Contact contact)
related

Gets the time of impact (TOI) as a fraction.

Returns
Time of impact fraction in the range of 0 to 1 if set (where 1 means no actual impact in current time slot), otherwise empty.
See also
HasValidToi, SetToi(Contact&, const std::optional<UnitIntervalFF<Real>>&).

◆ GetToiCount()

constexpr auto GetToiCount ( const Contact contact)
related

Gets the time of impact count.

See also
SetToiCount.

◆ GetWorldManifold()

WorldManifold GetWorldManifold ( const World &  world,
const Contact contact,
const Manifold &  manifold 
)
related

Gets the world manifold for the given data.

Note
This is a convenience function that in turn calls the GetWorldManifold(const Manifold&, const Transformation&, const Real, const Transformation& xfB, const Real) function.
Parameters
worldWorld that the result is to be relative to.
contactContact to return a world manifold for.
manifoldThe manifold to covert to a world manifold.
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 contact's intersection.

◆ HasValidToi()

constexpr auto HasValidToi ( const Contact contact)
related

Gets whether a TOI is set.

See also
GetToi.

◆ IsDestroyed()

constexpr auto IsDestroyed ( const Contact c) -> bool
related

Whether or not the given contact was destroyed.

See also
SetDestroyed, UnsetDestroyed.

◆ IsFor() [1/2]

constexpr bool IsFor ( const Contact c,
BodyID  bodyID,
ShapeID  shapeID 
)
related

Is-for convenience function.

Returns
true if contact is for the identified body and shape, else false.

◆ IsFor() [2/2]

constexpr bool IsFor ( const Contact c,
ShapeID  shapeID 
)
related

Is-for convenience function.

Returns
true if contact is for the identified shape, else false.

◆ IsImpenetrable()

constexpr bool IsImpenetrable ( const Contact contact)
related

Whether the given contact is "impenetrable".

Note
This should be true whenever body A or body B are impenetrable.

◆ SetDestroyed()

constexpr void SetDestroyed ( Contact c)
related

Sets the destroyed property of the given contact.

Note
This is only meaningfully used by the world implementation.

◆ SetEnabled()

constexpr void SetEnabled ( Contact contact)
related

Enables the contact.

Postcondition
IsEnabled(contact) returns true.
See also
IsEnabled(const Contact &).

◆ SetFriction()

constexpr void SetFriction ( Contact contact,
NonNegative< Real value 
)
related

Sets the friction value for the identified contact.

Overrides the default friction mixture.

Note
This value persists until set or reset.
Parameters
contactThe contact whose friction should be set.
valueCo-efficient of friction value of zero or greater.
Precondition
friction must be greater-than or equal-to zero.
Postcondition
GetFriction(contact) returns the value set.
See also
GetFriction.

◆ SetImpenetrable()

constexpr void SetImpenetrable ( Contact contact)
related

Sets the impenetrability of the given contact.

Attention
Call this if body A or body B are impenetrable.
Postcondition
IsImpenetrable(contact) returns true.
See also
IsImpenetrable(const Contact &).

◆ SetRestitution()

constexpr void SetRestitution ( Contact contact,
Real  value 
)
related

Sets the restitution value for the identified contact.

This override the default restitution mixture.

Note
You can call this in "pre-solve" listeners.
The value persists until you set or reset.
Postcondition
GetRestitution(contact) returns the value set.
See also
GetRestitution.

◆ SetSensor()

constexpr void SetSensor ( Contact contact)
related

Sets the sensor state of the given contact.

Attention
Call this if shape A or shape B is a sensor.
Postcondition
IsSensor(contact) returns true.
See also
IsSensor(const Contact &).

◆ SetTangentSpeed()

constexpr void SetTangentSpeed ( Contact contact,
LinearVelocity  value 
)
related

Sets the desired tangent speed for a conveyor belt behavior.

Postcondition
GetTangentSpeed(contact) returns the value set.
See also
GetTangentSpeed.

◆ SetToi()

constexpr void SetToi ( Contact contact,
const std::optional< UnitIntervalFF< Real >> &  toi 
)
related

Sets the time of impact (TOI).

Parameters
contactThe contact to update.
toiOptional time of impact as a fraction between 0 and 1 where 1 indicates no actual impact in the current time slot.
Postcondition
HasValidToi(contact) returns toi.has_value().
GetToi(const Contact&) returns the value set.
See also
HasValidToi, GetToi.

◆ SetToiCount()

constexpr void SetToiCount ( Contact contact,
Contact::substep_type  value 
)
related

Sets the TOI count to the given value.

Postcondition
GetToiCount(contact) returns value.
See also
GetToiCount.

◆ UnflagForFiltering()

constexpr void UnflagForFiltering ( Contact contact)
related

Unflags this contact for filtering.

Postcondition
NeedsFiltering(contact) returns false.
See also
NeedsFiltering(const Contact &).

◆ UnflagForUpdating()

constexpr void UnflagForUpdating ( Contact contact)
related

Unflags this contact for updating.

Postcondition
NeedsUpdating(contact) returns false.
See also
NeedsUpdating(const Contact &).

◆ UnsetDestroyed()

constexpr void UnsetDestroyed ( Contact c)
related

Unsets the destroyed property of the given contact.

Note
This is only meaningfully used by the world implementation.

◆ UnsetImpenetrable()

constexpr void UnsetImpenetrable ( Contact contact)
related

Unsets the impenetrability of the given contact.

Attention
Call this if body A or body B are no longer impenetrable.
Postcondition
IsImpenetrable(contact) returns false.
See also
IsImpenetrable(const Contact &).

◆ UnsetSensor()

constexpr void UnsetSensor ( Contact contact)
related

Unsets the sensor state of the given contact.

Postcondition
IsSensor(contact) returns false.
See also
IsSensor(const Contact &).

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