Box2D
3.0.0
A Real-Time-Oriented 2-D Physics Engine
|
#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... | |
Body * | CreateBody (const BodyDef &def=GetDefaultBodyDef()) |
Creates a rigid body given a definition. More... | |
void | Destroy (Body *body) |
Destroys the given body. More... | |
Joint * | CreateJoint (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 Bodies & | GetBodies () const noexcept |
Gets the world body container for this constant world. More... | |
const Joints & | GetJoints () const noexcept |
Gets the world joint container. More... | |
const Contacts & | GetContacts () 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) |
Fixture * | CreateFixture (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 BodyDef & | GetDefaultBodyDef () |
Gets the default body definitions value. More... | |
The world class manages all physics entities, dynamic simulation, and queries.
using box2d::World::Bodies = std::list<Body*> |
Bodies container type.
using box2d::World::Contacts = std::list<Contact*> |
Contacts container type.
using box2d::World::Joints = std::list<Joint*> |
Joints container type.
using box2d::World::proxy_size_type = std::remove_const<decltype(MaxContacts)>::type |
Proxy size type.
Time step iteration type.
box2d::World::World | ( | const Def & | def = GetDefaultDef() | ) |
Constructs a world object.
box2d::World::~World | ( | ) |
Destructor.
All physics entities are destroyed and all dynamically allocated memory is released.
Body * box2d::World::CreateBody | ( | const BodyDef & | def = GetDefaultBodyDef() | ) |
Creates a rigid body given a definition.
Fixture * box2d::World::CreateFixture | ( | Body & | body, |
std::shared_ptr< const Shape > | shape, | ||
const FixtureDef & | def = GetDefaultFixtureDef() , |
||
bool | resetMassData = true |
||
) |
Creates a joint to constrain bodies together.
No reference to the definition is retained. This may cause the connected bodies to cease colliding.
nullptr
if world has MaxJoints
, else pointer to newly created joint. void box2d::World::Destroy | ( | Body * | body | ) |
Destroys the given body.
void box2d::World::Destroy | ( | Joint * | joint | ) |
Destroys a joint.
This may cause the connected bodies to begin colliding.
joint | Joint, created by this world, to destroy. |
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.
fixture | the fixture to be removed. |
resetMassData | Whether or not to reset the mass data of the associated body. |
|
inlinenoexcept |
Gets the world body container for this constant world.
|
inlinenoexcept |
Gets the world contact container.
|
static |
Gets the default body definitions value.
|
inlinestaticnoexcept |
Gets the default definitions value.
|
inline |
Gets the fat AABB for a proxy.
|
inlinenoexcept |
Get the global gravity vector.
|
inlinenoexcept |
Gets the inverse delta time.
|
inlinenoexcept |
Gets the world joint container.
|
inlinenoexcept |
Gets the maximum vertex radius that shapes in this world can be.
|
inlinenoexcept |
Gets the minimum vertex radius that shapes in this world can be.
|
inlinenoexcept |
Gets the number of broad-phase proxies.
|
inlinenoexcept |
Gets whether or not sub-stepping is enabled.
|
inline |
Get the balance of the dynamic tree.
|
inlinenoexcept |
Get the height of the dynamic tree.
|
inline |
Gets the quality metric of the dynamic tree.
The smaller the better.
|
inlinenoexcept |
Is the world locked (in the middle of a time step).
|
noexcept |
void box2d::World::QueryAABB | ( | QueryFixtureReporter * | callback, |
const AABB & | aabb | ||
) | const |
Queries the world for all fixtures that potentially overlap the provided AABB.
callback | a user implemented callback class. |
aabb | the query box. |
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.
callback | a user implemented callback class. |
point1 | the ray starting point |
point2 | the ray ending point |
bool box2d::World::RegisterForProxies | ( | Fixture * | fixture | ) |
bool box2d::World::RegisterForProxies | ( | Body * | body | ) |
|
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.
|
inlinenoexcept |
Register a contact event listener. The listener is owned by you and must remain in scope.
|
inlinenoexcept |
Register a destruction listener. The listener is owned by you and must remain in scope.
|
noexcept |
Change the global gravity vector.
|
inlinenoexcept |
Enable/disable single stepped continuous physics. For testing.
Sets the type of the given body.
void box2d::World::ShiftOrigin | ( | const Length2D | newOrigin | ) |
Shift the world origin. Useful for large worlds. The body shift formula is: position -= newOrigin.
newOrigin | the new origin with respect to the old origin |
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.
conf | Configuration for the simulation step. |
|
noexcept |
Touches each proxy of the given fixture.