HughPH.Box2D
Organised dotnet bindings for Box2D 3.1.0
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Properties | List of all members
Box2D.Body Struct Reference

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< BodyDefaultComparer = 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< BodyDefaultEqualityComparer = 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< ShapeShapes [get]
 The shapes attached to this body.
 
unsafe ReadOnlySpan< JointJoints [get]
 The joints attached to this body.
 
unsafe ReadOnlySpan< ContactDataContacts [get]
 The touching contact data for this body.
 
AABB AABB [get]
 The current world AABB that contains all the attached shapes.
 

Detailed Description

A Box2D physics body. The body's transform is the base transform for all shapes attached to this body.

Constructor & Destructor Documentation

◆ Body()

Box2D.Body.Body ( World  world,
BodyDef  def 
)
inline

Create a body in the supplied world using the supplied BodyDef.

Parameters
worldThe world in which to create the body
defThe BodyDef to use to create the body

Member Function Documentation

◆ ApplyAngularImpulse()

void Box2D.Body.ApplyAngularImpulse ( float  impulse,
bool  wake 
)
inline

Apply an angular impulse.

Parameters
impulseThe angular impulse, usually in units of kg*m*m/s
wakeOption 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

◆ ApplyForce()

void Box2D.Body.ApplyForce ( Vec2  force,
Vec2  point,
bool  wake 
)
inline

Apply a force at a world point.

Parameters
forceThe world force vector, usually in newtons (N)
pointThe world position of the point of application
wakeOption 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

◆ ApplyForceToCenter()

void Box2D.Body.ApplyForceToCenter ( Vec2  force,
bool  wake 
)
inline

Apply a force to the center of mass.

Parameters
forceThe world force vector, usually in newtons (N)
wakeOption 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

◆ ApplyLinearImpulse()

void Box2D.Body.ApplyLinearImpulse ( Vec2  impulse,
Vec2  point,
bool  wake 
)
inline

Apply an impulse at a point.

Parameters
impulseThe world impulse vector, usually in N*s or kg*m/s
pointThe world position of the point of application
wakeOption 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

◆ ApplyLinearImpulseToCenter()

void Box2D.Body.ApplyLinearImpulseToCenter ( Vec2  impulse,
bool  wake 
)
inline

Apply an impulse to the center of mass.

Parameters
impulseThe world impulse vector, usually in N*s or kg*m/s
wakeOption 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

◆ ApplyMassFromShapes()

void Box2D.Body.ApplyMassFromShapes ( )
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.

◆ ApplyTorque()

void Box2D.Body.ApplyTorque ( float  torque,
bool  wake 
)
inline

Apply a torque.

Parameters
torqueThe torque about the z-axis (out of the screen), usually in N*m
wakeOption 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

◆ CompareTo()

int Box2D.Body.CompareTo ( Body  other)
inline

Compare this Body object with another Body object.

Parameters
otherThe other Body object to compare with
Returns
A negative number if this Body object should be ordered before the other Body object, a positive number if this Body object should be ordered after the other Body object, or zero if they are equal

◆ CreateChain()

ChainShape Box2D.Body.CreateChain ( ChainDef  def)
inline

Creates a chain shape.

Parameters
defThe chain definition
Returns
The chain shape

◆ CreateShape() [1/4]

Shape Box2D.Body.CreateShape ( in ShapeDef  def,
in Capsule  capsule 
)
inline

Creates a capsule shape and attaches it to this body.

Parameters
defThe shape definition
capsuleThe capsule
Returns
The shape

The shape definition and geometry are fully cloned. Contacts are not created until the next time step

◆ CreateShape() [2/4]

Shape Box2D.Body.CreateShape ( in ShapeDef  def,
in Circle  circle 
)
inline

Creates a circle shape and attaches it to this body.

Parameters
defThe shape definition
circleThe circle
Returns
The shape

The shape definition and geometry are fully cloned. Contacts are not created until the next time step

◆ CreateShape() [3/4]

Shape Box2D.Body.CreateShape ( in ShapeDef  def,
in Polygon  polygon 
)

Creates a polygon shape and attaches it to this body.

Parameters
defThe shape definition
polygonThe polygon
Returns
The shape

The shape definition and geometry are fully cloned. Contacts are not created until the next time step

◆ CreateShape() [4/4]

Shape Box2D.Body.CreateShape ( in ShapeDef  def,
in Segment  segment 
)
inline

Creates a line segment shape and attaches it to this body.

Parameters
defThe shape definition
segmentThe segment
Returns
The shape

The shape definition and geometry are fully cloned. Contacts are not created until the next time step

◆ Destroy()

void Box2D.Body.Destroy ( )
inline

Destroy this body.

This destroys all shapes and joints attached to the body. Do not keep references to the associated shapes and joints

◆ EnableContactEvents()

void Box2D.Body.EnableContactEvents ( bool  flag)
inline

Enable/disable contact events on all shapes.

Parameters
flagOption to enable or disable contact events on all shapes

Warning: Changing this at runtime may cause mismatched begin/end touch events.

◆ EnableHitEvents()

void Box2D.Body.EnableHitEvents ( bool  flag)
inline

Enable/disable hit events on all shapes.

Parameters
flagOption to enable or disable hit events on all shapes

◆ Equals() [1/2]

bool Box2D.Body.Equals ( Body  other)

Check if two Body objects represent the same Body.

Parameters
otherThe other Body object to compare with
Returns
True if the two Body objects are equal, false otherwise

◆ Equals() [2/2]

override bool Box2D.Body.Equals ( object?  obj)

Check if this Body object is equal to another object.

Parameters
objThe object to compare with
Returns
True if the object is a Body and equal to this Body, false otherwise

◆ GetHashCode()

override int Box2D.Body.GetHashCode ( )

Get the hash code for this Body object.

Returns
The hash code for this Body object

◆ GetLocalPoint()

Vec2 Box2D.Body.GetLocalPoint ( Vec2  worldPoint)

Get a local point on a body given a world point.

Parameters
worldPointThe world point
Returns
The local point on the body

◆ GetLocalPointVelocity()

Vec2 Box2D.Body.GetLocalPointVelocity ( Vec2  localPoint)
inline

Get the linear velocity of a local point attached to a body.

Parameters
localPointThe local point
Returns
The linear velocity of the local point attached to the body, usually in meters per second

Usually in meters per second

◆ GetLocalVector()

Vec2 Box2D.Body.GetLocalVector ( Vec2  worldVector)

Get a local vector on a body given a world vector.

Parameters
worldVectorThe world vector
Returns
The local vector on the body

◆ GetWorldPoint()

Vec2 Box2D.Body.GetWorldPoint ( Vec2  localPoint)

Get a world point on a body given a local point.

Parameters
localPointThe local point
Returns
The world point on the body

◆ GetWorldPointVelocity()

Vec2 Box2D.Body.GetWorldPointVelocity ( Vec2  worldPoint)
inline

Get the linear velocity of a world point attached to a body.

Parameters
worldPointThe world point
Returns
The linear velocity of the world point attached to the body, usually in meters per second

Usually in meters per second

◆ GetWorldVector()

Vec2 Box2D.Body.GetWorldVector ( Vec2  localVector)

Get a world vector on a body given a local vector.

Parameters
localVectorThe local vector
Returns
The world vector on the body

◆ operator!=()

static bool Box2D.Body.operator!= ( Body  left,
Body  right 
)
static

Check if two Body objects are not equal.

Parameters
leftThe first Body object
rightThe second Body object
Returns
True if the two Body objects are not equal, false otherwise

◆ operator==()

static bool Box2D.Body.operator== ( Body  left,
Body  right 
)
static

Check if two Body objects are equal.

Parameters
leftThe first Body object
rightThe second Body object
Returns
True if the two Body objects are equal, false otherwise

◆ ReferenceEquals()

bool Box2D.Body.ReferenceEquals ( Body  other)

Check if this Body object refers to the same Body as another Body object.

Parameters
otherThe other Body object to compare with
Returns
True if this Body object refers to the same Body as the other Body object, false otherwise

◆ SetTargetTransform()

void Box2D.Body.SetTargetTransform ( Transform  target,
float  timeStep 
)
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.

Parameters
targetThe target transform
timeStepThe time step

Property Documentation

◆ AABB

AABB Box2D.Body.AABB
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

◆ AngularDamping

float Box2D.Body.AngularDamping
getset

The angular damping.

Normally this is set in BodyDef before creation

◆ AngularVelocity

float Box2D.Body.AngularVelocity
getset

The angular velocity of the body in radians per second.

In radians per second

◆ Awake

bool Box2D.Body.Awake
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.

◆ Bullet

bool Box2D.Body.Bullet
getset

The bullet flag of the body.

A bullet does continuous collision detection against dynamic bodies (but not other bullets)

◆ Contacts

unsafe ReadOnlySpan<ContactData> Box2D.Body.Contacts
get

The touching contact data for this body.

Note: Box2D uses speculative collision so some contact points may be separated.

◆ FixedRotation

bool Box2D.Body.FixedRotation
getset

The fixed rotation flag of the body.

Setting this causes the mass to be reset in all cases

◆ GravityScale

float Box2D.Body.GravityScale
getset

The gravity scale.

Normally this is set in BodyDef before creation

◆ LinearDamping

float Box2D.Body.LinearDamping
getset

The linear damping.

Normally this is set in BodyDef before creation

◆ LinearVelocity

Vec2 Box2D.Body.LinearVelocity
getset

The linear velocity of the body's center of mass.

Usually in meters per second

◆ Position

Vec2 Box2D.Body.Position
get

The world position of the body.

This is the location of the body origin

◆ SleepEnabled

bool Box2D.Body.SleepEnabled
getset

Option to enable or disable sleeping for this body.

If sleeping is disabled the body will wake

◆ Transform

Transform Box2D.Body.Transform
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.

◆ Valid

bool Box2D.Body.Valid
get

Body identifier validation.

Returns
True if the body id is valid

Can be used to detect orphaned ids. Provides validation for up to 64K allocations


The documentation for this struct was generated from the following file: