Box2D
3.0.0
A Real-Time-Oriented 2-D Physics Engine
|
A physical entity that exists within a World. More...
#include <Body.hpp>
Public Types | |
using | Fixtures = std::forward_list< Fixture * > |
using | Joints = std::unordered_set< Joint * > |
using | Contacts = std::list< Contact * > |
Public Member Functions | |
Fixture * | CreateFixture (std::shared_ptr< const Shape > shape, const FixtureDef &def=GetDefaultFixtureDef(), bool resetMassData=true) |
Creates a fixture and attaches it to this body. More... | |
bool | DestroyFixture (Fixture *fixture, bool resetMassData=true) |
Destroys a fixture. More... | |
void | SetTransform (const Length2D position, 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... | |
Length2D | GetLocation () const noexcept |
Gets the world body origin location. More... | |
const Sweep & | GetSweep () const noexcept |
Angle | GetAngle () const noexcept |
Get the angle in radians. More... | |
Length2D | GetWorldCenter () const noexcept |
Get the world position of the center of mass. More... | |
Length2D | GetLocalCenter () const noexcept |
Gets the local position of the center of mass. More... | |
Velocity | GetVelocity () const noexcept |
void | SetVelocity (const Velocity &v) noexcept |
Sets the body's velocity (linear and angular velocity). More... | |
void | SetAcceleration (const LinearAcceleration2D linear, const AngularAcceleration angular) noexcept |
Sets the linear and rotational accelerations on this body. More... | |
LinearAcceleration2D | GetLinearAcceleration () const noexcept |
AngularAcceleration | GetAngularAcceleration () const noexcept |
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 &data) |
Set the mass properties to override the mass properties of the fixtures. More... | |
void | ResetMassData () |
Resets the mass data properties. More... | |
RealNum | GetLinearDamping () const noexcept |
Get the linear damping of the body. More... | |
void | SetLinearDamping (RealNum linearDamping) noexcept |
Set the linear damping of the body. More... | |
RealNum | GetAngularDamping () const noexcept |
Get the angular damping of the body. More... | |
void | SetAngularDamping (RealNum angularDamping) noexcept |
Set the angular damping of the body. More... | |
void | SetType (BodyType type) |
Set the type of this body. This may alter the mass and velocity. More... | |
BodyType | GetType () const noexcept |
Get 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 |
Should this body be treated like a bullet for continuous collision detection? More... | |
bool | IsImpenetrable () const noexcept |
Is this body treated like a bullet for continuous collision detection? More... | |
void | SetSleepingAllowed (bool flag) noexcept |
You can disable sleeping on this body. If you disable sleeping, the body will be woken. More... | |
bool | IsSleepingAllowed () const noexcept |
Is this body allowed to sleep. More... | |
void | SetAwake () noexcept |
Sets this body to awake if it's a "speedable" 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 | SetEnabled (bool flag) |
Set 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. 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. A disabled body is still owned by a World object and remains in the body list. More... | |
bool | IsEnabled () const noexcept |
Get the enabled/disabled state of the body. More... | |
void | SetFixedRotation (bool flag) |
Set this body to have fixed rotation. This causes the mass to be reset. More... | |
bool | IsFixedRotation () const noexcept |
Does this body have fixed rotation? More... | |
const Fixtures & | GetFixtures () const noexcept |
Gets the container of all fixtures attached to this body. More... | |
const Joints & | GetJoints () const noexcept |
Gets the container of all joints attached to this body. More... | |
const Contacts & | GetContacts () const noexcept |
Gets the container of all contacts attached to this body. More... | |
void * | GetUserData () const noexcept |
Get the user data pointer that was provided in the body definition. More... | |
void | SetUserData (void *data) noexcept |
Set the user data. Use this to store your application specific data. More... | |
World * | GetWorld () noexcept |
Gets the parent world of this body. More... | |
const World * | GetWorld () const noexcept |
Gets the parent world of this body. More... | |
bool | IsMassDataDirty () const noexcept |
Static Public Member Functions | |
static bool | IsValid (const Shape &shape) |
Static Public Attributes | |
static constexpr auto | InvalidIslandIndex = static_cast<body_count_t>(-1) |
Friends | |
class | BodyAtty |
A physical entity that exists within a World.
A rigid body entity created or destroyed through a World instance.
using box2d::Body::Contacts = std::list<Contact*> |
using box2d::Body::Fixtures = std::forward_list<Fixture*> |
using box2d::Body::Joints = std::unordered_set<Joint*> |
Fixture * Body::CreateFixture | ( | std::shared_ptr< const Shape > | shape, |
const FixtureDef & | def = GetDefaultFixtureDef() , |
||
bool | resetMassData = true |
||
) |
Creates a fixture and attaches it to this body.
shape | Sharable shape definition. Its vertex radius must be less than the minimum or more than the maximum allowed by the body's world. |
def | Initial fixture settings. Friction and density must be >= 0. Restitution must be > -infinity and < infinity. |
resetMassData | Whether or not to reset the mass data of the body. |
nullptr
if the world is locked or a parameter is dissallowed. A pointer to the created fixture otherwise. bool Body::DestroyFixture | ( | Fixture * | fixture, |
bool | resetMassData = true |
||
) |
Destroys a fixture.
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.
fixture | the fixture to be removed. |
resetMassData | Whether or not to reset the mass data. |
|
inlinenoexcept |
Get the angle in radians.
|
inlinenoexcept |
|
inlinenoexcept |
Get the angular damping of the body.
|
inlinenoexcept |
Gets the container of all contacts attached to this body.
|
inlinenoexcept |
Gets the container of all fixtures attached to this body.
|
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.
|
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.
|
inlinenoexcept |
Gets the container of all joints attached to this body.
|
inlinenoexcept |
|
inlinenoexcept |
Get the linear damping of the body.
|
inlinenoexcept |
Gets the local position of the center of mass.
|
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:
|
inlinenoexcept |
|
inlinenoexcept |
Gets the body transform for the body's origin.
|
inlinenoexcept |
Get the type of this body.
|
inlinenoexcept |
Gets this body's under-active time value.
|
inlinenoexcept |
Get the user data pointer that was provided in the body definition.
|
inlinenoexcept |
|
inlinenoexcept |
Gets the parent world of this body.
|
inlinenoexcept |
Gets the parent world of this body.
|
inlinenoexcept |
Get the world position of the center of mass.
|
inlinenoexcept |
Is accelerable.
Indicates whether this body is accelerable, ie. whether it is effected by forces. Only Dynamic bodies are accelerable.
|
inlinenoexcept |
Gets the awake/asleep state of this body.
|
inlinenoexcept |
Get the enabled/disabled state of the body.
|
inlinenoexcept |
Does this body have fixed rotation?
|
inlinenoexcept |
Is this body treated like a bullet for continuous collision detection?
|
inlinenoexcept |
|
inlinenoexcept |
Is this body allowed to sleep.
|
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.
|
static |
void Body::ResetMassData | ( | ) |
Resets the mass data properties.
This resets the mass data to the sum of the mass properties of the fixtures.
CreateFixture
to update the body mass data properties unless SetMassData
is used.
|
noexcept |
Sets the linear and rotational accelerations on this body.
linear | Linear acceleration. |
angular | Angular acceleration. |
|
inlinenoexcept |
Set the angular damping of the body.
|
inlinenoexcept |
Sets this body to awake if it's a "speedable" body.
This sets the sleep state of the body to awake if it's a "speedable" body. It has no effect otherwise.
|
inlinenoexcept |
Should this body be treated like a bullet for continuous collision detection?
void Body::SetEnabled | ( | bool | flag | ) |
Set 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. 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. A disabled body is still owned by a World object and remains in the body list.
void Body::SetFixedRotation | ( | bool | flag | ) |
Set this body to have fixed rotation. This causes the mass to be reset.
|
inlinenoexcept |
Set the linear damping of the body.
void Body::SetMassData | ( | const MassData & | data | ) |
Set the mass properties to override the mass properties of the fixtures.
data | the mass properties. |
|
inlinenoexcept |
You can disable sleeping on this body. If you disable sleeping, the body will be woken.
Sets the position of the body's origin and rotation.
This instantly adjusts the body to be at the new position and new orientation.
position | Valid world position of the body's local origin. Behavior is undefined if value is invalid. |
angle | Valid world rotation in radians. Behavior is undefined if value is invalid. |
void Body::SetType | ( | BodyType | type | ) |
Set the type of this body. This may alter the mass and velocity.
|
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.
|
inlinenoexcept |
Set the user data. Use this to store your application specific data.
|
noexcept |
Sets the body's velocity (linear and angular velocity).
|
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).
|
friend |
|
static |