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

Physical entity that exists within a World. More...

#include <Body.hpp>

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

Public Types

enum  Flag : FlagsType {
  e_awakeFlag = FlagsType(0x0002), e_autoSleepFlag = FlagsType(0x0004), e_impenetrableFlag = FlagsType(0x0008), e_fixedRotationFlag = FlagsType(0x0010),
  e_enabledFlag = FlagsType(0x0020), e_velocityFlag = FlagsType(0x0080), e_accelerationFlag = FlagsType(0x0100), e_massDataDirtyFlag = FlagsType(0x0200)
}
 Flag enumeration. More...
 
using FlagsType = std::uint16_t
 Flags type. More...
 

Public Member Functions

 Body (const BodyConf &bd=GetDefaultBodyConf()) noexcept
 Initializing constructor. More...
 
const TransformationGetTransformation () const noexcept
 Gets the body transform for the body's origin. More...
 
void SetTransformation (const Transformation &value) noexcept
 Sets the body's transformation. More...
 
const SweepGetSweep () const noexcept
 Gets the body's sweep. More...
 
Velocity GetVelocity () const noexcept
 Gets the velocity. More...
 
void SetVelocity (const Velocity &velocity) noexcept
 Sets the body's velocity (linear and angular velocity). More...
 
void JustSetVelocity (Velocity value) noexcept
 Sets the body's velocity. More...
 
void SetAcceleration (LinearAcceleration2 linear, AngularAcceleration angular) noexcept
 Sets the linear and rotational accelerations on this body. More...
 
LinearAcceleration2 GetLinearAcceleration () const noexcept
 Gets this body's linear acceleration. More...
 
AngularAcceleration GetAngularAcceleration () const noexcept
 Gets this body's angular acceleration. More...
 
InvMass GetInvMass () const noexcept
 Gets the inverse total mass of the body. More...
 
void SetInvMass (InvMass v) noexcept
 Sets the inverse mass. More...
 
InvRotInertia GetInvRotInertia () const noexcept
 Gets the inverse rotational inertia of the body. More...
 
void SetInvRotInertia (InvRotInertia v) noexcept
 Sets the inverse rotational inertia. More...
 
Frequency GetLinearDamping () const noexcept
 Gets the linear damping of the body. More...
 
void SetLinearDamping (NonNegative< Frequency > linearDamping) noexcept
 Sets the linear damping of the body. More...
 
Frequency GetAngularDamping () const noexcept
 Gets the angular damping of the body. More...
 
void SetAngularDamping (NonNegative< Frequency > angularDamping) noexcept
 Sets the angular damping of the body. More...
 
BodyType GetType () const noexcept
 Gets the type of this body. More...
 
void SetType (BodyType value) noexcept
 Sets the type of this body. More...
 
bool IsSpeedable () const noexcept
 Is "speedable". More...
 
bool IsAccelerable () const noexcept
 Is "accelerable". More...
 
bool IsImpenetrable () const noexcept
 Is this body treated like a bullet for continuous collision detection? More...
 
void SetImpenetrable () noexcept
 Sets the impenetrable status of this body. More...
 
void UnsetImpenetrable () noexcept
 Unsets the impenetrable status of this body. More...
 
bool IsSleepingAllowed () const noexcept
 Gets whether or not this body allowed to sleep. More...
 
void SetSleepingAllowed (bool flag) noexcept
 Sets whether or not this body is allowed to sleep. More...
 
bool IsAwake () const noexcept
 Gets the awake/asleep state of this body. More...
 
void SetAwake () noexcept
 Awakens this body. More...
 
void UnsetAwake () noexcept
 Sets this body to asleep if sleeping is allowed. More...
 
Time GetUnderActiveTime () const noexcept
 Gets this body's under-active time value. More...
 
void SetUnderActiveTime (Time value) noexcept
 Sets the "under-active" time to the given value. More...
 
void ResetUnderActiveTime () noexcept
 Resets the under-active time for this body. More...
 
bool IsFixedRotation () const noexcept
 Does this body have fixed rotation? More...
 
void SetFixedRotation (bool flag)
 Sets this body to have fixed rotation. More...
 
void SetAwakeFlag () noexcept
 Sets the body's awake flag. More...
 
void UnsetAwakeFlag () noexcept
 Unsets the body's awake flag. More...
 
bool IsMassDataDirty () const noexcept
 Gets whether the mass data for this body is "dirty". More...
 
void SetMassDataDirty () noexcept
 Sets this body to have the mass data dirty state. More...
 
void UnsetMassDataDirty () noexcept
 Unsets the body from being in the mass data dirty state. More...
 
bool IsEnabled () const noexcept
 Gets the enabled/disabled state of the body. More...
 
void SetEnabled () noexcept
 Sets the enabled state. More...
 
void UnsetEnabled () noexcept
 Unsets the enabled flag. More...
 
void SetSweep (const Sweep &value) noexcept
 Sets the sweep value of the given 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 ResetAlpha0 () noexcept
 Resets the given body's "alpha-0" value. More...
 
void Restore (const Sweep &value) noexcept
 Restores the given body's sweep to the given sweep value. More...
 
void Advance0 (Real value) noexcept
 Calls the body sweep's Advance0 method to advance to the given value. More...
 
void Advance (Real value) noexcept
 Advances the body by a given time ratio. More...
 

Static Public Member Functions

static FlagsType GetFlags (BodyType type) noexcept
 Gets the flags for the given value.
 
static FlagsType GetFlags (const BodyConf &bd) noexcept
 Gets the flags for the given value. More...
 

Private Attributes

Transformation m_xf
 Transformation for body origin. More...
 
Sweep m_sweep
 Sweep motion for CCD. 36-bytes. More...
 
FlagsType m_flags = 0
 Flags. 2-bytes.
 
LinearVelocity2 m_linearVelocity = LinearVelocity2{}
 Linear velocity. More...
 
LinearAcceleration2 m_linearAcceleration = LinearAcceleration2{}
 Linear acceleration. More...
 
AngularVelocity m_angularVelocity = AngularVelocity{}
 Angular velocity. More...
 
AngularAcceleration m_angularAcceleration = AngularAcceleration{0}
 Angular acceleration. More...
 
InvMass m_invMass = 0
 Inverse mass of the body. More...
 
InvRotInertia m_invRotI = 0
 Inverse rotational inertia about the center of mass. More...
 
NonNegative< Frequencym_linearDamping {}
 Linear damping. 4-bytes.
 
NonNegative< Frequencym_angularDamping {}
 Angular damping. 4-bytes.
 
Time m_underActiveTime = 0
 Under-active time. More...
 

Related Functions

(Note that these are not member functions.)

BodyType GetType (const Body &body) noexcept
 Gets the type of this body. More...
 
void SetType (Body &body, BodyType value) noexcept
 Sets the type of this body. More...
 
bool IsSpeedable (const Body &body) noexcept
 Is "speedable". More...
 
bool IsAccelerable (const Body &body) noexcept
 Is "accelerable". More...
 
bool IsImpenetrable (const Body &body) noexcept
 Is this body treated like a bullet for continuous collision detection? More...
 
void SetImpenetrable (Body &body) noexcept
 Sets the impenetrable status of this body. More...
 
void UnsetImpenetrable (Body &body) noexcept
 Unsets the impenetrable status of this body. More...
 
bool IsSleepingAllowed (const Body &body) noexcept
 Gets whether or not this body allowed to sleep. More...
 
void SetSleepingAllowed (Body &body, bool value) noexcept
 You can disable sleeping on this body. If you disable sleeping, the body will be woken. More...
 
bool IsEnabled (const Body &body) noexcept
 Gets the enabled/disabled state of the body. More...
 
void SetEnabled (Body &body) noexcept
 Sets the enabled state. More...
 
void UnsetEnabled (Body &body) noexcept
 Unsets the enabled state. More...
 
void SetEnabled (Body &body, bool value) noexcept
 Sets the enabled state to the given value. More...
 
bool IsAwake (const Body &body) noexcept
 Gets the awake/asleep state of this body. More...
 
void SetAwake (Body &body) noexcept
 Awakens this body. More...
 
void UnsetAwake (Body &body) noexcept
 Sets this body to asleep if sleeping is allowed. More...
 
Transformation GetTransformation (const Body &body) noexcept
 Gets the body's transformation. More...
 
void SetTransformation (Body &body, Transformation value) noexcept
 Sets the body's transformation. More...
 
Length2 GetLocation (const Body &body) noexcept
 Gets the body's origin location. More...
 
const SweepGetSweep (const Body &body) noexcept
 Gets the body's sweep. More...
 
void SetSweep (Body &body, const Sweep &value) noexcept
 Sets the sweep value of the given body. More...
 
Position GetPosition1 (const Body &body) noexcept
 Gets the "position 1" Position information for the given body.
 
Angle GetAngle (const Body &body) noexcept
 Gets the body's angle. More...
 
Position GetPosition (const Body &body) noexcept
 Gets the body's position.
 
Time GetUnderActiveTime (const Body &body) noexcept
 Gets the given body's under-active time. More...
 
bool IsFixedRotation (const Body &body) noexcept
 Does this body have fixed rotation? More...
 
void SetFixedRotation (Body &body, bool value)
 Sets this body to have fixed rotation. More...
 
bool IsMassDataDirty (const Body &body) noexcept
 Gets whether the mass data for this body is "dirty".
 
InvMass GetInvMass (const Body &body) noexcept
 Gets the inverse total mass of the body. More...
 
InvRotInertia GetInvRotInertia (const Body &body) noexcept
 Gets the inverse rotational inertia of the body. More...
 
Frequency GetLinearDamping (const Body &body) noexcept
 Gets the linear damping of the body. More...
 
void SetLinearDamping (Body &body, NonNegative< Frequency > value) noexcept
 Sets the linear damping of the body. More...
 
Frequency GetAngularDamping (const Body &body) noexcept
 Gets the angular damping of the body. More...
 
void SetAngularDamping (Body &body, NonNegative< Frequency > value) noexcept
 Sets the angular damping of the body. More...
 
Acceleration GetAcceleration (const Body &body) noexcept
 Gets the given body's acceleration. More...
 
void SetAcceleration (Body &body, Acceleration value) noexcept
 Sets the accelerations on the given body. More...
 
LinearAcceleration2 GetLinearAcceleration (const Body &body) noexcept
 Gets this body's linear acceleration. More...
 
AngularAcceleration GetAngularAcceleration (const Body &body) noexcept
 Gets this body's angular acceleration. More...
 
bool Awaken (Body &body) noexcept
 Awakens the body if it's asleep. More...
 
bool Unawaken (Body &body) noexcept
 Puts the body to sleep if it's awake. More...
 
Mass GetMass (const Body &body) noexcept
 Gets the mass of the body. More...
 
void SetMass (Body &body, Mass mass)
 Sets the mass of the given body.
 
void SetAcceleration (Body &body, LinearAcceleration2 linear, AngularAcceleration angular) noexcept
 Sets the linear and rotational accelerations on this body. More...
 
void SetAcceleration (Body &body, LinearAcceleration2 value) noexcept
 Sets the given linear acceleration of the given body. More...
 
void SetAcceleration (Body &body, AngularAcceleration value) noexcept
 Sets the given angular acceleration of the given body. More...
 
RotInertia GetRotInertia (const Body &body) noexcept
 Gets the rotational inertia of the body. More...
 
RotInertia GetLocalRotInertia (const Body &body) noexcept
 Gets the rotational inertia of the body about the local origin. More...
 
Velocity GetVelocity (const Body &body) noexcept
 Gets the velocity. More...
 
void SetVelocity (Body &body, const Velocity &value) noexcept
 Sets the body's velocity (linear and angular velocity). More...
 
LinearVelocity2 GetLinearVelocity (const Body &body) noexcept
 Gets the linear velocity of the center of mass. More...
 
AngularVelocity GetAngularVelocity (const Body &body) noexcept
 Gets the angular velocity. More...
 
void SetVelocity (Body &body, LinearVelocity2 value) noexcept
 Sets the linear velocity of the center of mass. More...
 
void SetVelocity (Body &body, AngularVelocity value) noexcept
 Sets the angular velocity. 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.
 
Length2 GetLocalPoint (const Body &body, const Length2 worldPoint) noexcept
 Gets a local point relative to the body's origin given a world point. More...
 
UnitVec GetLocalVector (const Body &body, const UnitVec uv) noexcept
 Gets a locally oriented unit vector given a world oriented unit vector. More...
 
LinearVelocity2 GetLinearVelocityFromWorldPoint (const Body &body, const Length2 worldPoint) noexcept
 Gets the linear velocity from a world point attached to this body. More...
 
LinearVelocity2 GetLinearVelocityFromLocalPoint (const Body &body, const Length2 localPoint) noexcept
 Gets the linear velocity from a local point. More...
 
Force2 GetForce (const Body &body) noexcept
 Gets the net force that the given body is currently experiencing.
 
Torque GetTorque (const Body &body) noexcept
 Gets the net torque that the given body is currently experiencing.
 
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...
 
void ApplyLinearImpulse (Body &body, Momentum2 impulse, Length2 point) noexcept
 Applies an impulse at a point. More...
 
void ApplyAngularImpulse (Body &body, AngularMomentum impulse) noexcept
 Applies an angular impulse. More...
 
bool operator== (const Body &lhs, const Body &rhs)
 Equals operator.
 
bool operator!= (const Body &lhs, const Body &rhs)
 Not-equals operator.
 
BodyConf GetBodyConf (const Body &body) noexcept
 Gets the body definition for the given body. More...
 

Detailed Description

Physical entity that exists within a World.

A rigid body entity created or destroyed through a World instance. These have physical properties like: position, velocity, acceleration, and mass.

Invariant
Only bodies that allow sleeping, can be put to sleep.
Only "speedable" bodies can be awake.
Only "speedable" bodies can have non-zero velocities.
Only "accelerable" bodies can have non-zero accelerations.
Only "accelerable" bodies can have non-zero "under-active" times.
Note
Create these using the World::CreateBody method.
Destroy these using the World::Destroy(BodyID) method.
From a memory management perspective, bodies own Fixture instances.
On a 64-bit architecture with 4-byte Real, this data structure is at least 192-bytes large.
See also
World, BodyConf.
Examples
Body.cpp.

Member Typedef Documentation

◆ FlagsType

using playrho::d2::Body::FlagsType = std::uint16_t

Flags type.

Note
For internal use. Made public to facilitate unit testing.

Member Enumeration Documentation

◆ Flag

Flag enumeration.

Note
For internal use. Made public to facilitate unit testing.
Enumerator
e_awakeFlag 

Awake flag.

e_autoSleepFlag 

Auto sleep flag.

e_impenetrableFlag 

Impenetrable flag.

Indicates whether CCD should be done for this body. All static and kinematic bodies have this flag enabled.

e_fixedRotationFlag 

Fixed rotation flag.

e_enabledFlag 

Enabled flag.

e_velocityFlag 

Velocity flag.

Set this to enable changes in position due to velocity. Bodies with this set are "speedable" - either kinematic or dynamic bodies.

e_accelerationFlag 

Acceleration flag.

Set this to enable changes in velocity due to physical properties (like forces). Bodies with this set are "accelerable" - dynamic bodies.

e_massDataDirtyFlag 

Mass Data Dirty Flag.

Constructor & Destructor Documentation

◆ Body()

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

Initializing constructor.

Note
To create a body within a world, use World::CreateBody.
Parameters
bdConfiguration data for the body to construct.
Postcondition
The internal m_flags state will be set to the value of GetFlags(const BodyConf&) given bd.
GetLinearDamping() will return the value of bd.linearDamping.
GetAngularDamping() will return the value of bd.angularDamping.
GetInvMass() will return Real(0)/Kilogram if bd.type != BodyType::Dynamic, otherwise it will return Real(1)/Kilogram.
GetTransformation() will return the value of playrho::d2::GetTransformation(const BodyConf&) given bd.
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 the values of bd.linearAcceleration and bd.angularAcceleration.
See also
GetFlags(const BodyConf&).
GetLinearDamping, GetAngularDamping, GetInvMass, GetTransformation, GetVelocity, GetAcceleration.
World::CreateBody.

Member Function Documentation

◆ Advance()

void playrho::d2::Body::Advance ( Real  value)
inlinenoexcept

Advances the body by a given time ratio.

This method:

  1. advances the body's sweep to the given time ratio;
  2. updates the body's sweep positions (linear and angular) to the advanced ones; and
  3. updates the body's transform to the new sweep one settings.
    Parameters
    valueValid new time factor in [0,1) to advance the sweep to.
    See also
    GetSweep, SetSweep, GetTransofmration, SetTransformation.

◆ Advance0()

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

Calls the body sweep's Advance0 method to advance to the given value.

See also
GetSweep.

◆ GetAngularAcceleration()

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

Gets this body's angular acceleration.

See also
SetAcceleration.

◆ GetAngularDamping()

Frequency playrho::d2::Body::GetAngularDamping ( ) const
inlinenoexcept

Gets the angular damping of the body.

See also
SetAngularDamping.

◆ GetFlags()

Body::FlagsType playrho::d2::Body::GetFlags ( const BodyConf bd)
staticnoexcept

Gets the flags for the given value.

Returns
Value formed in part from calling GetFlags(bd.type).
See also
GetFlags(BodyType).

◆ GetInvMass()

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. 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
SetInvMass.

◆ GetInvRotInertia()

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. 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
SetInvRotInertia.

◆ GetLinearAcceleration()

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

Gets this body's linear acceleration.

See also
SetAcceleration.

◆ GetLinearDamping()

Frequency playrho::d2::Body::GetLinearDamping ( ) const
inlinenoexcept

Gets the linear damping of the body.

See also
SetLinearDamping.

◆ GetSweep()

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

Gets the body's sweep.

See also
SetSweep.

Referenced by playrho::d2::WorldImpl::SetBody().

◆ 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. Restitution and friction values of the body's fixtures when they experience collisions.
    Returns
    the world transform of the body's origin.
    See also
    SetTransformation.

◆ GetType()

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

Gets the type of this body.

See also
SetType.

Referenced by playrho::d2::WorldImpl::SetBody().

◆ 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, ResetUnderActiveTime.

◆ GetVelocity()

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

Gets the velocity.

See also
SetVelocity.

◆ 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.

◆ 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
GetType, SetType, SetImpenetrable, UnsetImpenetrable.

◆ IsMassDataDirty()

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

Gets whether the mass data for this body is "dirty".

See also
SetMassDataDirty, UnsetMassDataDirty.

◆ IsSleepingAllowed()

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

Gets whether or not this body allowed to sleep.

See also
SetSleepingAllowed.

Referenced by UnsetAwake(), and UnsetAwakeFlag().

◆ 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.

Referenced by Advance(), Advance0(), SetAwake(), SetAwakeFlag(), SetPosition0(), SetPosition1(), SetSweep(), UnsetAwake(), and UnsetAwakeFlag().

◆ JustSetVelocity()

void playrho::d2::Body::JustSetVelocity ( Velocity  value)
inlinenoexcept

Sets the body's velocity.

Note
This sets what GetVelocity() returns.
See also
GetVelocity.
Examples
Body.cpp.

◆ ResetAlpha0()

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

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

See also
GetSweep.

◆ ResetUnderActiveTime()

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

Resets the under-active time for this body.

Note
This has performance degrading potential and is best not called unless the caller is certain that it should be.
See also
GetUnderActiveTime.

Referenced by SetAwake().

◆ Restore()

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

Restores the given body's sweep to the given sweep value.

See also
GetSweep, SetSweep.

◆ SetAcceleration()

void playrho::d2::Body::SetAcceleration ( 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.
See also
GetLinearAcceleration, GetAngularAcceleration.
Examples
Body.cpp.

◆ SetAngularDamping()

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

Sets the angular damping of the body.

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 method has no effect otherwise.

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

◆ SetAwakeFlag()

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

Sets the body's awake flag.

This is done unconditionally.

Note
This should not be called unless the body is "speedable".
Warning
Behavior is undefined if called for a body that is not "speedable".
See also
UnsetAwakeFlag.

Referenced by SetAwake().

◆ SetEnabled()

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

Sets the enabled state.

See also
IsEnabled.

◆ SetFixedRotation()

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

Sets this body to have fixed rotation.

Note
This causes the mass to be reset.
See also
IsFixedRotation.

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

◆ SetImpenetrable()

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

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, GetType, SetType.

◆ SetInvMass()

void playrho::d2::Body::SetInvMass ( InvMass  v)
inlinenoexcept

Sets the inverse mass.

See also
GetInvMass

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

◆ SetInvRotInertia()

void playrho::d2::Body::SetInvRotInertia ( InvRotInertia  v)
inlinenoexcept

Sets the inverse rotational inertia.

See also
GetInvRotInertia.
Examples
Body.cpp.

◆ SetLinearDamping()

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

Sets the linear damping of the body.

See also
GetLinearDamping.

◆ SetMassDataDirty()

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

Sets this body to have the mass data dirty state.

See also
IsMassDataDirty.

◆ SetPosition0()

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

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

See also
GetSweep, SetSweep.

◆ SetPosition1()

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

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

See also
GetSweep, SetSweep.

Referenced by playrho::d2::WorldImpl::UpdateBody().

◆ SetSleepingAllowed()

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

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 sweep value of the given body.

See also
GetSweep.
Examples
Body.cpp.

Referenced by Restore().

◆ SetTransformation()

void playrho::d2::Body::SetTransformation ( const Transformation value)
inlinenoexcept

Sets the body's transformation.

Note
SetSweep may also need to be called.
Postcondition
GetTransformation() will return the value set.
See also
GetTransformation, GetSweep, SetSweep.
Examples
Body.cpp.

Referenced by Restore(), and playrho::d2::WorldImpl::UpdateBody().

◆ SetType()

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

Sets the type of this body.

See also
GetType.
Examples
Body.cpp.

◆ 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.

Warning
Behavior is undefined for negative values.
Note
A non-zero time is only valid for an "accelerable" body.
See also
GetUnderActiveTime.

◆ SetVelocity()

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

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

Note
This method does nothing if this body is not speedable.
A non-zero velocity will awaken this body.
See also
SetAwake, SetUnderActiveTime, GetVelocity.
Examples
Body.cpp.

◆ 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
This body's IsAwake method returns false.
This body's GetUnderActiveTime method returns zero.
This body's GetVelocity method returns zero linear and zero angular speed.
See also
IsAwake.

◆ UnsetAwakeFlag()

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

Unsets the body's awake flag.

See also
SetAwakeFlag.

Referenced by UnsetAwake().

◆ UnsetEnabled()

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

Unsets the enabled flag.

See also
IsEnabled.

◆ UnsetImpenetrable()

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

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, GetType, SetType.

◆ UnsetMassDataDirty()

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

Unsets the body from being in the mass data dirty state.

See also
IsMassDataDirty.

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,
Momentum2  impulse,
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.
Examples
World.cpp.

◆ GetAngularAcceleration()

AngularAcceleration GetAngularAcceleration ( const Body body)
related

◆ GetAngularDamping()

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

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
SetInvMass.

◆ GetInvRotInertia()

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

◆ GetLinearDamping()

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

◆ 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::SetInvRotInertia.

◆ 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 fixtures when they experience collisions.
    Returns
    World location of the body's origin.
    See also
    GetAngle.
Examples
World.cpp.

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

◆ 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::SetInvRotInertia.

◆ GetSweep()

const Sweep & GetSweep ( const Body body)
related

Gets the body's sweep.

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

◆ GetTransformation()

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

◆ 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

Gets the velocity.

See also
SetVelocity(Body& body, const Velocity& value).
Examples
World.cpp.

◆ 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.

Warning
Behavior is undefined if the given elapsed time is an invalid value (like NaN).
Parameters
bodyBody to get the velocity for.
hTime elapsed to get velocity for. Behavior is undefined if this value is invalid.

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

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

◆ 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.

Examples
World.cpp.

◆ SetAcceleration() [1/4]

void SetAcceleration ( Body body,
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() [2/4]

void SetAcceleration ( Body body,
AngularAcceleration  value 
)
related

Sets the given angular acceleration of the given body.

See also
GetAcceleration(const Body& body).

◆ SetAcceleration() [3/4]

void SetAcceleration ( Body body,
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,
LinearAcceleration2  value 
)
related

Sets the given linear acceleration of the given body.

See also
GetAcceleration(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 method has no effect otherwise.

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

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

◆ 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,
Transformation  value 
)
related

Sets the body's transformation.

Note
This sets what GetLocation returns.
See also
GetTransformation(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 Velocity value 
)
related

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

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

◆ SetVelocity() [3/3]

void SetVelocity ( Body body,
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).

◆ 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
This body's IsAwake method returns false.
This body's GetUnderActiveTime method returns zero.
This body's GetVelocity method 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&).

Member Data Documentation

◆ m_angularAcceleration

AngularAcceleration playrho::d2::Body::m_angularAcceleration = AngularAcceleration{0}
private

Angular acceleration.

Note
4-bytes.

Referenced by GetAngularAcceleration().

◆ m_angularVelocity

AngularVelocity playrho::d2::Body::m_angularVelocity = AngularVelocity{}
private

Angular velocity.

Note
4-bytes.

Referenced by GetVelocity(), JustSetVelocity(), SetFixedRotation(), and UnsetAwake().

◆ m_invMass

InvMass playrho::d2::Body::m_invMass = 0
private

Inverse mass of the body.

A non-negative value. Can only be zero for non-accelerable bodies.

Note
4-bytes.

Referenced by GetInvMass(), and SetInvMass().

◆ m_invRotI

InvRotInertia playrho::d2::Body::m_invRotI = 0
private

Inverse rotational inertia about the center of mass.

A non-negative value.

Note
4-bytes.

Referenced by GetInvRotInertia(), and SetInvRotInertia().

◆ m_linearAcceleration

LinearAcceleration2 playrho::d2::Body::m_linearAcceleration = LinearAcceleration2{}
private

Linear acceleration.

Note
8-bytes.

Referenced by GetLinearAcceleration().

◆ m_linearVelocity

LinearVelocity2 playrho::d2::Body::m_linearVelocity = LinearVelocity2{}
private

Linear velocity.

Note
8-bytes.

Referenced by GetVelocity(), JustSetVelocity(), and UnsetAwake().

◆ m_sweep

Sweep playrho::d2::Body::m_sweep
private

Sweep motion for CCD. 36-bytes.

Note
This is something of a non-essential part.
Todo:
Consider refactoring this data out of this class and into the world implementation.

Referenced by Advance(), Advance0(), GetSweep(), ResetAlpha0(), SetPosition0(), SetPosition1(), and SetSweep().

◆ m_underActiveTime

Time playrho::d2::Body::m_underActiveTime = 0
private

Under-active time.

A body under-active for enough time should have their awake flag unset. I.e. if a body is under-active for long enough, it should go to sleep.

Note
4-bytes.

Referenced by GetUnderActiveTime(), ResetUnderActiveTime(), and UnsetAwake().

◆ m_xf

Transformation playrho::d2::Body::m_xf
private

Transformation for body origin.

Note
Also availble from GetTransform1(m_sweep).
16-bytes.

Referenced by Advance(), and GetTransformation().


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