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

A potential contact between the children of two Fixture objects. More...

#include <Contact.hpp>

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

Public Types

enum  : FlagsType {
  e_touchingFlag = 0x01, e_enabledFlag = 0x02, e_filterFlag = 0x04, e_toiFlag = 0x08,
  e_dirtyFlag = 0x10, e_sensorFlag = 0x20, e_activeFlag = 0x40, e_impenetrableFlag = 0x80
}
 Flags stored in m_flags. More...
 
using substep_type = TimestepIters
 Substep type.
 
using FlagsType = std::uint8_t
 Flags type data type.
 

Public Member Functions

 Contact () noexcept=default
 Default construction not allowed.
 
 Contact (BodyID bA, FixtureID fA, ChildCounter iA, BodyID bB, FixtureID fB, ChildCounter iB) noexcept
 Initializing constructor. More...
 
bool IsTouching () const noexcept
 Is this contact touching? More...
 
void SetTouching () noexcept
 Sets the touching flag state. More...
 
void UnsetTouching () noexcept
 Unsets the touching flag state.
 
void SetEnabled (bool flag) noexcept
 Enables or disables this contact. More...
 
bool IsEnabled () const noexcept
 Has this contact been disabled?
 
void SetEnabled () noexcept
 Enables this contact.
 
void UnsetEnabled () noexcept
 Disables this contact.
 
BodyID GetBodyA () const noexcept
 Gets the body-A identifier.
 
FixtureID GetFixtureA () const noexcept
 Gets fixture A in this contact.
 
ChildCounter GetChildIndexA () const noexcept
 Get the child primitive index for fixture A.
 
BodyID GetBodyB () const noexcept
 Gets the body-B identifier.
 
FixtureID GetFixtureB () const noexcept
 Gets fixture B in this contact.
 
ChildCounter GetChildIndexB () const noexcept
 Get the child primitive index for fixture B.
 
void SetFriction (Real friction) noexcept
 Sets the friction value for this contact. More...
 
Real GetFriction () const noexcept
 Gets the coefficient of friction. More...
 
void SetRestitution (Real restitution) noexcept
 Sets the restitution. More...
 
Real GetRestitution () const noexcept
 Gets the restitution.
 
void SetTangentSpeed (LinearVelocity speed) noexcept
 Sets the desired tangent speed for a conveyor belt behavior.
 
LinearVelocity GetTangentSpeed () const noexcept
 Gets the desired tangent speed.
 
substep_type GetToiCount () const noexcept
 Gets the time of impact count.
 
bool HasValidToi () const noexcept
 Gets whether a TOI is set. More...
 
Real GetToi () const
 Gets the time of impact (TOI) as a fraction. More...
 
void FlagForFiltering () noexcept
 Flags the contact for filtering.
 
bool NeedsFiltering () const noexcept
 Whether or not the contact needs filtering.
 
void FlagForUpdating () noexcept
 Flags the contact for updating.
 
bool NeedsUpdating () const noexcept
 Whether or not the contact needs updating.
 
bool IsSensor () const noexcept
 Whether or not this contact is a "sensor". More...
 
void SetIsSensor () noexcept
 Sets the sensor state of this contact. More...
 
void UnsetIsSensor () noexcept
 Unsets the sensor state of this contact.
 
bool IsImpenetrable () const noexcept
 Whether or not this contact is "impenetrable". More...
 
void SetImpenetrable () noexcept
 Sets the impenetrability of this contact. More...
 
void UnsetImpenetrable () noexcept
 Unsets the impenetrability of this contact.
 
bool IsActive () const noexcept
 Whether or not this contact is "active". More...
 
void SetIsActive () noexcept
 Sets the active state of this contact. More...
 
void UnsetIsActive () noexcept
 Unsets the active state of this contact. More...
 
void UnflagForFiltering () noexcept
 Flags this contact for filtering. More...
 
void UnflagForUpdating () noexcept
 Unflags this contact for updating.
 
void SetToi (Real toi) noexcept
 Sets the time of impact (TOI). More...
 
void UnsetToi () noexcept
 Unsets the TOI.
 
void SetToiCount (substep_type value) noexcept
 Sets the TOI count to the given value.
 
void IncrementToiCount () noexcept
 Increments the TOI count.
 

Private Attributes

BodyID m_bodyA = InvalidBodyID
 Identifier of body A. More...
 
BodyID m_bodyB = InvalidBodyID
 Identifier of body B. More...
 
FixtureID m_fixtureA = InvalidFixtureID
 Identifier of fixture A. More...
 
FixtureID m_fixtureB = InvalidFixtureID
 Identifier of fixture B. More...
 
ChildCounter m_indexA
 Index A. 4-bytes.
 
ChildCounter m_indexB
 Index B. 4-bytes.
 
Real m_friction = 0
 Mix of frictions of associated fixtures. More...
 
Real m_restitution = 0
 Mix of restitutions of associated fixtures. More...
 
LinearVelocity m_tangentSpeed = 0
 Tangent speed. More...
 
Real m_toi = 0
 Time of impact. More...
 
substep_type m_toiCount = 0
 Count of TOI calculations contact has gone through since last reset.
 
FlagsType m_flags = e_enabledFlag | e_dirtyFlag
 Flags.
 

Related Functions

(Note that these are not member functions.)

AABB ComputeIntersectingAABB (const World &world, const Contact &contact)
 Computes the intersecting AABB for the given contact.
 
WorldManifold GetWorldManifold (const World &world, const Contact &contact, const Manifold &manifold)
 Gets the world manifold for the given data. More...
 
BodyID GetBodyA (const Contact &contact) noexcept
 Gets the body A ID of the given contact.
 
BodyID GetBodyB (const Contact &contact) noexcept
 Gets the body B ID of the given contact.
 
FixtureID GetFixtureA (const Contact &contact) noexcept
 Gets the fixture A associated with the given contact.
 
FixtureID GetFixtureB (const Contact &contact) noexcept
 Gets the fixture B associated with the given contact.
 
ChildCounter GetChildIndexA (const Contact &contact) noexcept
 Gets the child index A of the given contact.
 
ChildCounter GetChildIndexB (const Contact &contact) noexcept
 Gets the child index B of the given contact.
 
bool IsImpenetrable (const Contact &contact) noexcept
 Whether the given contact is "impenetrable".
 
bool IsActive (const Contact &contact) noexcept
 Determines whether the given contact is "active".
 
bool IsEnabled (const Contact &contact) noexcept
 Gets whether the given contact is enabled or not.
 
bool IsTouching (const Contact &contact) noexcept
 Gets whether the given contact is touching or not.
 
bool IsSensor (const Contact &contact) noexcept
 Gets whether the given contact is for sensors or not.
 
auto GetToiCount (const Contact &contact) noexcept
 Gets the time of impact count.
 
auto NeedsFiltering (const Contact &contact) noexcept
 Whether or not the contact needs filtering.
 
auto NeedsUpdating (const Contact &contact) noexcept
 Whether or not the contact needs updating.
 
auto HasValidToi (const Contact &contact) noexcept
 Gets whether a TOI is set. More...
 
Real GetToi (const Contact &contact) noexcept
 Gets the time of impact (TOI) as a fraction. More...
 
auto GetFriction (const Contact &contact) noexcept
 Gets the coefficient of friction. More...
 
void SetFriction (Contact &contact, Real value) noexcept
 Sets the friction value for the identified contact. More...
 
auto GetRestitution (const Contact &contact) noexcept
 Gets the coefficient of restitution. More...
 
void SetRestitution (Contact &contact, Real value)
 Sets the restitution value for the identified contact. More...
 
auto GetTangentSpeed (const Contact &contact) noexcept
 Gets the desired tangent speed. More...
 
void SetTangentSpeed (Contact &contact, LinearVelocity value) noexcept
 Sets the desired tangent speed for a conveyor belt behavior. More...
 

Detailed Description

A potential contact between the children of two Fixture objects.

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.

Examples
World.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum : FlagsType

Flags stored in m_flags.

Enumerator
e_sensorFlag 

Indicates whether the contact is to be treated as a sensor or not.

e_activeFlag 

Indicates whether the contact is to be treated as active or not.

e_impenetrableFlag 

Indicates whether the contact is to be treated as between impenetrable bodies.

Constructor & Destructor Documentation

◆ Contact()

playrho::d2::Contact::Contact ( BodyID  bA,
FixtureID  fA,
ChildCounter  iA,
BodyID  bB,
FixtureID  fB,
ChildCounter  iB 
)
noexcept

Initializing constructor.

Parameters
bAIdentifier of body-A.
fANon-invalid identifier to fixture A that must have a shape and may not be the same or have the same body as the other fixture.
iAChild index A.
bBIdentifier of body-B.
fBNon-invalid identifier to fixture B that must have a shape and may not be the same or have the same body as the other fixture.
iBChild index B.
Note
This need never be called directly by a user.
Warning
Behavior is undefined if fA is null.
Behavior is undefined if fB is null.
Behavior is undefined if fA == fB.
Behavior is undefined if both fixture's have the same body.

Member Function Documentation

◆ GetFriction()

Real playrho::d2::Contact::GetFriction ( ) const
inlinenoexcept

Gets the coefficient of friction.

Gets the combined friction of the two fixtures associated with this contact.

Returns
Value of 0 or higher.
See also
SetFriction.

◆ GetToi()

Real playrho::d2::Contact::GetToi ( ) const
inline

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

Note
This is only valid if a TOI has been set.
See also
void SetToi(Real toi).
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 undefined.

◆ HasValidToi()

bool playrho::d2::Contact::HasValidToi ( ) const
inlinenoexcept

Gets whether a TOI is set.

Returns
true if this object has a TOI set for it, false otherwise.

Referenced by GetToi().

◆ IsActive()

bool playrho::d2::Contact::IsActive ( ) const
inlinenoexcept

Whether or not this contact is "active".

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

◆ IsImpenetrable()

bool playrho::d2::Contact::IsImpenetrable ( ) const
inlinenoexcept

Whether or not this contact is "impenetrable".

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

◆ IsSensor()

bool playrho::d2::Contact::IsSensor ( ) const
inlinenoexcept

Whether or not this contact is a "sensor".

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

◆ IsTouching()

bool playrho::d2::Contact::IsTouching ( ) const
inlinenoexcept

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.

◆ SetEnabled()

void playrho::d2::Contact::SetEnabled ( bool  flag)
inlinenoexcept

Enables or disables this contact.

Note
This can be used inside the pre-solve contact listener. The contact is only disabled for the current time step (or sub-step in continuous collisions).

◆ SetFriction()

void playrho::d2::Contact::SetFriction ( Real  friction)
inlinenoexcept

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.
Warning
Behavior is undefined if given a negative friction value.
Parameters
frictionCo-efficient of friction value of zero or greater.
See also
GetFriction.

◆ SetImpenetrable()

void playrho::d2::Contact::SetImpenetrable ( )
inlinenoexcept

Sets the impenetrability of this contact.

Attention
Call this if body A or body B are impenetrable.

◆ SetIsActive()

void playrho::d2::Contact::SetIsActive ( )
inlinenoexcept

Sets the active state of this contact.

Attention
Call this if body A or body B are "awake".

◆ SetIsSensor()

void playrho::d2::Contact::SetIsSensor ( )
inlinenoexcept

Sets the sensor state of this contact.

Attention
Call this if fixture A or fixture B is a sensor.

◆ SetRestitution()

void playrho::d2::Contact::SetRestitution ( Real  restitution)
inlinenoexcept

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.

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

◆ SetToi()

void playrho::d2::Contact::SetToi ( Real  toi)
inlinenoexcept

Sets the time of impact (TOI).

After returning, this object will have a TOI that is set as indicated by HasValidToi().

Note
Behavior is undefined if the value assigned is less than 0 or greater than 1.
See also
Real GetToi() const.
HasValidToi.
Parameters
toiTime of impact as a fraction between 0 and 1 where 1 indicates no actual impact in the current time slot.

◆ SetTouching()

void playrho::d2::Contact::SetTouching ( )
inlinenoexcept

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.
See also
IsTouching().

◆ UnflagForFiltering()

void playrho::d2::Contact::UnflagForFiltering ( )
inlinenoexcept

Flags this contact for filtering.

Note
Filtering will occur the next time step.

◆ UnsetIsActive()

void playrho::d2::Contact::UnsetIsActive ( )
inlinenoexcept

Unsets the active state of this contact.

Attention
Call this if neither body A nor body B are "awake".

Friends And Related Function Documentation

◆ GetFriction()

auto GetFriction ( const Contact contact)
related

Gets the coefficient of friction.

See also
SetFriction.

◆ GetRestitution()

auto GetRestitution ( const Contact contact)
related

Gets the coefficient of restitution.

See also
SetRestitution.

◆ GetTangentSpeed()

auto GetTangentSpeed ( const Contact contact)
related

Gets the desired tangent speed.

Exceptions
std::out_of_rangeIf given an invalid contact identifier.
See also
SetTangentSpeed.

◆ GetToi()

Real GetToi ( const Contact contact)
related

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

Note
This is only valid if a TOI has been set.
See also
void SetToi(Real toi).
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 undefined.
See also
HasValidToi

◆ 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()

auto HasValidToi ( const Contact contact)
related

Gets whether a TOI is set.

See also
GetToi.
Examples
World.cpp.

◆ SetFriction()

void SetFriction ( Contact contact,
Real  value 
)
related

Sets the friction value for the identified contact.

Overrides the default friction mixture.

Note
This value persists until set or reset.
Warning
Behavior is undefined if given a negative friction value.
Parameters
contactThe contact whose friction should be set.
valueCo-efficient of friction value of zero or greater.
Exceptions
std::out_of_rangeIf given an invalid contact identifier.
See also
GetFriction.

◆ SetRestitution()

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.
Exceptions
std::out_of_rangeIf given an invalid contact identifier.
See also
GetRestitution.

◆ SetTangentSpeed()

void SetTangentSpeed ( Contact contact,
LinearVelocity  value 
)
related

Sets the desired tangent speed for a conveyor belt behavior.

Exceptions
std::out_of_rangeIf given an invalid contact identifier.
See also
GetTangentSpeed.

Member Data Documentation

◆ m_bodyA

BodyID playrho::d2::Contact::m_bodyA = InvalidBodyID
private

Identifier of body A.

Note
Field is 2-bytes.
Warning
Should only be body of fixture A.

Referenced by GetBodyA().

◆ m_bodyB

BodyID playrho::d2::Contact::m_bodyB = InvalidBodyID
private

Identifier of body B.

Note
Field is 2-bytes.
Warning
Should only be body of fixture B.

Referenced by GetBodyB().

◆ m_fixtureA

FixtureID playrho::d2::Contact::m_fixtureA = InvalidFixtureID
private

Identifier of fixture A.

Note
Field is 2-bytes.

Referenced by GetFixtureA().

◆ m_fixtureB

FixtureID playrho::d2::Contact::m_fixtureB = InvalidFixtureID
private

Identifier of fixture B.

Note
Field is 2-bytes.

Referenced by GetFixtureB().

◆ m_friction

Real playrho::d2::Contact::m_friction = 0
private

Mix of frictions of associated fixtures.

Note
Field is 4-bytes (with 4-byte Real).
See also
MixFriction.

Referenced by GetFriction(), and SetFriction().

◆ m_restitution

Real playrho::d2::Contact::m_restitution = 0
private

Mix of restitutions of associated fixtures.

Note
Field is 4-bytes (with 4-byte Real).
See also
MixRestitution.

Referenced by GetRestitution(), and SetRestitution().

◆ m_tangentSpeed

LinearVelocity playrho::d2::Contact::m_tangentSpeed = 0
private

Tangent speed.

Note
Field is 4-bytes (with 4-byte Real).

Referenced by GetTangentSpeed(), and SetTangentSpeed().

◆ m_toi

Real playrho::d2::Contact::m_toi = 0
private

Time of impact.

Note
This is a unit interval of time (a value between 0 and 1).
Only valid if m_flags & e_toiFlag.

Referenced by GetToi(), and SetToi().


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