HughPH.Box2D
Organised dotnet bindings for Box2D 3.1.0
|
A Box2D physics body. The body's transform is the base transform for all shapes attached to this body. More...
Inherits IEquatable< Body >, and IComparable< Body >.
Public Member Functions | |
Body (World world, BodyDef def) | |
Create a body in the supplied world using the supplied BodyDef. | |
bool | Equals (Body other) |
Check if two Body objects represent the same Body. | |
override bool | Equals (object? obj) |
Check if this Body object is equal to another object. | |
override int | GetHashCode () |
Get the hash code for this Body object. | |
bool | ReferenceEquals (Body other) |
Check if this Body object refers to the same Body as another Body object. | |
int | CompareTo (Body other) |
Compare this Body object with another Body object. | |
void | Destroy () |
Destroy this body. | |
Vec2 | GetLocalPoint (Vec2 worldPoint) |
Get a local point on a body given a world point. | |
Vec2 | GetWorldPoint (Vec2 localPoint) |
Get a world point on a body given a local point. | |
Vec2 | GetLocalVector (Vec2 worldVector) |
Get a local vector on a body given a world vector. | |
Vec2 | GetWorldVector (Vec2 localVector) |
Get a world vector on a body given a local vector. | |
void | SetTargetTransform (Transform target, float timeStep) |
Set the velocity to reach the given transform after a given time step. The result will be close but maybe not exact. This is meant for kinematic bodies. This will automatically wake the body if asleep. | |
Vec2 | GetLocalPointVelocity (Vec2 localPoint) |
Get the linear velocity of a local point attached to a body. | |
Vec2 | GetWorldPointVelocity (Vec2 worldPoint) |
Get the linear velocity of a world point attached to a body. | |
void | ApplyForce (Vec2 force, Vec2 point, bool wake) |
Apply a force at a world point. | |
void | ApplyForceToCenter (Vec2 force, bool wake) |
Apply a force to the center of mass. | |
void | ApplyTorque (float torque, bool wake) |
Apply a torque. | |
void | ApplyLinearImpulse (Vec2 impulse, Vec2 point, bool wake) |
Apply an impulse at a point. | |
void | ApplyLinearImpulseToCenter (Vec2 impulse, bool wake) |
Apply an impulse to the center of mass. | |
void | ApplyAngularImpulse (float impulse, bool wake) |
Apply an angular impulse. | |
void | ApplyMassFromShapes () |
This updates the mass properties to the sum of the mass properties of the shapes. | |
void | EnableContactEvents (bool flag) |
Enable/disable contact events on all shapes. | |
void | EnableHitEvents (bool flag) |
Enable/disable hit events on all shapes. | |
Shape | CreateShape (in ShapeDef def, in Circle circle) |
Creates a circle shape and attaches it to this body. | |
Shape | CreateShape (in ShapeDef def, in Segment segment) |
Creates a line segment shape and attaches it to this body. | |
Shape | CreateShape (in ShapeDef def, in Capsule capsule) |
Creates a capsule shape and attaches it to this body. | |
Shape | CreateShape (in ShapeDef def, in Polygon polygon) |
Creates a polygon shape and attaches it to this body. | |
ChainShape | CreateChain (ChainDef def) |
Creates a chain shape. | |
Static Public Member Functions | |
static bool | operator== (Body left, Body right) |
Check if two Body objects are equal. | |
static bool | operator!= (Body left, Body right) |
Check if two Body objects are not equal. | |
Properties | |
static IComparer< Body > | DefaultComparer = BodyComparer.Instance [get] |
Default comparer for Body instances. This is used for sorting and comparing Body instances. Using the default comparer is recommended to avoid boxing and unboxing overhead. | |
static IEqualityComparer< Body > | DefaultEqualityComparer = BodyComparer.Instance [get] |
Default equality comparer for Body instances. This is used for comparing Body instances. Using the default equality comparer is recommended to avoid boxing and unboxing overhead. | |
bool | Valid [get] |
Body identifier validation. | |
BodyType | Type [get, set] |
The body type: static, kinematic, or dynamic. | |
string? | Name [get, set] |
The body name. | |
object? | UserData [get, set] |
The user data object for this body. | |
Vec2 | Position [get] |
The world position of the body. | |
Rotation | Rotation [get] |
The world rotation of this body as a cosine/sine pair (complex number). | |
Transform | Transform [get, set] |
The world transform of this body. | |
Vec2 | LinearVelocity [get, set] |
The linear velocity of the body's center of mass. | |
float | AngularVelocity [get, set] |
The angular velocity of the body in radians per second. | |
float | Mass [get] |
The mass of the body, usually in kilograms. | |
float | RotationalInertia [get] |
The rotational inertia of the body, usually in kg*m². | |
Vec2 | LocalCenterOfMass [get] |
The center of mass position of the body in local space. | |
Vec2 | WorldCenterOfMass [get] |
The center of mass position of the body in world space. | |
MassData | MassData [get, set] |
The mass data for this body. | |
float | LinearDamping [get, set] |
The linear damping. | |
float | AngularDamping [get, set] |
The angular damping. | |
float | GravityScale [get, set] |
The gravity scale. | |
bool | Awake [get, set] |
The body awake state. | |
bool | SleepEnabled [get, set] |
Option to enable or disable sleeping for this body. | |
float | SleepThreshold [get, set] |
The sleep threshold, usually in meters per second. | |
bool | Enabled [get, set] |
The body enabled flag. | |
bool | FixedRotation [get, set] |
The fixed rotation flag of the body. | |
bool | Bullet [get, set] |
The bullet flag of the body. | |
World | World [get] |
The world that owns this body. | |
unsafe ReadOnlySpan< Shape > | Shapes [get] |
The shapes attached to this body. | |
unsafe ReadOnlySpan< Joint > | Joints [get] |
The joints attached to this body. | |
unsafe ReadOnlySpan< ContactData > | Contacts [get] |
The touching contact data for this body. | |
AABB | AABB [get] |
The current world AABB that contains all the attached shapes. | |
A Box2D physics body. The body's transform is the base transform for all shapes attached to this body.
Create a body in the supplied world using the supplied BodyDef.
world | The world in which to create the body |
def | The BodyDef to use to create the body |
|
inline |
Apply an angular impulse.
impulse | The angular impulse, usually in units of kg*m*m/s |
wake | Option to wake up the body |
The impulse is ignored if the body is not awake
Warning: This should be used for one-shot impulses. If you need a steady force, use a force instead, which will work better with the sub-stepping solver
|
inline |
Apply a force at a world point.
force | The world force vector, usually in newtons (N) |
point | The world position of the point of application |
wake | Option to wake up the body |
If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. The force is ignored if the body is not awake
|
inline |
Apply a force to the center of mass.
force | The world force vector, usually in newtons (N) |
wake | Option to wake up the body |
This wakes up the body
If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. The force is ignored if the body is not awake
|
inline |
Apply an impulse at a point.
impulse | The world impulse vector, usually in N*s or kg*m/s |
point | The world position of the point of application |
wake | Option to wake up the body |
This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. The impulse is ignored if the body is not awake
Warning: This should be used for one-shot impulses. If you need a steady force, use a force instead, which will work better with the sub-stepping solver
|
inline |
Apply an impulse to the center of mass.
impulse | The world impulse vector, usually in N*s or kg*m/s |
wake | Option to wake up the body |
This immediately modifies the velocity. The impulse is ignored if the body is not awake
Warning: This should be used for one-shot impulses. If you need a steady force, use a force instead, which will work better with the sub-stepping solver
|
inline |
This updates the mass properties to the sum of the mass properties of the shapes.
This normally does not need to be called unless you called SetMassData to override the mass, and you later want to reset the mass. You may also use this when automatic mass computation has been disabled. You should call this regardless of body type
Note: Sensor shapes may have mass.
|
inline |
Apply a torque.
torque | The torque about the z-axis (out of the screen), usually in N*m |
wake | Option to wake up the body |
This affects the angular velocity without affecting the linear velocity. The torque is ignored if the body is not awake
|
inline |
Compare this Body object with another Body object.
other | The other Body object to compare with |
|
inline |
Creates a chain shape.
def | The chain definition |
Creates a capsule shape and attaches it to this body.
def | The shape definition |
capsule | The capsule |
The shape definition and geometry are fully cloned. Contacts are not created until the next time step
Creates a circle shape and attaches it to this body.
def | The shape definition |
circle | The circle |
The shape definition and geometry are fully cloned. Contacts are not created until the next time step
Creates a polygon shape and attaches it to this body.
def | The shape definition |
polygon | The polygon |
The shape definition and geometry are fully cloned. Contacts are not created until the next time step
Creates a line segment shape and attaches it to this body.
def | The shape definition |
segment | The segment |
The shape definition and geometry are fully cloned. Contacts are not created until the next time step
|
inline |
Destroy this body.
This destroys all shapes and joints attached to the body. Do not keep references to the associated shapes and joints
|
inline |
Enable/disable contact events on all shapes.
flag | Option to enable or disable contact events on all shapes |
Warning: Changing this at runtime may cause mismatched begin/end touch events.
|
inline |
Enable/disable hit events on all shapes.
flag | Option to enable or disable hit events on all shapes |
bool Box2D.Body.Equals | ( | Body | other | ) |
Check if two Body objects represent the same Body.
other | The other Body object to compare with |
override bool Box2D.Body.Equals | ( | object? | obj | ) |
Check if this Body object is equal to another object.
obj | The object to compare with |
override int Box2D.Body.GetHashCode | ( | ) |
Get the hash code for this Body object.
Vec2 Box2D.Body.GetLocalPoint | ( | Vec2 | worldPoint | ) |
Get a local point on a body given a world point.
worldPoint | The world point |
|
inline |
Get the linear velocity of a local point attached to a body.
localPoint | The local point |
Usually in meters per second
Vec2 Box2D.Body.GetLocalVector | ( | Vec2 | worldVector | ) |
Get a local vector on a body given a world vector.
worldVector | The world vector |
Vec2 Box2D.Body.GetWorldPoint | ( | Vec2 | localPoint | ) |
Get a world point on a body given a local point.
localPoint | The local point |
|
inline |
Get the linear velocity of a world point attached to a body.
worldPoint | The world point |
Usually in meters per second
Vec2 Box2D.Body.GetWorldVector | ( | Vec2 | localVector | ) |
Get a world vector on a body given a local vector.
localVector | The local vector |
Check if two Body objects are not equal.
left | The first Body object |
right | The second Body object |
Check if two Body objects are equal.
left | The first Body object |
right | The second Body object |
bool Box2D.Body.ReferenceEquals | ( | Body | other | ) |
Check if this Body object refers to the same Body as another Body object.
other | The other Body object to compare with |
|
inline |
Set the velocity to reach the given transform after a given time step. The result will be close but maybe not exact. This is meant for kinematic bodies. This will automatically wake the body if asleep.
target | The target transform |
timeStep | The time step |
|
get |
The current world AABB that contains all the attached shapes.
Note that this may not encompass the body origin. If there are no shapes attached then the returned AABB is empty and centered on the body origin
|
getset |
The angular damping.
Normally this is set in BodyDef before creation
|
getset |
The angular velocity of the body in radians per second.
In radians per second
|
getset |
The body awake state.
This wakes the entire island the body is touching. Warning: Putting a body to sleep will put the entire island of bodies touching this body to sleep, which can be expensive and possibly unintuitive.
|
getset |
The bullet flag of the body.
A bullet does continuous collision detection against dynamic bodies (but not other bullets)
|
get |
The touching contact data for this body.
Note: Box2D uses speculative collision so some contact points may be separated.
|
getset |
The fixed rotation flag of the body.
Setting this causes the mass to be reset in all cases
|
getset |
The gravity scale.
Normally this is set in BodyDef before creation
|
getset |
The linear damping.
Normally this is set in BodyDef before creation
|
getset |
The linear velocity of the body's center of mass.
Usually in meters per second
|
get |
The world position of the body.
This is the location of the body origin
|
getset |
Option to enable or disable sleeping for this body.
If sleeping is disabled the body will wake
|
getset |
The world transform of this body.
Setting this acts as a teleport and is fairly expensive.
Note: Generally you should create a body with the intended transform.
|
get |
Body identifier validation.
Can be used to detect orphaned ids. Provides validation for up to 64K allocations