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

#include <Body.hpp>

Public Types

enum  Flag : FlagsType {
  e_islandFlag = FlagsType(0x0001), 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 Fixtures = std::vector< Fixture * >
 Container type for fixtures. More...
 
using KeyedJointPtr = std::pair< Body *, Joint * >
 Keyed joint pointer. More...
 
using Joints = std::vector< KeyedJointPtr >
 Container type for joints. More...
 
using Contacts = std::vector< KeyedContactPtr >
 Container type for contacts. More...
 
using FlagsType = std::uint16_t
 Flags type. More...
 

Public Member Functions

FixtureCreateFixture (const Shape &shape, const FixtureConf &def=GetDefaultFixtureConf(), bool resetMassData=true)
 Creates a fixture and attaches it to this body. More...
 
bool Destroy (Fixture *fixture, bool resetMassData=true)
 Destroys a fixture. More...
 
void DestroyFixtures ()
 Destroys fixtures. More...
 
void SetTransform (Length2 location, Angle angle)
 Sets the position of the body's origin and rotation. More...
 
Transformation GetTransformation () const noexcept
 Gets the body transform for the body's origin. More...
 
Length2 GetLocation () const noexcept
 Gets the world body origin location. More...
 
const SweepGetSweep () const noexcept
 Gets the body's sweep. More...
 
Angle GetAngle () const noexcept
 Get the angle. More...
 
Length2 GetWorldCenter () const noexcept
 Get the world position of the center of mass. More...
 
Length2 GetLocalCenter () const noexcept
 Gets the local position of the center of mass. 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 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...
 
InvRotInertia GetInvRotInertia () const noexcept
 Gets the inverse rotational inertia of the body. More...
 
void SetMassData (const MassData &massData)
 Set the mass properties to override the mass properties of the fixtures. More...
 
void ResetMassData ()
 Resets the mass data properties. 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...
 
void SetType (BodyType type)
 Sets the type of this body. More...
 
BodyType GetType () const noexcept
 Gets the type of this body. More...
 
bool IsSpeedable () const noexcept
 Is "speedable". More...
 
bool IsAccelerable () const noexcept
 Is "accelerable". More...
 
void SetBullet (bool flag) noexcept
 Sets the bullet status of this body. More...
 
bool IsImpenetrable () const noexcept
 Is this body treated like a bullet for continuous collision detection? More...
 
void SetSleepingAllowed (bool flag) noexcept
 
bool IsSleepingAllowed () const noexcept
 Gets whether or not this body allowed to sleep. More...
 
void SetAwake () noexcept
 Awakens this body. More...
 
void UnsetAwake () noexcept
 Sets this body to asleep if sleeping is allowed. More...
 
bool IsAwake () const noexcept
 Gets the awake/asleep state of this body. 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...
 
void SetEnabled (bool flag)
 Sets the enabled state of the body. More...
 
bool IsEnabled () const noexcept
 Gets the enabled/disabled state of the body. More...
 
void SetFixedRotation (bool flag)
 Sets this body to have fixed rotation. More...
 
bool IsFixedRotation () const noexcept
 Does this body have fixed rotation? More...
 
SizedRange< Fixtures::const_iterator > GetFixtures () const noexcept
 Gets the range of all constant fixtures attached to this body. More...
 
SizedRange< Fixtures::iterator > GetFixtures () noexcept
 Gets the range of all fixtures attached to this body. More...
 
SizedRange< Joints::const_iterator > GetJoints () const noexcept
 Gets the range of all joints attached to this body. More...
 
SizedRange< Joints::iterator > GetJoints () noexcept
 Gets the range of all joints attached to this body. More...
 
SizedRange< Contacts::const_iterator > GetContacts () const noexcept
 Gets the container of all contacts attached to this body. More...
 
void * GetUserData () const noexcept
 Gets the user data pointer that was provided in the body definition. More...
 
void SetUserData (void *data) noexcept
 Sets the user data. Use this to store your application specific data. More...
 
WorldGetWorld () const noexcept
 Gets the parent world of this body. More...
 
bool IsMassDataDirty () const noexcept
 Gets whether the mass data for this body is "dirty". More...
 

Static Public Member Functions

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

Static Public Attributes

static const PLAYRHO_CONSTEXPR auto InvalidIslandIndex = static_cast<BodyCounter>(-1)
 Invalid island index. More...
 

Friends

class BodyAtty
 

Related Functions

(Note that these are not member functions.)

AABB ComputeAABB (const Body &body)
 Computes the AABB for the given body. More...
 
MassData ComputeMassData (const Body &body) noexcept
 Computes the body's mass data. More...
 
MassData GetMassData (const Body &body) noexcept
 Gets the mass data 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...
 
Acceleration CalcGravitationalAcceleration (const Body &body) noexcept
 Calculates the gravitationally associated acceleration for the given body within its world. 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...
 
bool ShouldCollide (const Body &lhs, const Body &rhs) noexcept
 Should collide. More...
 
Position GetPosition1 (const Body &body) noexcept
 Gets the "position 1" Position information for the given body. More...
 
Mass GetMass (const Body &body) noexcept
 Gets the mass of the body. More...
 
void SetLinearAcceleration (Body &body, LinearAcceleration2 value) noexcept
 Sets the given linear acceleration of the given body. More...
 
void SetAngularAcceleration (Body &body, AngularAcceleration value) noexcept
 Sets the given angular acceleration of the given body. More...
 
void ApplyLinearAcceleration (Body &body, LinearAcceleration2 amount)
 Applies the given linear acceleration to the given body. More...
 
void SetForce (Body &body, Force2 force, Length2 point) noexcept
 Sets the given amount of force at the given point to the given body. More...
 
void ApplyForce (Body &body, Force2 force, Length2 point) noexcept
 Apply a force at a world point. More...
 
void ApplyForceToCenter (Body &body, Force2 force) noexcept
 Apply a force to the center of mass. More...
 
void SetTorque (Body &body, Torque torque) noexcept
 Sets the given amount of torque to the given body. More...
 
void ApplyTorque (Body &body, Torque torque) noexcept
 Applies a torque. 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...
 
Force2 GetCentripetalForce (const Body &body, Length2 axis)
 Gets the centripetal force necessary to put the body into an orbit having the given radius. 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...
 
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 SetLinearVelocity (Body &body, const LinearVelocity2 v) noexcept
 Sets the linear velocity of the center of mass. More...
 
void SetAngularVelocity (Body &body, AngularVelocity omega) 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. 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...
 
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. More...
 
Torque GetTorque (const Body &body) noexcept
 Gets the net torque that the given body is currently experiencing. 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...
 
BodyCounter GetWorldIndex (const Body *body) noexcept
 Gets the world index for the given body. More...
 
std::size_t GetFixtureCount (const Body &body) noexcept
 Gets the fixture count of the given body. More...
 
void RotateAboutWorldPoint (Body &body, Angle amount, Length2 worldPoint)
 Rotates a body a given amount around a point in world coordinates. More...
 
void RotateAboutLocalPoint (Body &body, Angle amount, Length2 localPoint)
 Rotates a body a given amount around a point in body local coordinates. More...
 
Length2 GetLocation (const Body &body) noexcept
 Gets the body's origin location. More...
 
Angle GetAngle (const Body &body) noexcept
 Gets the body's angle. More...
 
void SetLocation (Body &body, Length2 value) noexcept
 Sets the body's location. More...
 
void SetAngle (Body &body, Angle value) noexcept
 Sets the body's angular orientation. More...
 
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(Body*) 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, Fixture
Examples
Body.cpp, and World.cpp.

Definition at line 73 of file Body.hpp.

Member Typedef Documentation

◆ Fixtures

using playrho::d2::Body::Fixtures = std::vector<Fixture*>

Container type for fixtures.

Examples
Body.cpp.

Definition at line 78 of file Body.hpp.

◆ KeyedJointPtr

Keyed joint pointer.

Definition at line 81 of file Body.hpp.

◆ Joints

Container type for joints.

Examples
Body.cpp.

Definition at line 84 of file Body.hpp.

◆ Contacts

Container type for contacts.

Examples
Body.cpp.

Definition at line 87 of file Body.hpp.

◆ FlagsType

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

Flags type.

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

Definition at line 94 of file Body.hpp.

Member Enumeration Documentation

◆ Flag

Flag enumeration.

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

Island flag.

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.

Definition at line 98 of file Body.hpp.

Member Function Documentation

◆ GetFlags() [1/2]

Body::FlagsType playrho::d2::Body::GetFlags ( BodyType  type)
inlinestaticnoexcept

Gets the flags for the given value.

Examples
Body.cpp.

Definition at line 584 of file Body.hpp.

◆ GetFlags() [2/2]

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

Gets the flags for the given value.

Definition at line 38 of file Body.cpp.

◆ CreateFixture()

Fixture * playrho::d2::Body::CreateFixture ( const Shape shape,
const FixtureConf def = GetDefaultFixtureConf(),
bool  resetMassData = true 
)

Creates a fixture and attaches it to this body.

Creates a fixture for attaching a shape and other characteristics to this body. Fixtures automatically go away when this body is destroyed. Fixtures can also be manually removed and destroyed using the Destroy(Fixture*, bool), or DestroyFixtures() methods.

Note
This function should not be called if the world is locked.
Warning
This function is locked during callbacks.
Postcondition
After creating a new fixture, it will show up in the fixture enumeration returned by the GetFixtures() methods.
Parameters
shapeShareable shape definition. Its vertex radius must be less than the minimum or more than the maximum allowed by the body's world.
defInitial fixture settings. Friction and density must be >= 0. Restitution must be > -infinity and < infinity.
resetMassDataWhether or not to reset the mass data of the body.
Returns
Pointer to the created fixture.
Exceptions
WrongStateif called while the world is "locked".
InvalidArgumentif called for a shape with a vertex radius less than the minimum vertex radius.
InvalidArgumentif called for a shape with a vertex radius greater than the maximum vertex radius.
See also
Destroy, GetFixtures
Physical Entity Classes
Examples
Contact.cpp, and World.cpp.

Definition at line 113 of file Body.cpp.

◆ Destroy()

bool playrho::d2::Body::Destroy ( Fixture fixture,
bool  resetMassData = true 
)

Destroys a fixture.

Destroys a fixture previously created by the CreateFixture(const Shape&, const FixtureConf&, bool) method. This removes the fixture from the broad-phase and destroys all contacts associated with this fixture. All fixtures attached to a body are implicitly destroyed when the body is destroyed.

Warning
This function is locked during callbacks.
Note
Make sure to explicitly call ResetMassData() after fixtures have been destroyed if resetting the mass data is not requested via the reset mass data parameter.
Postcondition
After destroying a fixture, it will no longer show up in the fixture enumeration returned by the GetFixtures() methods.
Parameters
fixturethe fixture to be removed.
resetMassDataWhether or not to reset the mass data.
See also
CreateFixture, GetFixtures, ResetMassData.
Physical Entity Classes

Definition at line 119 of file Body.cpp.

◆ DestroyFixtures()

void playrho::d2::Body::DestroyFixtures ( )

Destroys fixtures.

Destroys all of the fixtures previously created for this body by the CreateFixture(const Shape&, const FixtureConf&, bool) method.

Note
This unconditionally calls the ResetMassData() method.
Postcondition
After this call, no fixtures will show up in the fixture enumeration returned by the GetFixtures() methods.
See also
CreateFixture, GetFixtures, ResetMassData.
Physical Entity Classes

Definition at line 128 of file Body.cpp.

◆ SetTransform()

void playrho::d2::Body::SetTransform ( Length2  location,
Angle  angle 
)

Sets the position of the body's origin and rotation.

This instantly adjusts the body to be at the new position and new orientation.

Warning
Manipulating a body's transform can cause non-physical behavior!
Note
Contacts are updated on the next call to World::Step.
Parameters
locationValid world location of the body's local origin. Behavior is undefined if value is invalid.
angleValid world rotation. Behavior is undefined if value is invalid.

Definition at line 291 of file Body.cpp.

◆ GetTransformation()

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

Gets the body transform for the body's origin.

Returns
the world transform of the body's origin.
See also
GetLocation.

Definition at line 607 of file Body.hpp.

◆ GetLocation()

Length2 playrho::d2::Body::GetLocation ( ) const
inlinenoexcept

Gets the world body 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
    GetTransformation.
Examples
Body.cpp, and World.cpp.

Definition at line 612 of file Body.hpp.

◆ GetSweep()

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

Gets the body's sweep.

Definition at line 617 of file Body.hpp.

◆ GetAngle()

Angle playrho::d2::Body::GetAngle ( ) const
inlinenoexcept

Get the angle.

Returns
the current world rotation angle.

Definition at line 622 of file Body.hpp.

◆ GetWorldCenter()

Length2 playrho::d2::Body::GetWorldCenter ( ) const
inlinenoexcept

Get the world position of the center of mass.

Definition at line 627 of file Body.hpp.

◆ GetLocalCenter()

Length2 playrho::d2::Body::GetLocalCenter ( ) const
inlinenoexcept

Gets the local position of the center of mass.

Definition at line 632 of file Body.hpp.

◆ GetVelocity()

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

Gets the velocity.

Definition at line 637 of file Body.hpp.

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

Definition at line 229 of file Body.cpp.

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

Definition at line 243 of file Body.cpp.

◆ GetLinearAcceleration()

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

Gets this body's linear acceleration.

Definition at line 821 of file Body.hpp.

◆ GetAngularAcceleration()

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

Gets this body's angular acceleration.

Definition at line 826 of file Body.hpp.

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

Definition at line 642 of file Body.hpp.

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

Definition at line 647 of file Body.hpp.

◆ SetMassData()

void playrho::d2::Body::SetMassData ( const MassData massData)

Set the mass properties to override the mass properties of the fixtures.

Note
This changes the center of mass position.
Creating or destroying fixtures can also alter the mass.
This function has no effect if the body isn't dynamic.
Parameters
massDatathe mass properties.

Definition at line 186 of file Body.cpp.

◆ ResetMassData()

void playrho::d2::Body::ResetMassData ( )

Resets the mass data properties.

This resets the mass data to the sum of the mass properties of the fixtures.

Note
This method must be called after calling CreateFixture to update the body mass data properties unless SetMassData is used.
See also
SetMassData.

Definition at line 138 of file Body.cpp.

◆ GetLinearDamping()

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

Gets the linear damping of the body.

Definition at line 652 of file Body.hpp.

◆ SetLinearDamping()

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

Sets the linear damping of the body.

Definition at line 657 of file Body.hpp.

◆ GetAngularDamping()

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

Gets the angular damping of the body.

Definition at line 662 of file Body.hpp.

◆ SetAngularDamping()

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

Sets the angular damping of the body.

Definition at line 667 of file Body.hpp.

◆ SetType()

void playrho::d2::Body::SetType ( playrho::BodyType  type)

Sets the type of this body.

Note
This may alter the mass and velocity.

Definition at line 108 of file Body.cpp.

◆ GetType()

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

Gets the type of this body.

Definition at line 596 of file Body.hpp.

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

Definition at line 757 of file Body.hpp.

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

Definition at line 762 of file Body.hpp.

◆ SetBullet()

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

Sets the bullet status of this body.

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

Definition at line 672 of file Body.hpp.

◆ IsImpenetrable()

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

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

Definition at line 684 of file Body.hpp.

◆ SetSleepingAllowed()

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

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

Definition at line 767 of file Body.hpp.

◆ IsSleepingAllowed()

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

Gets whether or not this body allowed to sleep.

Definition at line 781 of file Body.hpp.

◆ SetAwake()

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

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.

Definition at line 703 of file Body.hpp.

◆ UnsetAwake()

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

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.

Definition at line 714 of file Body.hpp.

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

Definition at line 724 of file Body.hpp.

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

Definition at line 729 of file Body.hpp.

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

Definition at line 734 of file Body.hpp.

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

Definition at line 742 of file Body.hpp.

◆ SetEnabled()

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

Sets the enabled state of the body.

A disabled body is not simulated and cannot be collided with or woken up. If you pass a flag of true, all fixtures will be added to the broad-phase. If you pass a flag of false, all fixtures will be removed from the broad-phase and all contacts will be destroyed. Fixtures and joints are otherwise unaffected.

Note
A disabled body is still owned by a World object and remains in the world's body container.
You may continue to create/destroy fixtures and joints on disabled bodies.
Fixtures on a disabled body are implicitly disabled and will not participate in collisions, ray-casts, or queries.
Joints connected to a disabled body are implicitly disabled.

Definition at line 309 of file Body.cpp.

◆ IsEnabled()

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

Gets the enabled/disabled state of the body.

Definition at line 747 of file Body.hpp.

◆ SetFixedRotation()

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

Sets this body to have fixed rotation.

Note
This causes the mass to be reset.

Definition at line 336 of file Body.cpp.

◆ IsFixedRotation()

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

Does this body have fixed rotation?

Definition at line 752 of file Body.hpp.

◆ GetFixtures() [1/2]

SizedRange< Body::Fixtures::iterator > playrho::d2::Body::GetFixtures ( ) const
inlinenoexcept

Gets the range of all constant fixtures attached to this body.

Definition at line 786 of file Body.hpp.

◆ GetFixtures() [2/2]

SizedRange<Fixtures::iterator> playrho::d2::Body::GetFixtures ( )
noexcept

Gets the range of all fixtures attached to this body.

◆ GetJoints() [1/2]

SizedRange< Body::Joints::iterator > playrho::d2::Body::GetJoints ( ) const
inlinenoexcept

Gets the range of all joints attached to this body.

Definition at line 796 of file Body.hpp.

◆ GetJoints() [2/2]

SizedRange<Joints::iterator> playrho::d2::Body::GetJoints ( )
noexcept

Gets the range of all joints attached to this body.

◆ GetContacts()

SizedRange< Body::Contacts::const_iterator > playrho::d2::Body::GetContacts ( ) const
inlinenoexcept

Gets the container of all contacts attached to this body.

Warning
This collection changes during the time step and you may miss some collisions if you don't use ContactListener.

Definition at line 806 of file Body.hpp.

◆ GetUserData()

void * playrho::d2::Body::GetUserData ( ) const
inlinenoexcept

Gets the user data pointer that was provided in the body definition.

Definition at line 816 of file Body.hpp.

◆ SetUserData()

void playrho::d2::Body::SetUserData ( void *  data)
inlinenoexcept

Sets the user data. Use this to store your application specific data.

Definition at line 811 of file Body.hpp.

◆ GetWorld()

World * playrho::d2::Body::GetWorld ( ) const
inlinenoexcept

Gets the parent world of this body.

Definition at line 842 of file Body.hpp.

◆ IsMassDataDirty()

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

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

Definition at line 857 of file Body.hpp.

Friends And Related Function Documentation

◆ BodyAtty

friend class BodyAtty
friend

Definition at line 454 of file Body.hpp.

◆ ComputeAABB()

AABB ComputeAABB ( const Body body)
related

Computes the AABB for the given body.

Definition at line 77 of file AABB.cpp.

◆ ComputeMassData()

MassData ComputeMassData ( const Body body)
related

Computes the body's mass data.

This basically accumulates the mass data over all fixtures.

Note
The center is the mass weighted sum of all fixture centers. Divide it by the mass to get the averaged center.
Returns
accumulated mass data for all fixtures associated with the given body.

Definition at line 187 of file MassData.cpp.

◆ GetMassData()

MassData GetMassData ( const Body body)
related

Gets the mass data of the body.

Returns
Data structure containing the mass, inertia, and center of the body.

Definition at line 206 of file MassData.cpp.

◆ GetAcceleration()

Acceleration GetAcceleration ( const Body body)
related

Gets the given body's acceleration.

Parameters
bodyBody whose acceleration should be returned.
Examples
Body.cpp, and World.cpp.

Definition at line 892 of file Body.hpp.

◆ SetAcceleration()

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.
Examples
Body.cpp, and World.cpp.

Definition at line 903 of file Body.hpp.

◆ CalcGravitationalAcceleration()

Acceleration CalcGravitationalAcceleration ( const Body body)
related

Calculates the gravitationally associated acceleration for the given body within its world.

Returns
Zero acceleration if given body is has no mass, else the acceleration of the body due to the gravitational attraction to the other bodies.
Examples
Body.cpp.

Definition at line 544 of file Body.cpp.

◆ Awaken()

bool Awaken ( Body body)
related

Awakens the body if it's asleep.

Examples
World.cpp.

Definition at line 917 of file Body.hpp.

◆ Unawaken()

bool Unawaken ( Body body)
related

Puts the body to sleep if it's awake.

Definition at line 929 of file Body.hpp.

◆ ShouldCollide()

bool ShouldCollide ( const Body lhs,
const Body rhs 
)
related

Should collide.

Determines whether a body should possibly be able to collide with the other body.

Returns
true if either body is dynamic and no joint prevents collision, false otherwise.

Definition at line 424 of file Body.cpp.

◆ GetPosition1()

Position GetPosition1 ( const Body body)
related

Gets the "position 1" Position information for the given body.

Definition at line 947 of file Body.hpp.

◆ 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, SetMassData
Examples
Body.cpp, and World.cpp.

Definition at line 957 of file Body.hpp.

◆ SetLinearAcceleration()

void SetLinearAcceleration ( Body body,
LinearAcceleration2  value 
)
related

Sets the given linear acceleration of the given body.

Definition at line 965 of file Body.hpp.

◆ SetAngularAcceleration()

void SetAngularAcceleration ( Body body,
AngularAcceleration  value 
)
related

Sets the given angular acceleration of the given body.

Definition at line 972 of file Body.hpp.

◆ ApplyLinearAcceleration()

void ApplyLinearAcceleration ( Body body,
LinearAcceleration2  amount 
)
related

Applies the given linear acceleration to the given body.

Examples
Body.cpp.

Definition at line 979 of file Body.hpp.

◆ SetForce()

void SetForce ( Body body,
Force2  force,
Length2  point 
)
related

Sets the given amount of force at the given point to the given body.

Definition at line 986 of file Body.hpp.

◆ ApplyForce()

void ApplyForce ( Body body,
Force2  force,
Length2  point 
)
related

Apply a force at a world point.

Note
If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity.
Non-zero forces wakes up the body.
Parameters
bodyBody to apply the force to.
forceWorld force vector.
pointWorld position of the point of application.

Definition at line 1004 of file Body.hpp.

◆ ApplyForceToCenter()

void ApplyForceToCenter ( Body body,
Force2  force 
)
related

Apply a force to the center of mass.

Note
Non-zero forces wakes up the body.
Parameters
bodyBody to apply the force to.
forceWorld force vector.
Examples
World.cpp.

Definition at line 1022 of file Body.hpp.

◆ SetTorque()

void SetTorque ( Body body,
Torque  torque 
)
related

Sets the given amount of torque to the given body.

Definition at line 1031 of file Body.hpp.

◆ ApplyTorque()

void ApplyTorque ( Body body,
Torque  torque 
)
related

Applies a torque.

Note
This affects the angular velocity without affecting the linear velocity of the center of mass.
Non-zero forces wakes up the body.
Parameters
bodyBody to apply the torque to.
torqueabout the z-axis (out of the screen).

Definition at line 1046 of file Body.hpp.

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

Definition at line 1063 of file Body.hpp.

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

Definition at line 1077 of file Body.hpp.

◆ GetCentripetalForce()

Force2 GetCentripetalForce ( const Body body,
Length2  axis 
)
related

Gets the centripetal force necessary to put the body into an orbit having the given radius.

Examples
Body.cpp.

Definition at line 528 of file Body.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.
Examples
Body.cpp.

Definition at line 1094 of file Body.hpp.

◆ GetLocalRotInertia()

RotInertia GetLocalRotInertia ( const Body body)
related

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

Returns
the rotational inertia.

Definition at line 1102 of file Body.hpp.

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

Definition at line 1112 of file Body.hpp.

◆ GetAngularVelocity()

AngularVelocity GetAngularVelocity ( const Body body)
related

Gets the angular velocity.

Parameters
bodyBody to get the angular velocity for.
Returns
the angular velocity.

Definition at line 1121 of file Body.hpp.

◆ SetLinearVelocity()

void SetLinearVelocity ( Body body,
const LinearVelocity2  v 
)
related

Sets the linear velocity of the center of mass.

Parameters
bodyBody to set the linear velocity of.
vthe new linear velocity of the center of mass.
Examples
Body.cpp.

Definition at line 1130 of file Body.hpp.

◆ SetAngularVelocity()

void SetAngularVelocity ( Body body,
AngularVelocity  omega 
)
related

Sets the angular velocity.

Parameters
bodyBody to set the angular velocity of.
omegathe new angular velocity.

Definition at line 1139 of file Body.hpp.

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

Definition at line 1149 of file Body.hpp.

◆ GetWorldVector() [1/2]

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.

Definition at line 1159 of file Body.hpp.

◆ GetWorldVector() [2/2]

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

Gets the world vector for the given local vector from the given body's transformation.

Definition at line 1166 of file Body.hpp.

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

Definition at line 1176 of file Body.hpp.

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

Definition at line 1186 of file Body.hpp.

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

Definition at line 1196 of file Body.hpp.

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

Definition at line 1211 of file Body.hpp.

◆ GetForce()

Force2 GetForce ( const Body body)
related

Gets the net force that the given body is currently experiencing.

Definition at line 1219 of file Body.hpp.

◆ GetTorque()

Torque GetTorque ( const Body body)
related

Gets the net torque that the given body is currently experiencing.

Definition at line 1226 of file Body.hpp.

◆ GetVelocity()

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.

Definition at line 458 of file Body.cpp.

◆ GetWorldIndex()

BodyCounter GetWorldIndex ( const Body body)
related

Gets the world index for the given body.

Examples
Body.cpp.

Definition at line 440 of file Body.cpp.

◆ GetFixtureCount()

std::size_t GetFixtureCount ( const Body body)
related

Gets the fixture count of the given body.

Examples
Body.cpp, and World.cpp.

Definition at line 504 of file Body.cpp.

◆ RotateAboutWorldPoint()

void RotateAboutWorldPoint ( Body body,
Angle  amount,
Length2  worldPoint 
)
related

Rotates a body a given amount around a point in world coordinates.

This changes both the linear and angular positions of the body.

Note
Manipulating a body's position this way may cause non-physical behavior.
Parameters
bodyBody to rotate.
amountAmount to rotate body by (in counter-clockwise direction).
worldPointPoint in world coordinates.
Examples
Body.cpp.

Definition at line 510 of file Body.cpp.

◆ RotateAboutLocalPoint()

void RotateAboutLocalPoint ( Body body,
Angle  amount,
Length2  localPoint 
)
related

Rotates a body a given amount around a point in body local coordinates.

This changes both the linear and angular positions of the body.

Note
Manipulating a body's position this way may cause non-physical behavior.
This is a convenience function that translates the local point into world coordinates and then calls the RotateAboutWorldPoint function.
Parameters
bodyBody to rotate.
amountAmount to rotate body by (in counter-clockwise direction).
localPointPoint in local coordinates.
Examples
Body.cpp.

Definition at line 523 of file Body.cpp.

◆ 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
Body.cpp, and World.cpp.

Definition at line 1287 of file Body.hpp.

◆ GetAngle()

Angle GetAngle ( const Body body)
related

Gets the body's angle.

Returns
Body's angle relative to its World.
Examples
Body.cpp, and World.cpp.

Definition at line 1295 of file Body.hpp.

◆ SetLocation()

void SetLocation ( Body body,
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
bodyBody to move.
valueValid world location of the body's local origin. Behavior is undefined if value is invalid.
See also
Body::SetTransform
Examples
Body.cpp, and World.cpp.

Definition at line 1328 of file Body.hpp.

◆ 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
bodyBody to move.
valueValid world angle of the body's local origin. Behavior is undefined if value is invalid.
See also
Body::SetTransform
Examples
Body.cpp.

Definition at line 1341 of file Body.hpp.

◆ GetBodyConf()

BodyConf GetBodyConf ( const Body body)
related

Gets the body definition for the given body.

Parameters
bodyBody to get the BodyConf for.

Definition at line 28 of file BodyConf.cpp.

Member Data Documentation

◆ InvalidIslandIndex

const PLAYRHO_CONSTEXPR auto playrho::d2::Body::InvalidIslandIndex = static_cast<BodyCounter>(-1)
static

Invalid island index.

Definition at line 90 of file Body.hpp.


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