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

A "body" physical entity. More...

#include <playrho/d2/Body.hpp>

Public Member Functions

 Body (const BodyConf &bd=GetDefaultBodyConf())
 Initializing constructor. More...
 
void Advance0 (ZeroToUnderOneFF< Real > value) noexcept
 Advances the body sweep's position 0 and alpha 0 values. More...
 
BodyAttach (ShapeID shapeId)
 Adds the given shape identifier to the identifiers associated with this body. More...
 
bool Detach (ShapeID shapeId)
 Removes the given shape identifier from the identifiers associated with this body. More...
 
AngularAcceleration GetAngularAcceleration () const noexcept
 Gets this body's angular acceleration. More...
 
NonNegative< FrequencyGetAngularDamping () const noexcept
 Gets the angular damping of the body. More...
 
NonNegativeFF< InvMassGetInvMass () const noexcept
 Gets the inverse total mass of the body. More...
 
NonNegativeFF< InvRotInertiaGetInvRotInertia () const noexcept
 Gets the inverse rotational inertia of the body. More...
 
LinearAcceleration2 GetLinearAcceleration () const noexcept
 Gets this body's linear acceleration. More...
 
NonNegative< FrequencyGetLinearDamping () const noexcept
 Gets the linear damping of the body. More...
 
const std::vector< ShapeID > & GetShapes () const noexcept
 Gets the identifiers of the shapes attached to this body. More...
 
const SweepGetSweep () const noexcept
 Gets the body's sweep. More...
 
const TransformationGetTransformation () const noexcept
 Gets the body transform for the body's origin. More...
 
BodyType GetType () const noexcept
 Gets the type of this body. More...
 
Time GetUnderActiveTime () const noexcept
 Gets this body's under-active time value. More...
 
Velocity GetVelocity () const noexcept
 Gets the velocity. More...
 
bool IsAccelerable () const noexcept
 Is "accelerable". More...
 
bool IsAwake () const noexcept
 Gets the awake/asleep state of this body. More...
 
constexpr bool IsDestroyed () const noexcept
 Whether or not this was destroyed. More...
 
bool IsEnabled () const noexcept
 Gets the enabled/disabled state of the body. More...
 
bool IsFixedRotation () const noexcept
 Does this body have fixed rotation? More...
 
bool IsImpenetrable () const noexcept
 Is this body treated like a bullet for continuous collision detection? More...
 
bool IsMassDataDirty () const noexcept
 Gets whether the mass data for this body is "dirty".
 
bool IsSleepingAllowed () const noexcept
 Gets whether or not this body allowed to sleep. More...
 
bool IsSpeedable () const noexcept
 Is "speedable". More...
 
void JustSetVelocity (const Velocity &value) noexcept
 
void ResetAlpha0 () noexcept
 Resets the given body's "alpha-0" value. More...
 
void SetAcceleration (const LinearAcceleration2 &linear, AngularAcceleration angular) noexcept
 Sets the linear and rotational accelerations on this body. More...
 
void SetAngularDamping (NonNegative< Frequency > angularDamping) noexcept
 Sets the angular damping of the body. More...
 
void SetAwake () noexcept
 Awakens this body. More...
 
void SetAwakeFlag () noexcept
 Sets the body's awake flag. More...
 
constexpr void SetDestroyed () noexcept
 Sets the destroyed property. More...
 
void SetEnabled () noexcept
 Sets the enabled state. More...
 
void SetFixedRotation (bool flag)
 Sets this body to have fixed rotation. More...
 
void SetImpenetrable () noexcept
 Sets the impenetrable status of this body. More...
 
void SetInvMassData (NonNegative< InvMass > invMass, NonNegative< InvRotInertia > invRotI) noexcept
 Sets the inverse mass data and clears the mass-data-dirty flag. More...
 
void SetLinearDamping (NonNegative< Frequency > linearDamping) noexcept
 Sets the linear damping of the body. More...
 
void SetPosition0 (const Position &value) noexcept
 Sets the "position 0" value of the body to the given position. More...
 
void SetPosition1 (const Position &value) noexcept
 Sets the body sweep's "position 1" value. More...
 
void SetShapes (std::vector< ShapeID > value)
 Sets the identifiers of the shapes attached to this body. More...
 
void SetSleepingAllowed (bool flag) noexcept
 Sets whether or not this body is allowed to sleep. More...
 
void SetSweep (const Sweep &value) noexcept
 Sets the body's sweep value. More...
 
void SetType (BodyType value) noexcept
 Sets the type of this body. More...
 
void SetUnderActiveTime (Time value) noexcept
 Sets the "under-active" time to the given value. More...
 
void SetVelocity (const Velocity &value) noexcept
 Sets the body's velocity (linear and angular velocity). More...
 
void UnsetAwake () noexcept
 Sets this body to asleep if sleeping is allowed. More...
 
void UnsetAwakeFlag () noexcept
 Unsets the body's awake flag. More...
 
constexpr void UnsetDestroyed () noexcept
 Unsets the destroyed property. More...
 
void UnsetEnabled () noexcept
 Unsets the enabled flag. More...
 
void UnsetImpenetrable () noexcept
 Unsets the impenetrable status of this body. More...
 

Static Public Attributes

static constexpr auto DefaultAngularDamping = NonNegative<Frequency>{}
 Default angular damping.
 
static constexpr auto DefaultLinearDamping = NonNegative<Frequency>{}
 Default linear damping.
 

Related Functions

(Note that these are not member functions.)

void ApplyAngularImpulse (Body &body, AngularMomentum impulse) noexcept
 Applies an angular impulse. More...
 
void ApplyLinearImpulse (Body &body, const Momentum2 &impulse, const Length2 &point) noexcept
 Applies an impulse at a point. More...
 
bool Awaken (Body &body) noexcept
 Awakens the body if it's asleep. More...
 
Acceleration GetAcceleration (const Body &body) noexcept
 Gets the given body's acceleration. More...
 
Angle GetAngle (const Body &body) noexcept
 Gets the body's angle. More...
 
AngularAcceleration GetAngularAcceleration (const Body &body) noexcept
 Gets this body's angular acceleration. More...
 
NonNegative< FrequencyGetAngularDamping (const Body &body) noexcept
 Gets the angular damping of the body. More...
 
AngularVelocity GetAngularVelocity (const Body &body) noexcept
 Gets the angular velocity. More...
 
BodyConf GetBodyConf (const Body &body)
 Gets the body definition for the given body. More...
 
Force2 GetForce (const Body &body) noexcept
 Gets the net force that the given body is currently experiencing.
 
NonNegativeFF< InvMassGetInvMass (const Body &body) noexcept
 Gets the inverse total mass of the body. More...
 
NonNegativeFF< InvRotInertiaGetInvRotInertia (const Body &body) noexcept
 Gets the inverse rotational inertia of the body. More...
 
LinearAcceleration2 GetLinearAcceleration (const Body &body) noexcept
 Gets this body's linear acceleration. More...
 
NonNegative< FrequencyGetLinearDamping (const Body &body) noexcept
 Gets the linear damping of the body. More...
 
LinearVelocity2 GetLinearVelocity (const Body &body) noexcept
 Gets the linear velocity of the center of mass. More...
 
LinearVelocity2 GetLinearVelocityFromLocalPoint (const Body &body, const Length2 &localPoint) noexcept
 Gets the linear velocity from a local point. More...
 
LinearVelocity2 GetLinearVelocityFromWorldPoint (const Body &body, const Length2 &worldPoint) noexcept
 Gets the linear velocity from a world point attached to this body. More...
 
Length2 GetLocalPoint (const Body &body, const Length2 &worldPoint) noexcept
 Gets a local point relative to the body's origin given a world point. More...
 
RotInertia GetLocalRotInertia (const Body &body) noexcept
 Gets the rotational inertia of the body about the local origin. More...
 
UnitVec GetLocalVector (const Body &body, const UnitVec &uv) noexcept
 Gets a locally oriented unit vector given a world oriented unit vector. More...
 
Length2 GetLocation (const Body &body) noexcept
 Gets the body's origin location. More...
 
Mass GetMass (const Body &body) noexcept
 Gets the mass of the body. More...
 
Position GetPosition (const Body &body) noexcept
 Gets the body's position.
 
Position GetPosition0 (const Body &body) noexcept
 Gets the "position 0" Position information for the given body.
 
Position GetPosition1 (const Body &body) noexcept
 Gets the "position 1" Position information for the given body.
 
RotInertia GetRotInertia (const Body &body) noexcept
 Gets the rotational inertia of the body. More...
 
const std::vector< ShapeID > & GetShapes (const Body &body) noexcept
 Gets the identifiers of the shapes attached to the body.
 
const SweepGetSweep (const Body &body) noexcept
 Gets the body's sweep. More...
 
Torque GetTorque (const Body &body) noexcept
 Gets the net torque that the given body is currently experiencing.
 
const TransformationGetTransformation (const Body &body) noexcept
 Gets the body's transformation. More...
 
BodyType GetType (const Body &body) noexcept
 Gets the type of this body. More...
 
Time GetUnderActiveTime (const Body &body) noexcept
 Gets the given body's under-active time. More...
 
Velocity GetVelocity (const Body &body) noexcept
 Gets the velocity. More...
 
Velocity GetVelocity (const Body &body, Time h) noexcept
 Gets the velocity of the body after the given time accounting for the body's acceleration and capped by the given configuration. More...
 
Length2 GetWorldPoint (const Body &body, const Length2 &localPoint) noexcept
 Gets the world coordinates of a point given in coordinates relative to the body's origin. More...
 
Length2 GetWorldVector (const Body &body, const Length2 &localVector) noexcept
 Gets the world coordinates of a vector given the local coordinates. More...
 
UnitVec GetWorldVector (const Body &body, const UnitVec &localVector) noexcept
 Gets the world vector for the given local vector from the given body's transformation.
 
bool IsAccelerable (const Body &body) noexcept
 Is "accelerable". More...
 
bool IsAwake (const Body &body) noexcept
 Gets the awake/asleep state of this body. More...
 
bool IsEnabled (const Body &body) noexcept
 Gets the enabled/disabled state of the body. More...
 
bool IsFixedRotation (const Body &body) noexcept
 Does this body have fixed rotation? More...
 
bool IsImpenetrable (const Body &body) noexcept
 Is this body treated like a bullet for continuous collision detection? More...
 
bool IsMassDataDirty (const Body &body) noexcept
 Gets whether the mass data for this body is "dirty".
 
bool IsSleepingAllowed (const Body &body) noexcept
 Gets whether or not this body allowed to sleep. More...
 
bool IsSpeedable (const Body &body) noexcept
 Is "speedable". More...
 
bool operator!= (const Body &lhs, const Body &rhs)
 Not-equals operator. More...
 
bool operator== (const Body &lhs, const Body &rhs)
 Equals operator. More...
 
void SetAcceleration (Body &body, AngularAcceleration value) noexcept
 Sets the given angular acceleration of the given body. More...
 
void SetAcceleration (Body &body, const Acceleration &value) noexcept
 Sets the accelerations on the given body. More...
 
void SetAcceleration (Body &body, const LinearAcceleration2 &linear, AngularAcceleration angular) noexcept
 Sets the linear and rotational accelerations on this body. More...
 
void SetAcceleration (Body &body, const LinearAcceleration2 &value) noexcept
 Sets the given linear acceleration of the given body. More...
 
void SetAngle (Body &body, Angle value)
 Sets the body's angular orientation. More...
 
void SetAngularDamping (Body &body, NonNegative< Frequency > value) noexcept
 Sets the angular damping of the body. More...
 
void SetAwake (Body &body) noexcept
 Awakens this body. More...
 
void SetEnabled (Body &body) noexcept
 Sets the enabled state. More...
 
void SetEnabled (Body &body, bool value) noexcept
 Sets the enabled state to the given value. More...
 
void SetFixedRotation (Body &body, bool value)
 Sets this body to have fixed rotation. More...
 
void SetImpenetrable (Body &body) noexcept
 Sets the impenetrable status of this body. More...
 
void SetLinearDamping (Body &body, NonNegative< Frequency > value) noexcept
 Sets the linear damping of the body. More...
 
void SetLocation (Body &body, const Length2 &value)
 Sets the body's location. More...
 
void SetMass (Body &body, Mass mass)
 Sets the mass of the given body.
 
void SetPosition0 (Body &body, const Position &value) noexcept
 Sets the "position 0" Position information for the given body.
 
void SetPosition1 (Body &body, const Position &value) noexcept
 Sets the "position 1" Position information for the given body.
 
void SetRotInertia (Body &body, RotInertia value) noexcept
 Sets the rotational inertia of the body.
 
void SetSleepingAllowed (Body &body, bool value) noexcept
 
void SetSweep (Body &body, const Sweep &value) noexcept
 Sets the sweep value of the given body. More...
 
void SetTransformation (Body &body, const Transformation &value) noexcept
 Sets the body's transformation. More...
 
void SetType (Body &body, BodyType value) noexcept
 Sets the type of this body. More...
 
void SetVelocity (Body &body, AngularVelocity value) noexcept
 Sets the angular velocity. More...
 
void SetVelocity (Body &body, const LinearVelocity2 &value) noexcept
 Sets the linear velocity of the center of mass. More...
 
void SetVelocity (Body &body, const Velocity &value) noexcept
 Sets the body's velocity (linear and angular velocity). More...
 
bool Unawaken (Body &body) noexcept
 Puts the body to sleep if it's awake. More...
 
void UnsetAwake (Body &body) noexcept
 Sets this body to asleep if sleeping is allowed. More...
 
void UnsetEnabled (Body &body) noexcept
 Unsets the enabled state. More...
 
void UnsetImpenetrable (Body &body) noexcept
 Unsets the impenetrable status of this body. More...
 

Detailed Description

A "body" physical entity.

A rigid body entity having associated properties like position, velocity, acceleration, and mass.

Invariant
Only bodies that allow sleeping, can be put to sleep.
Only "speedable" bodies can be awake or have non-zero velocities.
Only "accelerable" bodies can have non-zero accelerations or non-zero "under-active" times.
The body's transformation is always the body's sweep position one's linear position and the unit vector of the body's sweep position one's angular position.
See also
World, BodyConf.

Constructor & Destructor Documentation

◆ Body()

playrho::d2::Body::Body ( const BodyConf bd = GetDefaultBodyConf())
explicit

Initializing constructor.

Note
To create a body within a world, use World::CreateBody.
Parameters
bdConfiguration data for the body to construct.
Postcondition
GetLinearDamping() returns value of bd.linearDamping.
GetAngularDamping() returns value of bd.angularDamping.
GetInvMass() returns Real(0)/Kilogram if bd.type != BodyType::Dynamic, otherwise it returns value of bd.invMass.
GetInvRotInertia() returns InvRotInertia{} if bd.type != BodyType::Dynamic, otherwise it returns value of bd.invRotI.
GetVelocity() will return the value as if SetVelocity(const Velocity&) had been called with the values of bd.linearVelocity and bd.angularVelocity as the velocity.
GetAcceleration() will return the value as if SetAcceleration(LinearAcceleration2, AngularAcceleration) had been called with values of bd.linearAcceleration and bd.angularAcceleration.
See also
GetLinearDamping, GetAngularDamping, GetInvMass, GetTransformation, GetVelocity, GetAcceleration.
World::CreateBody.

Member Function Documentation

◆ Advance0()

void playrho::d2::Body::Advance0 ( ZeroToUnderOneFF< Real value)
inlinenoexcept

Advances the body sweep's position 0 and alpha 0 values.

Precondition
The body is speedable or body's sweep positions 0 and 1 are the same.
Postcondition
GetSweep() returns what calling Advance0(GetSweep(), value) would return before this call.
See also
GetSweep.

◆ Attach()

Body & playrho::d2::Body::Attach ( ShapeID  shapeId)

Adds the given shape identifier to the identifiers associated with this body.

Parameters
shapeIdIdentifier of the shape to attach.
Precondition
shapeId is not InvalidShapeID .
Postcondition
IsMassDataDirty() returns true.
GetShapes() returned container contains the given identifier.
See also
Detach, GetShapes, SetShapes, IsMassDataDirty.

◆ Detach()

bool playrho::d2::Body::Detach ( ShapeID  shapeId)

Removes the given shape identifier from the identifiers associated with this body.

Note
This also sets the mass-data-dirty flag. Call SetInvMassData to clear it.
Parameters
shapeIdIdentifier of the shape to detach.
Returns
true if identified shape was detached, false otherwise.
Postcondition
IsMassDataDirty() returns true if this function returned true.
GetShapes() returned container contains one less of the identifier.
See also
GetShapes, SetShapes, Attach, SetInvMassData.

◆ GetAngularAcceleration()

AngularAcceleration playrho::d2::Body::GetAngularAcceleration ( ) const
inlinenoexcept

Gets this body's angular acceleration.

See also
SetAcceleration.

◆ GetAngularDamping()

NonNegative< Frequency > playrho::d2::Body::GetAngularDamping ( ) const
inlinenoexcept

Gets the angular damping of the body.

See also
SetAngularDamping.

◆ GetInvMass()

NonNegativeFF< InvMass > playrho::d2::Body::GetInvMass ( ) const
inlinenoexcept

Gets the inverse total mass of the body.

This is the cached result of dividing 1 by the body's mass or zero for non linearly-accelerable bodies. Often floating division is much slower than multiplication. As such, it's likely faster to multiply values by this inverse value than to redivide them all the time by the mass.

Returns
Value of zero or more representing the body's inverse mass (in 1/kg).
See also
SetInvMassData.

◆ GetInvRotInertia()

NonNegativeFF< InvRotInertia > playrho::d2::Body::GetInvRotInertia ( ) const
inlinenoexcept

Gets the inverse rotational inertia of the body.

This is the cached result of dividing 1 by the body's rotational inertia or zero for non rotationally-accelerable bodies. Often floating division is much slower than multiplication. As such, it's likely faster to multiply values by this inverse value than to redivide them all the time by the rotational inertia.

Returns
Inverse rotational inertia (in 1/kg-m^2).
See also
SetInvMassData.

Referenced by SetMass().

◆ GetLinearAcceleration()

LinearAcceleration2 playrho::d2::Body::GetLinearAcceleration ( ) const
inlinenoexcept

Gets this body's linear acceleration.

See also
SetAcceleration.

◆ GetLinearDamping()

NonNegative< Frequency > playrho::d2::Body::GetLinearDamping ( ) const
inlinenoexcept

Gets the linear damping of the body.

See also
SetLinearDamping.

◆ GetShapes()

const std::vector< ShapeID > & playrho::d2::Body::GetShapes ( ) const
inlinenoexcept

Gets the identifiers of the shapes attached to this body.

See also
SetShapes, Attach, Detach.

Referenced by playrho::d2::AabbTreeWorld::GetShapes().

◆ GetSweep()

const Sweep & playrho::d2::Body::GetSweep ( ) const
inlinenoexcept

Gets the body's sweep.

Returns
The sweep used by this body.
See also
SetSweep.

◆ GetTransformation()

const Transformation & playrho::d2::Body::GetTransformation ( ) const
inlinenoexcept

Gets the body transform for the body's origin.

This gets the translation/location and rotation/direction of the body relative to its world. The location and direction of the body after stepping the world's physics simulations is dependent on a number of factors:

  1. Location and direction at the last time step.
  2. Forces and torques acting on the body (applied force, applied impulse, etc.).
  3. The mass and rotational inertia of the body.
  4. Damping of the body.
  5. Restitutioen and friction values of body's shape parts when experiencing collisions.
Returns
the world transform of the body's origin.
See also
SetSweep.

◆ GetType()

BodyType playrho::d2::Body::GetType ( ) const
noexcept

Gets the type of this body.

See also
SetType.

◆ GetUnderActiveTime()

Time playrho::d2::Body::GetUnderActiveTime ( ) const
inlinenoexcept

Gets this body's under-active time value.

Returns
Zero or more time in seconds (of step time) that this body has been "under-active" for.
See also
SetUnderActiveTime.

◆ GetVelocity()

Velocity playrho::d2::Body::GetVelocity ( ) const
inlinenoexcept

Gets the velocity.

See also
SetVelocity, JustSetVelocity.

◆ IsAccelerable()

bool playrho::d2::Body::IsAccelerable ( ) const
inlinenoexcept

Is "accelerable".

Indicates whether this body is accelerable, i.e. whether it is effected by forces. Only Dynamic bodies are accelerable.

Returns
true if the body is accelerable, false otherwise.
See also
GetType, SetType.

◆ IsAwake()

bool playrho::d2::Body::IsAwake ( ) const
inlinenoexcept

Gets the awake/asleep state of this body.

Warning
Being awake may or may not imply being speedable.
Returns
true if the body is awake.
See also
SetAwake.

◆ IsDestroyed()

constexpr bool playrho::d2::Body::IsDestroyed ( ) const
constexprnoexcept

Whether or not this was destroyed.

If you have gotten this body's value from a world, this function says whether the world considers the body destroyed or not.

See also
SetDestroyed, UnsetDestroyed.

◆ IsEnabled()

bool playrho::d2::Body::IsEnabled ( ) const
inlinenoexcept

Gets the enabled/disabled state of the body.

See also
SetEnabled, UnsetEnabled.

◆ IsFixedRotation()

bool playrho::d2::Body::IsFixedRotation ( ) const
inlinenoexcept

Does this body have fixed rotation?

See also
SetFixedRotation.

◆ IsImpenetrable()

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

Is this body treated like a bullet for continuous collision detection?

See also
SetImpenetrable, UnsetImpenetrable.

◆ IsSleepingAllowed()

bool playrho::d2::Body::IsSleepingAllowed ( ) const
inlinenoexcept

Gets whether or not this body allowed to sleep.

See also
SetSleepingAllowed.

◆ IsSpeedable()

bool playrho::d2::Body::IsSpeedable ( ) const
inlinenoexcept

Is "speedable".

Is this body able to have a non-zero speed associated with it. Kinematic and Dynamic bodies are speedable. Static bodies are not.

See also
GetType, SetType.

◆ JustSetVelocity()

void playrho::d2::Body::JustSetVelocity ( const Velocity value)
noexcept

Sets the body's velocity.

Note
This sets what GetVelocity() returns.
Parameters
valueValue of the velocity to set.
Precondition
IsSpeedable(const Body&) is true or given velocity is zero.
Postcondition
GetVelocity() returns the value set.
See also
GetVelocity, IsSpeedable(const Body&).

◆ ResetAlpha0()

void playrho::d2::Body::ResetAlpha0 ( )
inlinenoexcept

Resets the given body's "alpha-0" value.

Postcondition
GetSweep().alpha0 is zero.
See also
GetSweep.

◆ SetAcceleration()

void playrho::d2::Body::SetAcceleration ( const LinearAcceleration2 linear,
AngularAcceleration  angular 
)
noexcept

Sets the linear and rotational accelerations on this body.

Note
This has no effect on non-accelerable bodies.
A non-zero acceleration will also awaken the body.
Parameters
linearLinear acceleration.
angularAngular acceleration.
Precondition
linear and angular are both valid. I.e. IsValid(linear) && IsValid(angular).
Postcondition
GetLinearAcceleration() returns linear .
GetAngularAcceleration() returns angular .
IsAwake() is true and GetUnderActiveTime() returns zero if either of the new accelerations are higher, or the new linear acceleration is in a new direction, or the sign of the new angular acceleration is different.

◆ SetAngularDamping()

void playrho::d2::Body::SetAngularDamping ( NonNegative< Frequency angularDamping)
inlinenoexcept

Sets the angular damping of the body.

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

◆ SetAwake()

void playrho::d2::Body::SetAwake ( )
noexcept

Awakens this body.

Sets this body to awake and resets its under-active time if it's a "speedable" body. This function has no effect otherwise.

Postcondition
If this body is a "speedable" body, then the IsAwake() function returns true.
If this body is a "speedable" body, then this body's GetUnderActiveTime function returns zero.
See also
IsAwake.

◆ SetAwakeFlag()

void playrho::d2::Body::SetAwakeFlag ( )
inlinenoexcept

Sets the body's awake flag.

This is done unconditionally.

Precondition
IsSpeedable(const Body&) is true.
See also
UnsetAwakeFlag.

◆ SetDestroyed()

constexpr void playrho::d2::Body::SetDestroyed ( )
constexprnoexcept

Sets the destroyed property.

Note
This is only meaningfully used by the world implementation. While calling this in your code will have the stated post condition, it won't effect any bodies within a world.
Postcondition
IsDestroyed() returns true.

◆ SetEnabled()

void playrho::d2::Body::SetEnabled ( )
inlinenoexcept

Sets the enabled state.

Postcondition
IsEnabled() returns true.
See also
IsEnabled(const Body&).

◆ SetFixedRotation()

void playrho::d2::Body::SetFixedRotation ( bool  flag)

Sets this body to have fixed rotation.

Note
This causes the mass to be reset.
Postcondition
IsFixedRotation() returns the value set.
See also
IsFixedRotation.

Referenced by SetFixedRotation().

◆ SetImpenetrable()

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

Sets the impenetrable status of this body.

Sets that this body should be treated like a bullet for continuous collision detection.

Postcondition
IsImpenetrable() returns true.
See also
IsImpenetrable.

◆ SetInvMassData()

void playrho::d2::Body::SetInvMassData ( NonNegative< InvMass invMass,
NonNegative< InvRotInertia invRotI 
)
inlinenoexcept

Sets the inverse mass data and clears the mass-data-dirty flag.

Postcondition
GetInvMass() returns the set inverse mass.
GetInvRotInertia() returns the set inverse rotational inertia.
IsMassDataDirty() returns false.
See also
GetInvMass, GetInvRotInertia, IsMassDataDirty.

Referenced by SetMass().

◆ SetLinearDamping()

void playrho::d2::Body::SetLinearDamping ( NonNegative< Frequency linearDamping)
inlinenoexcept

Sets the linear damping of the body.

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

◆ SetPosition0()

void playrho::d2::Body::SetPosition0 ( const Position value)
inlinenoexcept

Sets the "position 0" value of the body to the given position.

Precondition
The body is speedable or the new position is equal to the existing position 0.
Postcondition
GetSweep().pos0 is the value set.
See also
GetSweep, SetSweep.

◆ SetPosition1()

void playrho::d2::Body::SetPosition1 ( const Position value)
inlinenoexcept

Sets the body sweep's "position 1" value.

Precondition
The body is speedable or the new position is equal to the existing position 1.
Postcondition
GetSweep().pos1 is the value set.
GetTransformation() returns GetTransform1(GetSweep()) of the new sweep.
See also
GetSweep, SetSweep, GetTransformation.

◆ SetShapes()

void playrho::d2::Body::SetShapes ( std::vector< ShapeID value)
inline

Sets the identifiers of the shapes attached to this body.

Postcondition
GetShapes() returns the value given.
IsMassDataDirty() returns true.
See also
GetShapes, Attach, Detach.

◆ SetSleepingAllowed()

void playrho::d2::Body::SetSleepingAllowed ( bool  flag)
noexcept

Sets whether or not this body is allowed to sleep.

Use to enable/disable sleeping on this body. If you disable sleeping, the body will be woken.

See also
IsSleepingAllowed.

◆ SetSweep()

void playrho::d2::Body::SetSweep ( const Sweep value)
inlinenoexcept

Sets the body's sweep value.

Note
This may also change the body's transformation.
Precondition
The body is speedable or the new sweep's position 0 and 1 are equal to each other.
Postcondition
GetSweep() returns the value set.
GetTransformation() returns GetTransform1(value).
See also
GetSweep, GetTransformation, IsSpeedable.

◆ SetType()

void playrho::d2::Body::SetType ( BodyType  value)
noexcept

Sets the type of this body.

Postcondition
GetType() returns type set.
GetFlags() returns a value reflective of the type set.
GetUnderActiveTime() returns 0.
IsAwake(const Body&) returns true for BodyType::Dynamic or BodyType::Kinematic, and returns false for BodyType::Static.
See also
GetType, GetFlags.

◆ SetUnderActiveTime()

void playrho::d2::Body::SetUnderActiveTime ( Time  value)
inlinenoexcept

Sets the "under-active" time to the given value.

Sets the "under-active" time to a value of zero or a non-zero value if the body is "accelerable". Otherwise it does nothing.

Note
A non-zero time is only valid for an "accelerable" body.
See also
GetUnderActiveTime.

◆ SetVelocity()

void playrho::d2::Body::SetVelocity ( const Velocity value)
noexcept

Sets the body's velocity (linear and angular velocity).

Parameters
valueValue of the velocity to set.
Postcondition
If velocity is non-zero and IsSpeedable(const Body&) is true, IsAwake(const Body&) returns true and GetUnderActiveTime() returns 0.
If velocity is zero or IsSpeedable(const Body&) is true, GetVelocity() returns the value set.
See also
IsAwake(const Body&), IsSpeedable(const Body&), GetUnderActiveTime, GetVelocity.

◆ UnsetAwake()

void playrho::d2::Body::UnsetAwake ( )
noexcept

Sets this body to asleep if sleeping is allowed.

If this body is allowed to sleep, this: sets the sleep state of the body to asleep, resets this body's under active time, and resets this body's velocity (linear and angular).

Postcondition
The IsAwake() function returns false.
This body's GetUnderActiveTime function returns zero.
This body's GetVelocity function returns zero linear & zero angular speed.
See also
IsAwake.

◆ UnsetAwakeFlag()

void playrho::d2::Body::UnsetAwakeFlag ( )
inlinenoexcept

Unsets the body's awake flag.

Precondition
Either !IsSpeedable(const Body&) or IsSleepingAllowed(const Body&).
See also
SetAwakeFlag.

◆ UnsetDestroyed()

constexpr void playrho::d2::Body::UnsetDestroyed ( )
constexprnoexcept

Unsets the destroyed property.

Note
This is only meaningfully used by the world implementation. While calling this in your code will have the stated post condition, it won't effect any bodies within a world.
Postcondition
IsDestroyed() returns false.

◆ UnsetEnabled()

void playrho::d2::Body::UnsetEnabled ( )
inlinenoexcept

Unsets the enabled flag.

Postcondition
IsEnabled() returns false.
See also
IsEnabled.

◆ UnsetImpenetrable()

void playrho::d2::Body::UnsetImpenetrable ( )
inlinenoexcept

Unsets the impenetrable status of this body.

Unsets that this body should be treated like a bullet for continuous collision detection.

Postcondition
IsImpenetrable() returns false.
See also
IsImpenetrable.

Friends And Related Function Documentation

◆ ApplyAngularImpulse()

void ApplyAngularImpulse ( Body body,
AngularMomentum  impulse 
)
related

Applies an angular impulse.

Parameters
bodyBody to apply the angular impulse to.
impulseAngular impulse to be applied.

◆ ApplyLinearImpulse()

void ApplyLinearImpulse ( Body body,
const Momentum2 impulse,
const Length2 point 
)
related

Applies an impulse at a point.

Note
This immediately modifies the velocity.
This also modifies the angular velocity if the point of application is not at the center of mass.
Non-zero impulses wakes up the body.
Parameters
bodyBody to apply the impulse to.
impulsethe world impulse vector.
pointthe world position of the point of application.

◆ Awaken()

bool Awaken ( Body body)
related

Awakens the body if it's asleep.

See also
Unawaken(Body& body).

◆ GetAcceleration()

Acceleration GetAcceleration ( const Body body)
related

Gets the given body's acceleration.

Parameters
bodyBody whose acceleration should be returned.
See also
SetAcceleration(Body& body, Acceleration value).

◆ GetAngle()

Angle GetAngle ( const Body body)
related

Gets the body's angle.

Returns
Body's angle relative to its World.

◆ GetAngularAcceleration()

AngularAcceleration GetAngularAcceleration ( const Body body)
related

Gets this body's angular acceleration.

See also
SetAcceleration(Body& body, Acceleration value), GetLinearAcceleration(const Body& body).

◆ GetAngularDamping()

NonNegative< Frequency > GetAngularDamping ( const Body body)
related

Gets the angular damping of the body.

See also
SetAngularDamping(Body& body, NonNegative<Frequency> value).

◆ GetAngularVelocity()

AngularVelocity GetAngularVelocity ( const Body body)
related

Gets the angular velocity.

Parameters
bodyBody to get the angular velocity for.
Returns
the angular velocity.
See also
GetVelocity(const Body& body).

◆ GetBodyConf()

BodyConf GetBodyConf ( const Body body)
related

Gets the body definition for the given body.

Parameters
bodyBody to get the BodyConf for.

◆ GetInvMass()

NonNegativeFF< InvMass > GetInvMass ( const Body body)
related

Gets the inverse total mass of the body.

This is the cached result of dividing 1 by the body's mass. Often floating division is much slower than multiplication. As such, it's likely faster to multiply values by this inverse value than to redivide them all the time by the mass.

Returns
Value of zero or more representing the body's inverse mass (in 1/kg).
See also
SetInvMassData.

◆ GetInvRotInertia()

NonNegativeFF< InvRotInertia > GetInvRotInertia ( const Body body)
related

Gets the inverse rotational inertia of the body.

This is the cached result of dividing 1 by the body's rotational inertia. Often floating division is much slower than multiplication. As such, it's likely faster to multiply values by this inverse value than to redivide them all the time by the rotational inertia.

Returns
Inverse rotational inertia (in 1/kg-m^2).

◆ GetLinearAcceleration()

LinearAcceleration2 GetLinearAcceleration ( const Body body)
related

Gets this body's linear acceleration.

See also
SetAcceleration(Body& body, Acceleration value), GetAngularAcceleration(const Body& body).

◆ GetLinearDamping()

NonNegative< Frequency > GetLinearDamping ( const Body body)
related

Gets the linear damping of the body.

See also
SetLinearDamping(Body& body, NonNegative<Frequency> value).

◆ GetLinearVelocity()

LinearVelocity2 GetLinearVelocity ( const Body body)
related

Gets the linear velocity of the center of mass.

Parameters
bodyBody to get the linear velocity for.
Returns
the linear velocity of the center of mass.
See also
GetVelocity(const Body& body).

◆ GetLinearVelocityFromLocalPoint()

LinearVelocity2 GetLinearVelocityFromLocalPoint ( const Body body,
const Length2 localPoint 
)
related

Gets the linear velocity from a local point.

Parameters
bodyBody to get the linear velocity for.
localPointpoint in local coordinates.
Returns
the world velocity of a point.

◆ GetLinearVelocityFromWorldPoint()

LinearVelocity2 GetLinearVelocityFromWorldPoint ( const Body body,
const Length2 worldPoint 
)
related

Gets the linear velocity from a world point attached to this body.

Parameters
bodyBody to get the linear velocity for.
worldPointpoint in world coordinates.
Returns
the world velocity of a point.

◆ GetLocalPoint()

Length2 GetLocalPoint ( const Body body,
const Length2 worldPoint 
)
related

Gets a local point relative to the body's origin given a world point.

Parameters
bodyBody that the returned point should be relative to.
worldPointpoint in world coordinates.
Returns
the corresponding local point relative to the body's origin.

◆ GetLocalRotInertia()

RotInertia GetLocalRotInertia ( const Body body)
related

Gets the rotational inertia of the body about the local origin.

Returns
the rotational inertia.
See also
Body::GetInvRotInertia, Body::SetInvMassData.

◆ GetLocalVector()

UnitVec GetLocalVector ( const Body body,
const UnitVec uv 
)
related

Gets a locally oriented unit vector given a world oriented unit vector.

Parameters
bodyBody that the returned vector should be relative to.
uvUnit vector in world orientation.
Returns
the corresponding local vector.

◆ GetLocation()

Length2 GetLocation ( const Body body)
related

Gets the body's origin location.

This is the location of the body's origin relative to its world. The location of the body after stepping the world's physics simulations is dependent on a number of factors:

  1. Location at the last time step.
  2. Forces acting on the body (gravity, applied force, applied impulse).
  3. The mass data of the body.
  4. Damping of the body.
  5. Restitution and friction values of the body's shape parts when they experience collisions.
    Returns
    World location of the body's origin.
    See also
    GetAngle.

◆ GetMass()

Mass GetMass ( const Body body)
related

Gets the mass of the body.

Note
This may be the total calculated mass or it may be the set mass of the body.
Returns
Value of zero or more representing the body's mass.
See also
GetInvMass, SetInvMassData

◆ GetRotInertia()

RotInertia GetRotInertia ( const Body body)
related

Gets the rotational inertia of the body.

Parameters
bodyBody to get the rotational inertia for.
Returns
the rotational inertia.
See also
Body::GetInvRotInertia, Body::SetInvMassData.

◆ GetSweep()

const Sweep & GetSweep ( const Body body)
related

Gets the body's sweep.

See also
SetSweep(Body& body, const Sweep& value).

◆ GetTransformation()

const Transformation & GetTransformation ( const Body body)
related

Gets the body's transformation.

See also
SetTransformation(Body& body, Transformation value).

◆ GetType()

BodyType GetType ( const Body body)
related

Gets the type of this body.

See also
SetType(Body&,BodyType).

◆ GetUnderActiveTime()

Time GetUnderActiveTime ( const Body body)
related

Gets the given body's under-active time.

Returns
Zero or more time in seconds (of step time) that this body has been "under-active" for.

◆ GetVelocity() [1/2]

Velocity GetVelocity ( const Body body)
related

◆ GetVelocity() [2/2]

Velocity GetVelocity ( const Body body,
Time  h 
)
related

Gets the velocity of the body after the given time accounting for the body's acceleration and capped by the given configuration.

Parameters
bodyBody to get the velocity for.
hTime elapsed to get velocity for.

◆ GetWorldPoint()

Length2 GetWorldPoint ( const Body body,
const Length2 localPoint 
)
related

Gets the world coordinates of a point given in coordinates relative to the body's origin.

Parameters
bodyBody that the given point is relative to.
localPointa point measured relative the the body's origin.
Returns
the same point expressed in world coordinates.

◆ GetWorldVector()

Length2 GetWorldVector ( const Body body,
const Length2 localVector 
)
related

Gets the world coordinates of a vector given the local coordinates.

Parameters
bodyBody that the given vector is relative to.
localVectora vector fixed in the body.
Returns
the same vector expressed in world coordinates.

◆ IsAccelerable()

bool IsAccelerable ( const Body body)
related

Is "accelerable".

Indicates whether this body is accelerable, i.e. whether it is effected by forces. Only Dynamic bodies are accelerable.

Returns
true if the body is accelerable, false otherwise.
See also
GetType(const Body& body), SetType(Body& body, BodyType value).

◆ IsAwake()

bool IsAwake ( const Body body)
related

Gets the awake/asleep state of this body.

Warning
Being awake may or may not imply being speedable.
Returns
true if the body is awake.
See also
SetAwake(Body&), UnsetAwake(Body&).

◆ IsEnabled()

bool IsEnabled ( const Body body)
related

Gets the enabled/disabled state of the body.

See also
SetEnabled(Body&), UnsetEnabled(Body&).

◆ IsFixedRotation()

bool IsFixedRotation ( const Body body)
related

Does this body have fixed rotation?

See also
SetFixedRotation(Body&, bool).

◆ IsImpenetrable()

bool IsImpenetrable ( const Body body)
related

Is this body treated like a bullet for continuous collision detection?

See also
SetImpenetrable(Body&).

◆ IsSleepingAllowed()

bool IsSleepingAllowed ( const Body body)
related

Gets whether or not this body allowed to sleep.

See also
SetSleepingAllowed(Body&).

◆ IsSpeedable()

bool IsSpeedable ( const Body body)
related

Is "speedable".

Is this body able to have a non-zero speed associated with it. Kinematic and Dynamic bodies are speedable. Static bodies are not.

◆ operator!=()

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

Not-equals operator.

See also
operator==(const Body&, const Body&).

◆ operator==()

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

Equals operator.

See also
operator!=(const Body&, const Body&).

◆ SetAcceleration() [1/4]

void SetAcceleration ( Body body,
AngularAcceleration  value 
)
related

Sets the given angular acceleration of the given body.

See also
GetAcceleration(const Body& body).

◆ SetAcceleration() [2/4]

void SetAcceleration ( Body body,
const Acceleration value 
)
related

Sets the accelerations on the given body.

Note
This has no effect on non-accelerable bodies.
A non-zero acceleration will also awaken the body.
Parameters
bodyBody whose acceleration should be set.
valueAcceleration value to set.
See also
GetAcceleration(const Body& body).

◆ SetAcceleration() [3/4]

void SetAcceleration ( Body body,
const LinearAcceleration2 linear,
AngularAcceleration  angular 
)
related

Sets the linear and rotational accelerations on this body.

Note
This has no effect on non-accelerable bodies.
A non-zero acceleration will also awaken the body.
Parameters
bodyBody to set the acceleration of.
linearLinear acceleration.
angularAngular acceleration.
See also
GetAcceleration(const Body& body).

◆ SetAcceleration() [4/4]

void SetAcceleration ( Body body,
const LinearAcceleration2 value 
)
related

Sets the given linear acceleration of the given body.

See also
GetAcceleration(const Body& body).

◆ SetAngle()

void SetAngle ( Body body,
Angle  value 
)
related

Sets the body's angular orientation.

This instantly adjusts the body to be at the new angular orientation.

Warning
Manipulating a body's angle this way can cause non-physical behavior!
Parameters
bodyThe body to update.
valueValid world angle of the body's local origin.
See also
GetAngle(const Body& body).

◆ SetAngularDamping()

void SetAngularDamping ( Body body,
NonNegative< Frequency value 
)
related

Sets the angular damping of the body.

See also
GetAngularDamping(const Body& body).

◆ SetAwake()

void SetAwake ( Body body)
related

Awakens this body.

Sets this body to awake and resets its under-active time if it's a "speedable" body. This function has no effect otherwise.

Postcondition
If this body is a "speedable" body, then IsAwake(const Body&) function returns true.
If this body is a "speedable" body, then this body's GetUnderActiveTime function returns zero.
See also
IsAwake(const Body&), UnsetAwake(Body&).

◆ SetEnabled() [1/2]

void SetEnabled ( Body body)
related

Sets the enabled state.

See also
IsEnabled(const Body&), UnsetEnabled(Body&).

◆ SetEnabled() [2/2]

void SetEnabled ( Body body,
bool  value 
)
related

Sets the enabled state to the given value.

See also
IsEnabled(const Body&), SetEnabled(Body&), UnsetEnabled(Body&).

◆ SetFixedRotation()

void SetFixedRotation ( Body body,
bool  value 
)
related

Sets this body to have fixed rotation.

Note
This causes the mass to be reset.
See also
IsFixedRotation(const Body&).

◆ SetImpenetrable()

void SetImpenetrable ( Body body)
related

Sets the impenetrable status of this body.

Sets whether or not this body should be treated like a bullet for continuous collision detection.

See also
IsImpenetrable(const Body&), UnsetImpenetrable(Body&).

◆ SetLinearDamping()

void SetLinearDamping ( Body body,
NonNegative< Frequency value 
)
related

Sets the linear damping of the body.

See also
GetLinearDamping(const Body& body).

◆ SetLocation()

void SetLocation ( Body body,
const Length2 value 
)
related

Sets the body's location.

This instantly adjusts the body to be at the new location.

Warning
Manipulating a body's location this way can cause non-physical behavior!
Parameters
bodyThe body to update.
valueValid world location of the body's local origin.
See also
GetLocation(const Body& body).

◆ SetSleepingAllowed()

void SetSleepingAllowed ( Body body,
bool  value 
)
related

You can disable sleeping on this body. If you disable sleeping, the body will be woken.

See also
IsSleepingAllowed(const Body&).

◆ SetSweep()

void SetSweep ( Body body,
const Sweep value 
)
related

Sets the sweep value of the given body.

See also
GetSweep(const Body& body).

◆ SetTransformation()

void SetTransformation ( Body body,
const Transformation value 
)
related

Sets the body's transformation.

Note
This sets the sweep to the new transformation.
Postcondition
GetTransformation(const Body& body) will return the value set.
GetPosition1(const Body& body) will return a position equivalent to value given.
See also
GetTransformation(const Body& body), GetPosition1(const Body& body).

◆ SetType()

void SetType ( Body body,
BodyType  value 
)
related

Sets the type of this body.

See also
GetType(const Body&).

◆ SetVelocity() [1/3]

void SetVelocity ( Body body,
AngularVelocity  value 
)
related

Sets the angular velocity.

Parameters
bodyBody to set the angular velocity of.
valuethe new angular velocity.
See also
GetAngularVelocity(const Body& body).

◆ SetVelocity() [2/3]

void SetVelocity ( Body body,
const LinearVelocity2 value 
)
related

Sets the linear velocity of the center of mass.

Parameters
bodyBody to set the linear velocity of.
valuethe new linear velocity of the center of mass.
See also
GetLinearVelocity(const Body& body).

◆ SetVelocity() [3/3]

void SetVelocity ( Body body,
const Velocity value 
)
related

Sets the body's velocity (linear and angular velocity).

Note
This function does nothing if this body is not speedable.
A non-zero velocity will awaken this body.
See also
GetVelocity(const Body& body), SetAwake, SetUnderActiveTime.

◆ Unawaken()

bool Unawaken ( Body body)
related

Puts the body to sleep if it's awake.

See also
Awaken(Body& body).

◆ UnsetAwake()

void UnsetAwake ( Body body)
related

Sets this body to asleep if sleeping is allowed.

If this body is allowed to sleep, this: sets the sleep state of the body to asleep, resets this body's under active time, and resets this body's velocity (linear and angular).

Postcondition
IsAwake(const Body&) function returns false.
This body's GetUnderActiveTime function returns zero.
This body's GetVelocity function returns zero linear and zero angular speed.
See also
IsAwake(const Body&), SetAwake(Body&).

◆ UnsetEnabled()

void UnsetEnabled ( Body body)
related

Unsets the enabled state.

See also
IsEnabled(const Body&), SetEnabled(Body&).

◆ UnsetImpenetrable()

void UnsetImpenetrable ( Body body)
related

Unsets the impenetrable status of this body.

Sets whether or not this body should be treated like a bullet for continuous collision detection.

See also
IsImpenetrable(const Body&), SetImpenetrable(Body&).

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