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

The per-contact velocity constraint data structure. More...

#include <VelocityConstraint.hpp>

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

Classes

struct  Conf
 Configuration data for velocity constraints. More...
 
struct  Point
 Velocity constraint point. More...
 

Public Types

using size_type = std::remove_const< decltype(MaxManifoldPoints)>::type
 Size type.
 

Public Member Functions

 VelocityConstraint ()=default
 Default constructor. More...
 
 VelocityConstraint (const VelocityConstraint &copy)=default
 Copy constructor.
 
VelocityConstraintoperator= (const VelocityConstraint &copy)=default
 Assignment operator.
 
 VelocityConstraint (Real friction, Real restitution, LinearVelocity tangentSpeed, const WorldManifold &worldManifold, BodyID bA, BodyID bB, const std::vector< BodyConstraint > &bodies, const Conf &conf=GetDefaultConf())
 Initializing constructor.
 
UnitVec GetNormal () const noexcept
 Gets the normal of the contact in world coordinates. More...
 
UnitVec GetTangent () const noexcept
 Gets the tangent.
 
size_type GetPointCount () const noexcept
 Gets the count of points added to this object. More...
 
InvMass22 GetK () const noexcept
 Gets the "K" value. More...
 
Mass22 GetNormalMass () const noexcept
 Gets the normal mass. More...
 
Real GetFriction () const noexcept
 Gets the combined friction of the associated contact.
 
Real GetRestitution () const noexcept
 Gets the combined restitution of the associated contact.
 
LinearVelocity GetTangentSpeed () const noexcept
 Gets the tangent speed of the associated contact.
 
BodyID GetBodyA () const noexcept
 Gets identifier of body A.
 
BodyID GetBodyB () const noexcept
 Gets identifier of body B.
 
Momentum GetNormalImpulseAtPoint (size_type index) const noexcept
 Gets the normal impulse at the given point. More...
 
Momentum GetTangentImpulseAtPoint (size_type index) const noexcept
 Gets the tangent impulse at the given point. More...
 
LinearVelocity GetVelocityBiasAtPoint (size_type index) const noexcept
 Gets the velocity bias at the given point. More...
 
Mass GetNormalMassAtPoint (size_type index) const noexcept
 Gets the normal mass at the given point. More...
 
Mass GetTangentMassAtPoint (size_type index) const noexcept
 Gets the tangent mass at the given point. More...
 
Length2 GetPointRelPosA (size_type index) const noexcept
 Gets the point relative position of A. More...
 
Length2 GetPointRelPosB (size_type index) const noexcept
 Gets the point relative position of B. More...
 
void SetNormalImpulseAtPoint (size_type index, Momentum value)
 Sets the normal impulse at the given point.
 
void SetTangentImpulseAtPoint (size_type index, Momentum value)
 Sets the tangent impulse at the given point.
 
const PointGetPointAt (size_type index) const
 Accesses the point identified by the given index. More...
 

Static Public Member Functions

static constexpr Conf GetDefaultConf () noexcept
 Gets the default configuration for a VelocityConstraint.
 

Private Member Functions

void AddPoint (Momentum normalImpulse, Momentum tangentImpulse, Length2 relA, Length2 relB, const std::vector< BodyConstraint > &bodies, Conf conf)
 Adds the given point to this contact velocity constraint object. More...
 
void RemovePoint () noexcept
 Removes the last point added.
 
Point GetPoint (Momentum normalImpulse, Momentum tangentImpulse, Length2 relA, Length2 relB, const std::vector< BodyConstraint > &bodies, Conf conf) const noexcept
 Gets a point instance for the given parameters.
 
PointPointAt (size_type index)
 Accesses the point identified by the given index. More...
 

Private Attributes

Point m_points [MaxManifoldPoints]
 Velocity constraint points array (at least 72-bytes).
 
InvMass3 m_K = InvMass3{}
 Block solver "K" info. More...
 
Mass3 m_normalMass = Mass3{}
 Normal mass information. More...
 
BodyID m_bodyA = InvalidBodyID
 Identifier for body-A.
 
BodyID m_bodyB = InvalidBodyID
 Identifier for body-B.
 
UnitVec m_normal = GetInvalid<UnitVec>()
 Normal of the world manifold. 8-bytes.
 
Real m_friction = GetInvalid<Real>()
 Friction coefficient (4-bytes). Usually in the range of [0,1].
 
Real m_restitution = GetInvalid<Real>()
 Restitution coefficient (4-bytes).
 
LinearVelocity m_tangentSpeed = GetInvalid<decltype(m_tangentSpeed)>()
 Tangent speed (4-bytes).
 
size_type m_pointCount = 0
 Point count (at least 1-byte).
 

Detailed Description

The per-contact velocity constraint data structure.

Note
A valid contact velocity constraint must have a point count of either 1 or 2.
Invariant
The "K" value cannot be changed independent of: the total inverse mass, the normal, and the point relative positions.
The normal mass cannot be changed independent of: the "K" value.
The velocity biases cannot be changed independent of: the normal, and the point relative positions.

Constructor & Destructor Documentation

◆ VelocityConstraint()

playrho::d2::VelocityConstraint::VelocityConstraint ( )
default

Default constructor.

Initializes object with: a zero point count, an invalid K, an invalid normal mass, an invalid normal, invalid friction, invalid restitution, an invalid tangent speed.

Member Function Documentation

◆ AddPoint()

void playrho::d2::VelocityConstraint::AddPoint ( Momentum  normalImpulse,
Momentum  tangentImpulse,
Length2  relA,
Length2  relB,
const std::vector< BodyConstraint > &  bodies,
Conf  conf 
)
private

Adds the given point to this contact velocity constraint object.

Adds up to MaxManifoldPoints points. To find out how many points have already been added, call GetPointCount.

Warning
Behavior is undefined if an attempt is made to add more than MaxManifoldPoints points.
See also
GetPointCount().

◆ GetK()

InvMass22 playrho::d2::VelocityConstraint::GetK ( ) const
inlinenoexcept

Gets the "K" value.

Note
This value is only valid if previously set to a valid value.
Returns
"K" value previously set or the zero initialized value.

◆ GetNormal()

UnitVec playrho::d2::VelocityConstraint::GetNormal ( ) const
inlinenoexcept

Gets the normal of the contact in world coordinates.

Note
This value is set on construction.
Returns
Contact normal (in world coordinates) if previously set, an invalid value otherwise.

◆ GetNormalImpulseAtPoint()

Momentum playrho::d2::VelocityConstraint::GetNormalImpulseAtPoint ( VelocityConstraint::size_type  index) const
inlinenoexcept

Gets the normal impulse at the given point.

Note
Call the AddPoint or SetNormalImpulseAtPoint method to set this value.
Returns
Value previously set, or an invalid value.
See also
SetNormalImpulseAtPoint.

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

◆ GetNormalMass()

Mass22 playrho::d2::VelocityConstraint::GetNormalMass ( ) const
inlinenoexcept

Gets the normal mass.

Note
This value is only valid if previously set.
Returns
normal mass previously set or the zero initialized value.

◆ GetNormalMassAtPoint()

Mass playrho::d2::VelocityConstraint::GetNormalMassAtPoint ( VelocityConstraint::size_type  index) const
inlinenoexcept

Gets the normal mass at the given point.

Note
This value depends on the values of: the sum of the inverse-masses of the two bodies, the bodies' inverse-rotational-inertia, the point-relative A and B positions, and the normal.
The AddPoint method sets this value.

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

◆ GetPointAt()

const Point& playrho::d2::VelocityConstraint::GetPointAt ( size_type  index) const
inline

Accesses the point identified by the given index.

Warning
Behavior is undefined if given index is not less than MaxManifoldPoints.
Parameters
indexIndex of the point to return. This should be a value less than returned by GetPointCount.
Returns
velocity constraint point for the given index. This point's data will be invalid unless previously added and set.
See also
GetPointCount.

◆ GetPointCount()

size_type playrho::d2::VelocityConstraint::GetPointCount ( ) const
inlinenoexcept

Gets the count of points added to this object.

Returns
Value between 0 and MaxManifoldPoints.
See also
MaxManifoldPoints.
AddPoint.

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

◆ GetPointRelPosA()

Length2 playrho::d2::VelocityConstraint::GetPointRelPosA ( VelocityConstraint::size_type  index) const
inlinenoexcept

Gets the point relative position of A.

Note
The AddPoint method sets this value.
Returns
Previously set value or an invalid value.

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

◆ GetPointRelPosB()

Length2 playrho::d2::VelocityConstraint::GetPointRelPosB ( VelocityConstraint::size_type  index) const
inlinenoexcept

Gets the point relative position of B.

Note
The AddPoint method sets this value.
Returns
Previously set value or an invalid value.

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

◆ GetTangentImpulseAtPoint()

Momentum playrho::d2::VelocityConstraint::GetTangentImpulseAtPoint ( VelocityConstraint::size_type  index) const
inlinenoexcept

Gets the tangent impulse at the given point.

Note
Call the AddPoint or SetTangentImpulseAtPoint method to set this value.
Returns
Value previously set, or an invalid value.
See also
SetTangentImpulseAtPoint.

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

◆ GetTangentMassAtPoint()

Mass playrho::d2::VelocityConstraint::GetTangentMassAtPoint ( VelocityConstraint::size_type  index) const
inlinenoexcept

Gets the tangent mass at the given point.

Note
This value depends on the values of: the sum of the inverse-masses of the two bodies, the bodies' inverse-rotational-inertia, the point-relative A and B positions, and the tangent.
The AddPoint method sets this value.

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

◆ GetVelocityBiasAtPoint()

LinearVelocity playrho::d2::VelocityConstraint::GetVelocityBiasAtPoint ( size_type  index) const
inlinenoexcept

Gets the velocity bias at the given point.

Note
The AddPoint method sets this value.
Returns
Previously set value or an invalid value.

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

◆ PointAt()

Point& playrho::d2::VelocityConstraint::PointAt ( size_type  index)
inlineprivate

Accesses the point identified by the given index.

Warning
Behavior is undefined if given index is not less than MaxManifoldPoints.
Parameters
indexIndex of the point to return. This should be a value less than returned by GetPointCount.
Returns
velocity constraint point for the given index. This point's data will be invalid unless previously added and set.
See also
GetPointCount.

Referenced by SetNormalImpulseAtPoint(), and SetTangentImpulseAtPoint().

Member Data Documentation

◆ m_K

InvMass3 playrho::d2::VelocityConstraint::m_K = InvMass3{}
private

Block solver "K" info.

Note
Depends on the total inverse mass, the normal, and the point relative positions.
Only used by block solver.
This field is 12-bytes (on at least one 64-bit platform).

Referenced by GetK().

◆ m_normalMass

Mass3 playrho::d2::VelocityConstraint::m_normalMass = Mass3{}
private

Normal mass information.

This is the cached inverse of the K value or the zero initialized value.

Note
Depends on the K value.
Only used by block solver.
This field is 12-bytes (on at least one 64-bit platform).

Referenced by GetNormalMass().


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