Box2D  3.0.0
A Real-Time-Oriented 2-D Physics Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
box2d::World Class Reference

World. More...

#include <World.hpp>

Classes

struct  Def
 World construction definitions. More...
 

Public Types

using proxy_size_type = std::remove_const< decltype(MaxContacts)>::type
 Proxy size type. More...
 
using ts_iters_type = ts_iters_t
 Time step iteration type. More...
 
using Bodies = std::list< Body * >
 Bodies container type. More...
 
using Contacts = std::list< Contact * >
 Contacts container type. More...
 
using Joints = std::list< Joint * >
 Joints container type. More...
 

Public Member Functions

 World (const Def &def=GetDefaultDef())
 Constructs a world object. More...
 
 ~World ()
 Destructor. More...
 
void SetDestructionListener (DestructionListener *listener) noexcept
 Register a destruction listener. The listener is owned by you and must remain in scope. More...
 
void SetContactFilter (ContactFilter *filter) noexcept
 Register a contact filter to provide specific control over collision. Otherwise the default filter is used. The listener is owned by you and must remain in scope. More...
 
void SetContactListener (ContactListener *listener) noexcept
 Register a contact event listener. The listener is owned by you and must remain in scope. More...
 
BodyCreateBody (const BodyDef &def=GetDefaultBodyDef())
 Creates a rigid body given a definition. More...
 
void Destroy (Body *body)
 Destroys the given body. More...
 
JointCreateJoint (const JointDef &def)
 Creates a joint to constrain bodies together. More...
 
void Destroy (Joint *joint)
 Destroys a joint. More...
 
StepStats Step (const StepConf &conf)
 Steps the world simulation according to the given configuration. More...
 
void QueryAABB (QueryFixtureReporter *callback, const AABB &aabb) const
 Queries the world for all fixtures that potentially overlap the provided AABB. More...
 
void RayCast (RayCastFixtureReporter *callback, const Length2D &point1, const Length2D &point2) const
 Ray-cast the world for all fixtures in the path of the ray. Your callback controls whether you get the closest point, any point, or n-points. The ray-cast ignores shapes that contain the starting point. More...
 
const BodiesGetBodies () const noexcept
 Gets the world body container for this constant world. More...
 
const JointsGetJoints () const noexcept
 Gets the world joint container. More...
 
const ContactsGetContacts () const noexcept
 Gets the world contact container. More...
 
bool GetSubStepping () const noexcept
 Gets whether or not sub-stepping is enabled. More...
 
void SetSubStepping (bool flag) noexcept
 Enable/disable single stepped continuous physics. For testing. More...
 
proxy_size_type GetProxyCount () const noexcept
 Gets the number of broad-phase proxies. More...
 
proxy_size_type GetTreeHeight () const noexcept
 Get the height of the dynamic tree. More...
 
proxy_size_type GetTreeBalance () const
 Get the balance of the dynamic tree. More...
 
RealNum GetTreeQuality () const
 Gets the quality metric of the dynamic tree. More...
 
void SetGravity (const LinearAcceleration2D gravity) noexcept
 Change the global gravity vector. More...
 
LinearAcceleration2D GetGravity () const noexcept
 Get the global gravity vector. More...
 
bool IsLocked () const noexcept
 Is the world locked (in the middle of a time step). More...
 
void ShiftOrigin (const Length2D newOrigin)
 Shift the world origin. Useful for large worlds. The body shift formula is: position -= newOrigin. More...
 
Length GetMinVertexRadius () const noexcept
 Gets the minimum vertex radius that shapes in this world can be. More...
 
Length GetMaxVertexRadius () const noexcept
 Gets the maximum vertex radius that shapes in this world can be. More...
 
Frequency GetInvDeltaTime () const noexcept
 Gets the inverse delta time. More...
 
AABB GetFatAABB (proxy_size_type proxyId) const
 Gets the fat AABB for a proxy. More...
 
void SetType (Body &body, BodyType type)
 Sets the type of the given body. More...
 
bool RegisterForProxies (Fixture *fixture)
 
bool RegisterForProxies (Body *body)
 
FixtureCreateFixture (Body &body, std::shared_ptr< const Shape > shape, const FixtureDef &def=GetDefaultFixtureDef(), bool resetMassData=true)
 
bool DestroyFixture (Fixture *fixture, bool resetMassData=true)
 Destroys a fixture. More...
 
bool IsValid (std::shared_ptr< const Shape > shape) const noexcept
 
bool TouchProxies (Fixture &fixture) noexcept
 Touches each proxy of the given fixture. More...
 

Static Public Member Functions

static constexpr Def GetDefaultDef () noexcept
 Gets the default definitions value. More...
 
static const BodyDefGetDefaultBodyDef ()
 Gets the default body definitions value. More...
 

Detailed Description

World.

The world class manages all physics entities, dynamic simulation, and queries.

Note
This data structure is 352-bytes large (with 4-byte RealNum on at least one 64-bit platform).

Member Typedef Documentation

◆ Bodies

using box2d::World::Bodies = std::list<Body*>

Bodies container type.

◆ Contacts

using box2d::World::Contacts = std::list<Contact*>

Contacts container type.

◆ Joints

using box2d::World::Joints = std::list<Joint*>

Joints container type.

◆ proxy_size_type

using box2d::World::proxy_size_type = std::remove_const<decltype(MaxContacts)>::type

Proxy size type.

◆ ts_iters_type

Time step iteration type.

Constructor & Destructor Documentation

◆ World()

box2d::World::World ( const Def def = GetDefaultDef())

Constructs a world object.

◆ ~World()

box2d::World::~World ( )

Destructor.

All physics entities are destroyed and all dynamically allocated memory is released.

Member Function Documentation

◆ CreateBody()

Body * box2d::World::CreateBody ( const BodyDef def = GetDefaultBodyDef())

Creates a rigid body given a definition.

Note
No reference to the definition is retained.
Warning
This function is locked during callbacks.

◆ CreateFixture()

Fixture * box2d::World::CreateFixture ( Body body,
std::shared_ptr< const Shape shape,
const FixtureDef def = GetDefaultFixtureDef(),
bool  resetMassData = true 
)

◆ CreateJoint()

Joint * box2d::World::CreateJoint ( const JointDef def)

Creates a joint to constrain bodies together.

No reference to the definition is retained. This may cause the connected bodies to cease colliding.

Warning
This function is locked during callbacks.
Returns
nullptr if world has MaxJoints, else pointer to newly created joint.

◆ Destroy() [1/2]

void box2d::World::Destroy ( Body body)

Destroys the given body.

Note
This function is locked during callbacks.
Warning
This automatically deletes all associated shapes and joints.
This function is locked during callbacks.

◆ Destroy() [2/2]

void box2d::World::Destroy ( Joint joint)

Destroys a joint.

This may cause the connected bodies to begin colliding.

Warning
This function is locked during callbacks.
Behavior is undefined if the passed joint was not created by this world.
Parameters
jointJoint, created by this world, to destroy.

◆ DestroyFixture()

bool box2d::World::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.

Warning
This function is locked during callbacks.
Note
Make sure to explicitly call ResetMassData after fixtures have been destroyed.
Parameters
fixturethe fixture to be removed.
resetMassDataWhether or not to reset the mass data of the associated body.
See also
ResetMassData.

◆ GetBodies()

const World::Bodies & box2d::World::GetBodies ( ) const
inlinenoexcept

Gets the world body container for this constant world.

Returns
Body container that can be iterated over using its begin and end methods or using ranged-based for-loops.

◆ GetContacts()

const World::Contacts & box2d::World::GetContacts ( ) const
inlinenoexcept

Gets the world contact container.

Warning
contacts are created and destroyed in the middle of a time step. Use ContactListener to avoid missing contacts.
Returns
World contact container.

◆ GetDefaultBodyDef()

const BodyDef & box2d::World::GetDefaultBodyDef ( )
static

Gets the default body definitions value.

◆ GetDefaultDef()

static constexpr Def box2d::World::GetDefaultDef ( )
inlinestaticnoexcept

Gets the default definitions value.

Note
This method exists as a work-around for providing the World constructor a default value without otherwise getting a compiler error such as: "cannot use defaulted constructor of 'Def' within 'World' outside of member functions because 'gravity' has an initializer"

◆ GetFatAABB()

AABB box2d::World::GetFatAABB ( proxy_size_type  proxyId) const
inline

Gets the fat AABB for a proxy.

Warning
Behavior is undefined if the given proxy ID is not a valid ID.

◆ GetGravity()

LinearAcceleration2D box2d::World::GetGravity ( ) const
inlinenoexcept

Get the global gravity vector.

◆ GetInvDeltaTime()

Frequency box2d::World::GetInvDeltaTime ( ) const
inlinenoexcept

Gets the inverse delta time.

◆ GetJoints()

const World::Joints & box2d::World::GetJoints ( ) const
inlinenoexcept

Gets the world joint container.

Returns
World joint container.

◆ GetMaxVertexRadius()

Length box2d::World::GetMaxVertexRadius ( ) const
inlinenoexcept

Gets the maximum vertex radius that shapes in this world can be.

◆ GetMinVertexRadius()

Length box2d::World::GetMinVertexRadius ( ) const
inlinenoexcept

Gets the minimum vertex radius that shapes in this world can be.

◆ GetProxyCount()

World::proxy_size_type box2d::World::GetProxyCount ( ) const
inlinenoexcept

Gets the number of broad-phase proxies.

◆ GetSubStepping()

bool box2d::World::GetSubStepping ( ) const
inlinenoexcept

Gets whether or not sub-stepping is enabled.

◆ GetTreeBalance()

World::proxy_size_type box2d::World::GetTreeBalance ( ) const
inline

Get the balance of the dynamic tree.

◆ GetTreeHeight()

World::proxy_size_type box2d::World::GetTreeHeight ( ) const
inlinenoexcept

Get the height of the dynamic tree.

◆ GetTreeQuality()

RealNum box2d::World::GetTreeQuality ( ) const
inline

Gets the quality metric of the dynamic tree.

The smaller the better.

Returns
Value of zero or more.

◆ IsLocked()

bool box2d::World::IsLocked ( ) const
inlinenoexcept

Is the world locked (in the middle of a time step).

◆ IsValid()

bool box2d::World::IsValid ( std::shared_ptr< const Shape shape) const
noexcept

◆ QueryAABB()

void box2d::World::QueryAABB ( QueryFixtureReporter callback,
const AABB aabb 
) const

Queries the world for all fixtures that potentially overlap the provided AABB.

Parameters
callbacka user implemented callback class.
aabbthe query box.

◆ RayCast()

void box2d::World::RayCast ( RayCastFixtureReporter callback,
const Length2D point1,
const Length2D point2 
) const

Ray-cast the world for all fixtures in the path of the ray. Your callback controls whether you get the closest point, any point, or n-points. The ray-cast ignores shapes that contain the starting point.

Parameters
callbacka user implemented callback class.
point1the ray starting point
point2the ray ending point

◆ RegisterForProxies() [1/2]

bool box2d::World::RegisterForProxies ( Fixture fixture)

◆ RegisterForProxies() [2/2]

bool box2d::World::RegisterForProxies ( Body body)

◆ SetContactFilter()

void box2d::World::SetContactFilter ( ContactFilter filter)
inlinenoexcept

Register a contact filter to provide specific control over collision. Otherwise the default filter is used. The listener is owned by you and must remain in scope.

◆ SetContactListener()

void box2d::World::SetContactListener ( ContactListener listener)
inlinenoexcept

Register a contact event listener. The listener is owned by you and must remain in scope.

◆ SetDestructionListener()

void box2d::World::SetDestructionListener ( DestructionListener listener)
inlinenoexcept

Register a destruction listener. The listener is owned by you and must remain in scope.

◆ SetGravity()

void box2d::World::SetGravity ( const LinearAcceleration2D  gravity)
noexcept

Change the global gravity vector.

◆ SetSubStepping()

void box2d::World::SetSubStepping ( bool  flag)
inlinenoexcept

Enable/disable single stepped continuous physics. For testing.

◆ SetType()

void box2d::World::SetType ( Body body,
BodyType  type 
)

Sets the type of the given body.

Note
This may alter the body's mass and velocity.

◆ ShiftOrigin()

void box2d::World::ShiftOrigin ( const Length2D  newOrigin)

Shift the world origin. Useful for large worlds. The body shift formula is: position -= newOrigin.

Parameters
newOriginthe new origin with respect to the old origin

◆ Step()

StepStats box2d::World::Step ( const StepConf conf)

Steps the world simulation according to the given configuration.

Performs position and velocity updating, sleeping of non-moving bodies, updating of the contacts, and notifying the contact listener of begin-contact, end-contact, pre-solve, and post-solve events.

Warning
Behavior is undefined if given a negative step time delta.
Varying the step time delta may lead to non-physical behaviors.
Note
Calling this with a zero step time delta results only in fixtures and bodies registered for proxy handling being processed. No physics is performed.
If the given velocity and position iterations are zero, this method doesn't do velocity or position resolutions respectively of the contacting bodies.
While body velocities are updated accordingly (per the sum of forces acting on them), body positions (barring any collisions) are updated as if they had moved the entire time step at those resulting velocities. In other words, a body initially at p0 going v0 fast with a sum acceleration of a, after time t and barring any collisions, will have a new velocity (v1) of v0 + (a * t) and a new position (p1) of p0 + v1 * t.
Postcondition
Static bodies are unmoved.
Kinetic bodies are moved based on their previous velocities.
Dynamic bodies are moved based on their previous velocities, gravity, applied forces, applied impulses, masses, damping, and the restitution and friction values of their fixtures when they experience collisions.
Parameters
confConfiguration for the simulation step.
Returns
Statistics for the step.

◆ TouchProxies()

bool box2d::World::TouchProxies ( Fixture fixture)
noexcept

Touches each proxy of the given fixture.

Note
Fixture must belong to a body that belongs to this world or this method will return false.
This sets things up so that pairs may be created for potentially new contacts.

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