Table of Contents

Struct BodyReference

Namespace
BepuPhysics
Assembly
BepuPhysics.dll

Convenience structure for directly referring to a body's properties.

public struct BodyReference
Inherited Members

Remarks

Note that this type makes no attempt to protect against unsafe modification of body properties, nor does modifying its properties try to wake up bodies if they are asleep.

Constructors

BodyReference(BodyHandle, Bodies)

Constructs a new body reference.

public BodyReference(BodyHandle handle, Bodies bodies)

Parameters

handle BodyHandle

Handle of the body to refer to.

bodies Bodies

Collection containing the body.

Remarks

Fields

Bodies

The bodies collection containing the body.

public Bodies Bodies

Field Value

Bodies

Handle

Handle of the body that this reference refers to.

public BodyHandle Handle

Field Value

BodyHandle

Properties

Activity

Gets a reference to the body's activity state.

public ref BodyActivity Activity { get; }

Property Value

BodyActivity

Awake

Gets or sets whether the body is in the active set. Setting this to true will attempt to wake the body; setting it to false will force the body and any constraint-connected bodies asleep.

public bool Awake { get; set; }

Property Value

bool

BoundingBox

Gets a copy of the body's bounding box. If the body has no shape, the bounding box has a min at float.MaxValue and a max at float.MinValue.

public BoundingBox BoundingBox { get; }

Property Value

BoundingBox

Collidable

Gets a reference to the body's collidable.

public ref Collidable Collidable { get; }

Property Value

Collidable

CollidableReference

Gets a CollidableReference for this body. CollidableReferences uniquely identify a collidable object in a simulation by including both the dynamic/kinematic/static state of the object and its handle.

Despite an unfortunate naming collision, CollidableReferences are distinct from a direct reference to a body's collidable data, which you can get from the Collidable property.

public CollidableReference CollidableReference { get; }

Property Value

CollidableReference

Constraints

Gets a reference to the list of the body's connected constraints.

public ref QuickList<BodyConstraintReference> Constraints { get; }

Property Value

QuickList<BodyConstraintReference>

Dynamics

Gets a reference to the body's solver-relevant state, including pose, velocity, and inertia.

public ref BodyDynamics Dynamics { get; }

Property Value

BodyDynamics

Exists

Gets whether the body reference exists within the body set. True if the handle maps to a valid memory location that agrees that the handle points to it, false otherwise.

public bool Exists { get; }

Property Value

bool

HasLockedInertia

Gets whether the body has locked inertia, meaning its inverse inertia tensor is zero.

public bool HasLockedInertia { get; }

Property Value

bool

Kinematic

Gets whether the body is kinematic, meaning its inverse inertia and mass are all zero.

public bool Kinematic { get; }

Property Value

bool

LocalInertia

Gets a reference to the body's local inertia.

public ref BodyInertia LocalInertia { get; }

Property Value

BodyInertia

MemoryLocation

Gets a reference to the body's memory location stored in the handle to location mapping.

public ref BodyMemoryLocation MemoryLocation { get; }

Property Value

BodyMemoryLocation

MotionState

Gets a reference to the body's motion state, including both pose and velocity.

public ref MotionState MotionState { get; }

Property Value

MotionState

Pose

Gets a reference to the body's pose.

public ref RigidPose Pose { get; }

Property Value

RigidPose

Velocity

Gets a reference to the body's velocity.

public ref BodyVelocity Velocity { get; }

Property Value

BodyVelocity

Methods

ApplyAngularImpulse(Vector3)

Applies an angular impulse to an angular velocity. Does not wake the body up.

public void ApplyAngularImpulse(Vector3 angularImpulse)

Parameters

angularImpulse Vector3

Impulse to apply to the velocity.

ApplyAngularImpulse(Vector3, in Symmetric3x3, ref Vector3)

Applies an angular impulse to an angular velocity. Does not wake the body up.

public static void ApplyAngularImpulse(Vector3 angularImpulse, in Symmetric3x3 inverseInertiaTensor, ref Vector3 angularVelocity)

Parameters

angularImpulse Vector3

Impulse to apply to the velocity.

inverseInertiaTensor Symmetric3x3

Inverse inertia tensor to transform the impulse with.

angularVelocity Vector3

Angular velocity to be modified.

ApplyDescription(in BodyDescription)

Sets a body's properties according to a description. Properly handles any transitions between dynamic and kinematic and between shapeless and shapeful. If the body is becoming kinematic, any constraints which only contain kinematic bodies will be removed. Wakes up the body and updates its bounds in the broad phase.

public void ApplyDescription(in BodyDescription description)

Parameters

description BodyDescription

Description of the body.

ApplyImpulse(in BodySet, int, Vector3, Vector3)

Applies an impulse to a body by index. Does not wake the body up.

public static void ApplyImpulse(in BodySet set, int index, Vector3 impulse, Vector3 impulseOffset)

Parameters

set BodySet

Body set containing the body to apply an impulse to.

index int

Index of the body in the body set.

impulse Vector3

Impulse to apply to the body.

impulseOffset Vector3

World space offset from the center of the body to apply the impulse at.

ApplyImpulse(Vector3, Vector3)

Applies an impulse to a body at the given world space offset. Does not modify activity states.

public void ApplyImpulse(Vector3 impulse, Vector3 impulseOffset)

Parameters

impulse Vector3

Impulse to apply to the body.

impulseOffset Vector3

World space offset to apply the impulse at.

ApplyImpulse(Vector3, Vector3, ref BodyInertia, ref RigidPose, ref BodyVelocity)

Applies an impulse to a body by index. Does not wake the body up.

public static void ApplyImpulse(Vector3 impulse, Vector3 impulseOffset, ref BodyInertia localInertia, ref RigidPose pose, ref BodyVelocity velocity)

Parameters

impulse Vector3

Impulse to apply to the body.

impulseOffset Vector3

World space offset from the center of the body to apply the impulse at.

localInertia BodyInertia

Local inertia of the body to apply impulse to.

pose RigidPose

Pose of the body to apply impulse to.

velocity BodyVelocity

Velocity of the body to apply impulse to.

ApplyLinearImpulse(Vector3)

Applies an impulse to a linear velocity. Does not wake the body up.

public void ApplyLinearImpulse(Vector3 impulse)

Parameters

impulse Vector3

Impulse to apply to the velocity.

ApplyLinearImpulse(Vector3, float, ref Vector3)

Applies an impulse to a linear velocity. Does not wake the body up.

public static void ApplyLinearImpulse(Vector3 impulse, float inverseMass, ref Vector3 linearVelocity)

Parameters

impulse Vector3

Impulse to apply to the velocity.

inverseMass float

Inverse mass to transform the impulse with.

linearVelocity Vector3

Linear velocity to be modified.

BecomeKinematic()

If the body is dynamic, turns the body kinematic by setting all inverse inertia and mass values to zero and activates it. Any constraints connected to the body that now only contain kinematic references are removed. If the body is kinematic, does nothing.

public void BecomeKinematic()

ComputeInverseInertia(out Symmetric3x3)

Computes the world space inverse inertia tensor for the body based on the LocalInertia and Pose.

public void ComputeInverseInertia(out Symmetric3x3 inverseInertia)

Parameters

inverseInertia Symmetric3x3

GetBoundsReferencesFromBroadPhase(out Vector3*, out Vector3*)

Gets direct pointers to the body's bounding box minimum and maximum in the broad phase. Outputs null if the body has no shape.

public bool GetBoundsReferencesFromBroadPhase(out Vector3* min, out Vector3* max)

Parameters

min Vector3*

Pointer to the bounding box minimum in the broad phase. Null if the body has no shape.

max Vector3*

Pointer to the bounding box maximum in the broad phase. Null if the body has no shape.

Returns

bool

True if the body has a shape and bounds, false otherwise.

GetDescription(out BodyDescription)

Gets a description of the body.

public void GetDescription(out BodyDescription description)

Parameters

description BodyDescription

Description of the body.

GetVelocityForOffset(Vector3, out Vector3)

Computes the velocity of a world space offset point attached to the body.

public void GetVelocityForOffset(Vector3 offset, out Vector3 velocity)

Parameters

offset Vector3

World space offset from the body's center to the point to measure.

velocity Vector3

Effective velocity of the point if it were attached to the body.

SetLocalInertia(in BodyInertia)

Sets the body's local inertia to the provided inertia. Wakes up the body and correctly handles any transition between dynamic and kinematic states. If the body moves from dynamic to kinematic, any constraints connected to the body that now only contain kinematic references are removed.

public void SetLocalInertia(in BodyInertia localInertia)

Parameters

localInertia BodyInertia

SetShape(TypedIndex)

Changes the shape of a body. Properly handles the transition between shapeless and shapeful. If the body is inactive, it will be forced awake. Updates the bounds of the body in the broad phase.

public void SetShape(TypedIndex newShape)

Parameters

newShape TypedIndex

Index of the new shape to use for the body.

UpdateBounds()

Updates the body's bounds in the broad phase for its current state. Does not include velocity expansion. Does nothing if the body has no shape.

public void UpdateBounds()

Remarks

Can be useful if you made modifications to the body's state that you want reflected in the broad phase before the next timestep. For example, if you want to perform ray casts against the broad phase after moving objects around directly, their bounds must be updated or else the broad phase bounds will be out of date and the ray will likely miss.

Operators

implicit operator BodyHandle(BodyReference)

Implicitly converts a BodyReference to the BodyHandle that the body reference was created from.

public static implicit operator BodyHandle(BodyReference reference)

Parameters

reference BodyReference

Body reference to extract the handle from.

Returns

BodyHandle