5#include <Box2D/Box2D.h>
10 : world_(
world), body_(
body), fixture_(fixture) {}
13 if (fixture_ && body_ && body_->
raw()) {
15 fixture_->SetUserData(
nullptr);
16 body_->
raw()->DestroyFixture(fixture_);
24 if (fixture_) fixture_->SetUserData(
nullptr);
31 if (!fixture_ || !body_ || !body_->
raw()) {
36 fixture_->SetUserData(
nullptr);
37 body_->
raw()->DestroyFixture(fixture_);
44 if (!fixture_)
return;
45 fixture_->SetSensor(sensor);
51 if (!fixture_)
return;
52 fixture_->SetFriction(friction);
58 if (!fixture_)
return;
65 if (!fixture_)
return;
66 fixture_->SetDensity(density);
67 if (body_ && body_->
raw()) body_->
raw()->ResetMassData();
73 if (!fixture_)
return;
74 b2Filter
filter = fixture_->GetFilterData();
75 filter.categoryBits =
static_cast<uint16
>(bits);
76 fixture_->SetFilterData(
filter);
80 return fixture_ ? int(fixture_->GetFilterData().categoryBits) : 0;
84 if (!fixture_)
return;
85 b2Filter
filter = fixture_->GetFilterData();
86 filter.maskBits =
static_cast<uint16
>(bits);
87 fixture_->SetFilterData(
filter);
93 if (!fixture_)
return;
94 b2Filter
filter = fixture_->GetFilterData();
96 fixture_->SetFilterData(
filter);
100 return fixture_ ? int(fixture_->GetFilterData().groupIndex) : 0;
106 if (!fixture_ || !world_)
return false;
2D rigid body (Box2D) in pixel-space coordinates. Owned by a World; create shapes with newRectangleFi...
b2Body * raw()
Exposes the underlying Box2D body for tightly-scoped backend integration.
int getId() const
Stable id used by contact/impact events.
void destroy()
Destroys the fixture inside its world.
void setSensor(bool sensor)
Sensor fixtures report contacts but never collide.
bool testPoint(float x, float y) const
Pixel-space point-in-fixture test (uses World meter).
int getMaskBits() const
Returns the mask bits.
int getCategoryBits() const
Returns the category bits.
Fixture(World *world, Body *body, b2Fixture *fixture)
Internal: wraps a Box2D fixture (use Body::new*Fixture).
void setMaskBits(int bits)
Sets the mask bits.
void invalidate()
Internal: marks the wrapper invalid after destruction.
float getFriction() const
Returns the friction.
void setDensity(float density)
Sets the density.
bool isSensor() const
True when sensor.
void setFriction(float friction)
Material properties.
int getGroupIndex() const
Returns the group index.
int getBodyId() const
Id of the owning body.
void setCategoryBits(int bits)
Collision filtering (Box2D category/mask bits, group index).
void setGroupIndex(int index)
Sets the group index.
float getDensity() const
Returns the density.
void setRestitution(float restitution)
Sets the restitution.
float getRestitution() const
Returns the restitution.
Box2D world wrapper (2D physics) with pixel-space coordinates. Handles stepping, gravity,...
void forgetFixture(Fixture *fixture)
float toMeters(float pixels) const
Converts a pixel-space length to meters.
Optional physics backend for vehicle mobility and body attach.