Jolt Physics
A multi core friendly Game Physics Engine
|
#include <Body.h>
Public Member Functions | |
JPH_OVERRIDE_NEW_DELETE | Body ()=default |
Default constructor. | |
~Body () | |
Destructor | |
const BodyID & | GetID () const |
Get the id of this body. | |
bool | IsActive () const |
If this body is currently actively simulating (true) or sleeping (false) | |
bool | IsStatic () const |
Check if this body is static (not movable) | |
bool | IsKinematic () const |
Check if this body is kinematic (keyframed), which means that it will move according to its current velocity, but forces don't affect it. | |
bool | IsDynamic () const |
Check if this body is dynamic, which means that it moves and forces can act on it. | |
bool | CanBeKinematicOrDynamic () const |
Check if a body could be made kinematic or dynamic (if it was created dynamic or with mAllowDynamicOrKinematic set to true) | |
void | SetIsSensor (bool inIsSensor) |
bool | IsSensor () const |
Check if this body is a sensor. | |
void | SetUseManifoldReduction (bool inUseReduction) |
bool | GetUseManifoldReduction () const |
Check if this body can use manifold reduction. | |
bool | GetUseManifoldReductionWithBody (const Body &inBody2) const |
Checks if the combination of this body and inBody2 should use manifold reduction. | |
EMotionType | GetMotionType () const |
Motion type of this body. | |
void | SetMotionType (EMotionType inMotionType) |
BroadPhaseLayer | GetBroadPhaseLayer () const |
Get broadphase layer, this determines in which broad phase sub-tree the object is placed. | |
ObjectLayer | GetObjectLayer () const |
Get object layer, this determines which other objects it collides with. | |
const CollisionGroup & | GetCollisionGroup () const |
Collision group and sub-group ID, determines which other objects it collides with. | |
CollisionGroup & | GetCollisionGroup () |
void | SetCollisionGroup (const CollisionGroup &inGroup) |
bool | GetAllowSleeping () const |
If this body can go to sleep. Note that disabling sleeping on a sleeping object wil not wake it up. | |
void | SetAllowSleeping (bool inAllow) |
float | GetFriction () const |
Friction (dimensionless number, usually between 0 and 1, 0 = no friction, 1 = friction force equals force that presses the two bodies together) | |
void | SetFriction (float inFriction) |
float | GetRestitution () const |
Restitution (dimensionless number, usually between 0 and 1, 0 = completely inelastic collision response, 1 = completely elastic collision response) | |
void | SetRestitution (float inRestitution) |
Vec3 | GetLinearVelocity () const |
Get world space linear velocity of the center of mass (unit: m/s) | |
void | SetLinearVelocity (Vec3Arg inLinearVelocity) |
Set world space linear velocity of the center of mass (unit: m/s) | |
void | SetLinearVelocityClamped (Vec3Arg inLinearVelocity) |
Set world space linear velocity of the center of mass, will make sure the value is clamped against the maximum linear velocity. | |
Vec3 | GetAngularVelocity () const |
Get world space angular velocity of the center of mass (unit: rad/s) | |
void | SetAngularVelocity (Vec3Arg inAngularVelocity) |
Set world space angular velocity of the center of mass (unit: rad/s) | |
void | SetAngularVelocityClamped (Vec3Arg inAngularVelocity) |
Set world space angular velocity of the center of mass, will make sure the value is clamped against the maximum angular velocity. | |
Vec3 | GetPointVelocityCOM (Vec3Arg inPointRelativeToCOM) const |
Velocity of point inPoint (in center of mass space, e.g. on the surface of the body) of the body (unit: m/s) | |
Vec3 | GetPointVelocity (RVec3Arg inPoint) const |
Velocity of point inPoint (in world space, e.g. on the surface of the body) of the body (unit: m/s) | |
void | AddForce (Vec3Arg inForce) |
Add force (unit: N) at center of mass for the next time step, will be reset after the next call to PhysicsSimulation::Update. | |
void | AddForce (Vec3Arg inForce, RVec3Arg inPosition) |
Add force (unit: N) at inPosition for the next time step, will be reset after the next call to PhysicsSimulation::Update. | |
void | AddTorque (Vec3Arg inTorque) |
Add torque (unit: N m) for the next time step, will be reset after the next call to PhysicsSimulation::Update. | |
Vec3 | GetAccumulatedForce () const |
Vec3 | GetAccumulatedTorque () const |
Mat44 | GetInverseInertia () const |
Get inverse inertia tensor in world space. | |
void | AddImpulse (Vec3Arg inImpulse) |
Add impulse to center of mass (unit: kg m/s) | |
void | AddImpulse (Vec3Arg inImpulse, RVec3Arg inPosition) |
Add impulse to point in world space (unit: kg m/s) | |
void | AddAngularImpulse (Vec3Arg inAngularImpulse) |
Add angular impulse in world space (unit: N m s) | |
void | MoveKinematic (RVec3Arg inTargetPosition, QuatArg inTargetRotation, float inDeltaTime) |
Set velocity of body such that it will be positioned at inTargetPosition/Rotation in inDeltaTime seconds. | |
bool | ApplyBuoyancyImpulse (RVec3Arg inSurfacePosition, Vec3Arg inSurfaceNormal, float inBuoyancy, float inLinearDrag, float inAngularDrag, Vec3Arg inFluidVelocity, Vec3Arg inGravity, float inDeltaTime) |
bool | IsInBroadPhase () const |
Check if this body has been added to the physics system. | |
bool | IsCollisionCacheInvalid () const |
Check if this body has been changed in such a way that the collision cache should be considered invalid for any body interacting with this body. | |
const Shape * | GetShape () const |
Get the shape of this body. | |
RVec3 | GetPosition () const |
World space position of the body. | |
Quat | GetRotation () const |
World space rotation of the body. | |
RMat44 | GetWorldTransform () const |
Calculates the transform of this body. | |
RVec3 | GetCenterOfMassPosition () const |
Gets the world space position of this body's center of mass. | |
RMat44 | GetCenterOfMassTransform () const |
Calculates the transform for this body's center of mass. | |
RMat44 | GetInverseCenterOfMassTransform () const |
Calculates the inverse of the transform for this body's center of mass. | |
const AABox & | GetWorldSpaceBounds () const |
Get world space bounding box. | |
const MotionProperties * | GetMotionProperties () const |
Access to the motion properties. | |
MotionProperties * | GetMotionProperties () |
const MotionProperties * | GetMotionPropertiesUnchecked () const |
Access to the motion properties (version that does not check if the object is kinematic or dynamic) | |
MotionProperties * | GetMotionPropertiesUnchecked () |
uint64 | GetUserData () const |
Access to the user data, can be used for anything by the application. | |
void | SetUserData (uint64 inUserData) |
Vec3 | GetWorldSpaceSurfaceNormal (const SubShapeID &inSubShapeID, RVec3Arg inPosition) const |
Get surface normal of a particular sub shape and its world space surface position on this body. | |
TransformedShape | GetTransformedShape () const |
Get the transformed shape of this body, which can be used to do collision detection outside of a body lock. | |
BodyCreationSettings | GetBodyCreationSettings () const |
Debug function to convert a body back to a body creation settings object to be able to save/recreate the body later. | |
Public Member Functions inherited from NonCopyable | |
NonCopyable ()=default | |
NonCopyable (const NonCopyable &)=delete | |
void | operator= (const NonCopyable &)=delete |
Static Public Attributes | |
static Body | sFixedToWorld |
A dummy body that can be used by constraints to attach a constraint to the world instead of another body. | |
static constexpr uint32 | cInactiveIndex = uint32(-1) |
Constant indicating that body is not active. | |
Friends | |
class | BodyManager |
THESE FUNCTIONS ARE FOR INTERNAL USE ONLY AND SHOULD NOT BE CALLED BY THE APPLICATION | |
enum class | ECanSleep { CannotSleep = 0 , CanSleep = 1 } |
void | AddPositionStep (Vec3Arg inLinearVelocityTimesDeltaTime) |
Update position using an Euler step (used during position integrate & constraint solving) | |
void | SubPositionStep (Vec3Arg inLinearVelocityTimesDeltaTime) |
void | AddRotationStep (Vec3Arg inAngularVelocityTimesDeltaTime) |
Update rotation using an Euler step (using during position integrate & constraint solving) | |
void | SubRotationStep (Vec3Arg inAngularVelocityTimesDeltaTime) |
void | SetInBroadPhaseInternal (bool inInBroadPhase) |
Flag if body is in the broadphase (should only be called by the BroadPhase) | |
bool | InvalidateContactCacheInternal () |
Invalidate the contact cache (should only be called by the BodyManager), will be reset the next simulation step. Returns true if the contact cache was still valid. | |
void | ValidateContactCacheInternal () |
Reset the collision cache invalid flag (should only be called by the BodyManager). | |
void | CalculateWorldSpaceBoundsInternal () |
Updates world space bounding box (should only be called by the PhysicsSystem) | |
void | SetPositionAndRotationInternal (RVec3Arg inPosition, QuatArg inRotation) |
Function to update body's position (should only be called by the BodyInterface since it also requires updating the broadphase) | |
void | UpdateCenterOfMassInternal (Vec3Arg inPreviousCenterOfMass, bool inUpdateMassProperties) |
void | SetShapeInternal (const Shape *inShape, bool inUpdateMassProperties) |
uint32 | GetIndexInActiveBodiesInternal () const |
Access to the index in the BodyManager::mActiveBodies list. | |
ECanSleep | UpdateSleepStateInternal (float inDeltaTime, float inMaxMovement, float inTimeBeforeSleep) |
Update eligibility for sleeping. | |
void | SaveState (StateRecorder &inStream) const |
Saving state for replay. | |
void | RestoreState (StateRecorder &inStream) |
Restoring state for replay. | |
static bool | sFindCollidingPairsCanCollide (const Body &inBody1, const Body &inBody2) |
A rigid body that can be simulated using the physics system
Note that internally all properties (position, velocity etc.) are tracked relative to the center of mass of the object to simplify the simulation of the object.
The offset between the position of the body and the center of mass position of the body is GetShape()->GetCenterOfMass(). The functions that get/set the position of the body all indicate if they are relative to the center of mass or to the original position in which the shape was created.
The linear velocity is also velocity of the center of mass, to correct for this: \(VelocityCOM = Velocity - AngularVelocity \times ShapeCOM\).
|
strong |
|
default |
Default constructor.
|
inline |
Destructor
|
inline |
Add angular impulse in world space (unit: N m s)
|
inline |
Add force (unit: N) at center of mass for the next time step, will be reset after the next call to PhysicsSimulation::Update.
Add force (unit: N) at inPosition for the next time step, will be reset after the next call to PhysicsSimulation::Update.
|
inline |
Add impulse to center of mass (unit: kg m/s)
Add impulse to point in world space (unit: kg m/s)
|
inline |
Update position using an Euler step (used during position integrate & constraint solving)
|
inline |
Update rotation using an Euler step (using during position integrate & constraint solving)
|
inline |
Add torque (unit: N m) for the next time step, will be reset after the next call to PhysicsSimulation::Update.
bool Body::ApplyBuoyancyImpulse | ( | RVec3Arg | inSurfacePosition, |
Vec3Arg | inSurfaceNormal, | ||
float | inBuoyancy, | ||
float | inLinearDrag, | ||
float | inAngularDrag, | ||
Vec3Arg | inFluidVelocity, | ||
Vec3Arg | inGravity, | ||
float | inDeltaTime ) |
Applies an impulse to the body that simulates fluid buoyancy and drag
inSurfacePosition | Position on the fluid surface in world space |
inSurfaceNormal | Normal of the fluid surface (should point up) |
inBuoyancy | The buoyancy factor for the body. 1 = neutral body, < 1 sinks, > 1 floats. Note that we don't use the fluid density since it is harder to configure than a simple number between [0, 2] |
inLinearDrag | Linear drag factor that slows down the body when in the fluid (approx. 0.5) |
inAngularDrag | Angular drag factor that slows down rotation when the body is in the fluid (approx. 0.01) |
inFluidVelocity | The average velocity of the fluid (in m/s) in which the body resides |
inGravity | The graviy vector (pointing down) |
inDeltaTime | Delta time of the next simulation step (in s) |
void Body::CalculateWorldSpaceBoundsInternal | ( | ) |
Updates world space bounding box (should only be called by the PhysicsSystem)
|
inline |
Check if a body could be made kinematic or dynamic (if it was created dynamic or with mAllowDynamicOrKinematic set to true)
|
inline |
|
inline |
|
inline |
If this body can go to sleep. Note that disabling sleeping on a sleeping object wil not wake it up.
|
inline |
Get world space angular velocity of the center of mass (unit: rad/s)
BodyCreationSettings Body::GetBodyCreationSettings | ( | ) | const |
Debug function to convert a body back to a body creation settings object to be able to save/recreate the body later.
|
inline |
Get broadphase layer, this determines in which broad phase sub-tree the object is placed.
|
inline |
Gets the world space position of this body's center of mass.
|
inline |
Calculates the transform for this body's center of mass.
|
inline |
|
inline |
Collision group and sub-group ID, determines which other objects it collides with.
|
inline |
Friction (dimensionless number, usually between 0 and 1, 0 = no friction, 1 = friction force equals force that presses the two bodies together)
|
inline |
Get the id of this body.
|
inline |
Access to the index in the BodyManager::mActiveBodies list.
|
inline |
Calculates the inverse of the transform for this body's center of mass.
|
inline |
Get inverse inertia tensor in world space.
|
inline |
Get world space linear velocity of the center of mass (unit: m/s)
|
inline |
|
inline |
Access to the motion properties.
|
inline |
|
inline |
Access to the motion properties (version that does not check if the object is kinematic or dynamic)
|
inline |
Motion type of this body.
|
inline |
Get object layer, this determines which other objects it collides with.
Velocity of point inPoint (in world space, e.g. on the surface of the body) of the body (unit: m/s)
Velocity of point inPoint (in center of mass space, e.g. on the surface of the body) of the body (unit: m/s)
|
inline |
World space position of the body.
|
inline |
Restitution (dimensionless number, usually between 0 and 1, 0 = completely inelastic collision response, 1 = completely elastic collision response)
|
inline |
World space rotation of the body.
|
inline |
Get the shape of this body.
|
inline |
Get the transformed shape of this body, which can be used to do collision detection outside of a body lock.
|
inline |
Check if this body can use manifold reduction.
|
inline |
Checks if the combination of this body and inBody2 should use manifold reduction.
|
inline |
Access to the user data, can be used for anything by the application.
|
inline |
Get world space bounding box.
|
inline |
Get surface normal of a particular sub shape and its world space surface position on this body.
|
inline |
Calculates the transform of this body.
|
inline |
Invalidate the contact cache (should only be called by the BodyManager), will be reset the next simulation step. Returns true if the contact cache was still valid.
|
inline |
If this body is currently actively simulating (true) or sleeping (false)
|
inline |
Check if this body has been changed in such a way that the collision cache should be considered invalid for any body interacting with this body.
|
inline |
Check if this body is dynamic, which means that it moves and forces can act on it.
|
inline |
Check if this body has been added to the physics system.
|
inline |
Check if this body is kinematic (keyframed), which means that it will move according to its current velocity, but forces don't affect it.
|
inline |
Check if this body is a sensor.
|
inline |
Check if this body is static (not movable)
Set velocity of body such that it will be positioned at inTargetPosition/Rotation in inDeltaTime seconds.
void Body::RestoreState | ( | StateRecorder & | inStream | ) |
Restoring state for replay.
void Body::SaveState | ( | StateRecorder & | inStream | ) | const |
Saving state for replay.
void Body::SetAllowSleeping | ( | bool | inAllow | ) |
|
inline |
Set world space angular velocity of the center of mass (unit: rad/s)
|
inline |
Set world space angular velocity of the center of mass, will make sure the value is clamped against the maximum angular velocity.
|
inline |
|
inline |
|
inline |
Flag if body is in the broadphase (should only be called by the BroadPhase)
|
inline |
Change the body to a sensor. A sensor will receive collision callbacks, but will not cause any collision responses and can be used as a trigger volume. The cheapest sensor (in terms of CPU usage) is a sensor with motion type Static (they can be moved around using BodyInterface::SetPosition/SetPositionAndRotation). These sensors will only detect collisions with active Dynamic or Kinematic bodies. As soon as a body go to sleep, the contact point with the sensor will be lost. If you make a sensor Dynamic or Kinematic and activate them, the sensor will be able to detect collisions with sleeping bodies too. An active sensor will never go to sleep automatically. When you make a Dynamic or Kinematic sensor, make sure it is in an ObjectLayer that does not collide with Static bodies or other sensors to avoid extra overhead in the broad phase.
|
inline |
Set world space linear velocity of the center of mass (unit: m/s)
|
inline |
Set world space linear velocity of the center of mass, will make sure the value is clamped against the maximum linear velocity.
void Body::SetMotionType | ( | EMotionType | inMotionType | ) |
Function to update body's position (should only be called by the BodyInterface since it also requires updating the broadphase)
|
inline |
void Body::SetShapeInternal | ( | const Shape * | inShape, |
bool | inUpdateMassProperties ) |
Function to update a body's shape (should only be called by the BodyInterface since it also requires updating the broadphase)
inShape | The new shape for this body |
inUpdateMassProperties | When true, the mass and inertia tensor is recalculated |
|
inline |
If PhysicsSettings::mUseManifoldReduction is true, this allows turning off manifold reduction for this specific body. Manifold reduction by default will combine contacts that come from different SubShapeIDs (e.g. different triangles or different compound shapes). If the application requires tracking exactly which SubShapeIDs are in contact, you can turn off manifold reduction. Note that this comes at a performance cost.
|
inline |
|
inlinestatic |
Helper function for BroadPhase::FindCollidingPairs that returns true when two bodies can collide It assumes that body 1 is dynamic and active and guarantees that it body 1 collides with body 2 that body 2 will not collide with body 1 in order to avoid finding duplicate collision pairs
|
inline |
|
inline |
void Body::UpdateCenterOfMassInternal | ( | Vec3Arg | inPreviousCenterOfMass, |
bool | inUpdateMassProperties ) |
Updates the center of mass and optionally mass propertes after shifting the center of mass or changes to the shape (should only be called by the BodyInterface since it also requires updating the broadphase)
inPreviousCenterOfMass | Center of mass of the shape before the alterations |
inUpdateMassProperties | When true, the mass and inertia tensor is recalculated |
Body::ECanSleep Body::UpdateSleepStateInternal | ( | float | inDeltaTime, |
float | inMaxMovement, | ||
float | inTimeBeforeSleep ) |
Update eligibility for sleeping.
|
inline |
Reset the collision cache invalid flag (should only be called by the BodyManager).
|
friend |
Constant indicating that body is not active.
|
static |
A dummy body that can be used by constraints to attach a constraint to the world instead of another body.