Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
MotionProperties Class Reference

The Body class only keeps track of state for static bodies, the MotionProperties class keeps the additional state needed for a moving Body. It has a 1-on-1 relationship with the body. More...

#include <MotionProperties.h>

Inheritance diagram for MotionProperties:
SoftBodyMotionProperties

Public Member Functions

JPH_OVERRIDE_NEW_DELETE EMotionQuality GetMotionQuality () const
 Motion quality, or how well it detects collisions when it has a high velocity.
 
EAllowedDOFs GetAllowedDOFs () const
 Get the allowed degrees of freedom that this body has (this can be changed by calling SetMassProperties)
 
bool GetAllowSleeping () const
 If this body can go to sleep.
 
Vec3 GetLinearVelocity () const
 Get world space linear velocity of the center of mass.
 
void SetLinearVelocity (Vec3Arg inLinearVelocity)
 Set world space linear velocity of the center of mass.
 
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.
 
void SetAngularVelocity (Vec3Arg inAngularVelocity)
 Set world space angular velocity of the center of mass.
 
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.
 
void MoveKinematic (Vec3Arg inDeltaPosition, QuatArg inDeltaRotation, float inDeltaTime)
 Set velocity of body such that it will be rotate/translate by inDeltaPosition/Rotation in inDeltaTime seconds.
 
void ClampLinearVelocity ()
 Clamp velocity according to limit.
 
void ClampAngularVelocity ()
 
float GetLinearDamping () const
 Get linear damping: dv/dt = -c * v. c must be between 0 and 1 but is usually close to 0.
 
void SetLinearDamping (float inLinearDamping)
 
float GetAngularDamping () const
 Get angular damping: dw/dt = -c * w. c must be between 0 and 1 but is usually close to 0.
 
void SetAngularDamping (float inAngularDamping)
 
float GetGravityFactor () const
 Get gravity factor (1 = normal gravity, 0 = no gravity)
 
void SetGravityFactor (float inGravityFactor)
 
void SetMassProperties (EAllowedDOFs inAllowedDOFs, const MassProperties &inMassProperties)
 Set the mass and inertia tensor.
 
float GetInverseMass () const
 Get inverse mass (1 / mass). Should only be called on a dynamic object (static or kinematic bodies have infinite mass so should be treated as 1 / mass = 0)
 
float GetInverseMassUnchecked () const
 
void SetInverseMass (float inInverseMass)
 
Vec3 GetInverseInertiaDiagonal () const
 Diagonal of inverse inertia matrix: D. Should only be called on a dynamic object (static or kinematic bodies have infinite mass so should be treated as D = 0)
 
Quat GetInertiaRotation () const
 Rotation (R) that takes inverse inertia diagonal to local space: \(I_{body}^{-1} = R \: D \: R^{-1}\).
 
void SetInverseInertia (Vec3Arg inDiagonal, QuatArg inRot)
 
void ScaleToMass (float inMass)
 
Mat44 GetLocalSpaceInverseInertia () const
 Get inverse inertia matrix ( \(I_{body}^{-1}\)). Will be a matrix of zeros for a static or kinematic object.
 
Mat44 GetLocalSpaceInverseInertiaUnchecked () const
 Same as GetLocalSpaceInverseInertia() but doesn't check if the body is dynamic.
 
Mat44 GetInverseInertiaForRotation (Mat44Arg inRotation) const
 Get inverse inertia matrix ( \(I^{-1}\)) for a given object rotation (translation will be ignored). Zero if object is static or kinematic.
 
JPH_INLINE Vec3 MultiplyWorldSpaceInverseInertiaByVector (QuatArg inBodyRotation, Vec3Arg inV) const
 Multiply a vector with the inverse world space inertia tensor ( \(I_{world}^{-1}\)). Zero if object is static or kinematic.
 
JPH_INLINE 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)
 
JPH_INLINE Vec3 GetAccumulatedForce () const
 
JPH_INLINE Vec3 GetAccumulatedTorque () const
 
JPH_INLINE void ResetForce ()
 
JPH_INLINE void ResetTorque ()
 
JPH_INLINE void ResetMotion ()
 
JPH_INLINE UVec4 GetLinearDOFsMask () const
 Returns a vector where the linear components that are not allowed by mAllowedDOFs are set to 0 and the rest to 0xffffffff.
 
JPH_INLINE Vec3 LockTranslation (Vec3Arg inV) const
 Takes a translation vector inV and returns a vector where the components that are not allowed by mAllowedDOFs are set to 0.
 
JPH_INLINE UVec4 GetAngularDOFsMask () const
 Returns a vector where the angular components that are not allowed by mAllowedDOFs are set to 0 and the rest to 0xffffffff.
 
JPH_INLINE Vec3 LockAngular (Vec3Arg inV) const
 Takes an angular velocity / torque vector inV and returns a vector where the components that are not allowed by mAllowedDOFs are set to 0.
 
void SetNumVelocityStepsOverride (uint inN)
 Used only when this body is dynamic and colliding. Override for the number of solver velocity iterations to run, 0 means use the default in PhysicsSettings::mNumVelocitySteps. The number of iterations to use is the max of all contacts and constraints in the island.
 
uint GetNumVelocityStepsOverride () const
 
void SetNumPositionStepsOverride (uint inN)
 Used only when this body is dynamic and colliding. Override for the number of solver position iterations to run, 0 means use the default in PhysicsSettings::mNumPositionSteps. The number of iterations to use is the max of all contacts and constraints in the island.
 
uint GetNumPositionStepsOverride () const
 
void ApplyGyroscopicForceInternal (QuatArg inBodyRotation, float inDeltaTime)
 Apply the gyroscopic force (aka Dzhanibekov effect, see https://en.wikipedia.org/wiki/Tennis_racket_theorem)
 
void ApplyForceTorqueAndDragInternal (QuatArg inBodyRotation, Vec3Arg inGravity, float inDeltaTime)
 Apply all accumulated forces, torques and drag (should only be called by the PhysicsSystem)
 
uint32 GetIslandIndexInternal () const
 Access to the island index.
 
void SetIslandIndexInternal (uint32 inIndex)
 
uint32 GetIndexInActiveBodiesInternal () const
 Access to the index in the active bodies array.
 
void ResetSleepTestSpheres (const RVec3 *inPoints)
 Reset spheres to center around inPoints with radius 0.
 
void ResetSleepTestTimer ()
 Reset the sleep test timer without resetting the sleep test spheres.
 
ECanSleep AccumulateSleepTime (float inDeltaTime, float inTimeBeforeSleep)
 Accumulate sleep time and return if a body can go to sleep.
 
void SaveState (StateRecorder &inStream) const
 Saving state for replay.
 
void RestoreState (StateRecorder &inStream)
 Restoring state for replay.
 
Velocity limits
float GetMaxLinearVelocity () const
 Maximum linear velocity that a body can achieve. Used to prevent the system from exploding.
 
void SetMaxLinearVelocity (float inLinearVelocity)
 
float GetMaxAngularVelocity () const
 Maximum angular velocity that a body can achieve. Used to prevent the system from exploding.
 
void SetMaxAngularVelocity (float inAngularVelocity)
 
Update linear and angular velocity (used during constraint solving)
void AddLinearVelocityStep (Vec3Arg inLinearVelocityChange)
 
void SubLinearVelocityStep (Vec3Arg inLinearVelocityChange)
 
void AddAngularVelocityStep (Vec3Arg inAngularVelocityChange)
 
void SubAngularVelocityStep (Vec3Arg inAngularVelocityChange)
 

Static Public Attributes

static constexpr uint32 cInactiveIndex = uint32(-1)
 Constant indicating that body is not active.
 

Friends

class BodyManager
 
class Body
 

Detailed Description

The Body class only keeps track of state for static bodies, the MotionProperties class keeps the additional state needed for a moving Body. It has a 1-on-1 relationship with the body.

Member Function Documentation

◆ AccumulateSleepTime()

ECanSleep MotionProperties::AccumulateSleepTime ( float  inDeltaTime,
float  inTimeBeforeSleep 
)
inline

Accumulate sleep time and return if a body can go to sleep.

◆ AddAngularVelocityStep()

void MotionProperties::AddAngularVelocityStep ( Vec3Arg  inAngularVelocityChange)
inline

◆ AddLinearVelocityStep()

void MotionProperties::AddLinearVelocityStep ( Vec3Arg  inLinearVelocityChange)
inline

◆ ApplyForceTorqueAndDragInternal()

void MotionProperties::ApplyForceTorqueAndDragInternal ( QuatArg  inBodyRotation,
Vec3Arg  inGravity,
float  inDeltaTime 
)
inline

Apply all accumulated forces, torques and drag (should only be called by the PhysicsSystem)

◆ ApplyGyroscopicForceInternal()

void MotionProperties::ApplyGyroscopicForceInternal ( QuatArg  inBodyRotation,
float  inDeltaTime 
)
inline

Apply the gyroscopic force (aka Dzhanibekov effect, see https://en.wikipedia.org/wiki/Tennis_racket_theorem)

◆ ClampAngularVelocity()

void MotionProperties::ClampAngularVelocity ( )
inline

◆ ClampLinearVelocity()

void MotionProperties::ClampLinearVelocity ( )
inline

Clamp velocity according to limit.

◆ GetAccumulatedForce()

JPH_INLINE Vec3 MotionProperties::GetAccumulatedForce ( ) const
inline

◆ GetAccumulatedTorque()

JPH_INLINE Vec3 MotionProperties::GetAccumulatedTorque ( ) const
inline

◆ GetAllowedDOFs()

EAllowedDOFs MotionProperties::GetAllowedDOFs ( ) const
inline

Get the allowed degrees of freedom that this body has (this can be changed by calling SetMassProperties)

◆ GetAllowSleeping()

bool MotionProperties::GetAllowSleeping ( ) const
inline

If this body can go to sleep.

◆ GetAngularDamping()

float MotionProperties::GetAngularDamping ( ) const
inline

Get angular damping: dw/dt = -c * w. c must be between 0 and 1 but is usually close to 0.

◆ GetAngularDOFsMask()

JPH_INLINE UVec4 MotionProperties::GetAngularDOFsMask ( ) const
inline

Returns a vector where the angular components that are not allowed by mAllowedDOFs are set to 0 and the rest to 0xffffffff.

◆ GetAngularVelocity()

Vec3 MotionProperties::GetAngularVelocity ( ) const
inline

Get world space angular velocity of the center of mass.

◆ GetGravityFactor()

float MotionProperties::GetGravityFactor ( ) const
inline

Get gravity factor (1 = normal gravity, 0 = no gravity)

◆ GetIndexInActiveBodiesInternal()

uint32 MotionProperties::GetIndexInActiveBodiesInternal ( ) const
inline

Access to the index in the active bodies array.

◆ GetInertiaRotation()

Quat MotionProperties::GetInertiaRotation ( ) const
inline

Rotation (R) that takes inverse inertia diagonal to local space: \(I_{body}^{-1} = R \: D \: R^{-1}\).

◆ GetInverseInertiaDiagonal()

Vec3 MotionProperties::GetInverseInertiaDiagonal ( ) const
inline

Diagonal of inverse inertia matrix: D. Should only be called on a dynamic object (static or kinematic bodies have infinite mass so should be treated as D = 0)

◆ GetInverseInertiaForRotation()

Mat44 MotionProperties::GetInverseInertiaForRotation ( Mat44Arg  inRotation) const
inline

Get inverse inertia matrix ( \(I^{-1}\)) for a given object rotation (translation will be ignored). Zero if object is static or kinematic.

◆ GetInverseMass()

float MotionProperties::GetInverseMass ( ) const
inline

Get inverse mass (1 / mass). Should only be called on a dynamic object (static or kinematic bodies have infinite mass so should be treated as 1 / mass = 0)

◆ GetInverseMassUnchecked()

float MotionProperties::GetInverseMassUnchecked ( ) const
inline

◆ GetIslandIndexInternal()

uint32 MotionProperties::GetIslandIndexInternal ( ) const
inline

Access to the island index.

◆ GetLinearDamping()

float MotionProperties::GetLinearDamping ( ) const
inline

Get linear damping: dv/dt = -c * v. c must be between 0 and 1 but is usually close to 0.

◆ GetLinearDOFsMask()

JPH_INLINE UVec4 MotionProperties::GetLinearDOFsMask ( ) const
inline

Returns a vector where the linear components that are not allowed by mAllowedDOFs are set to 0 and the rest to 0xffffffff.

◆ GetLinearVelocity()

Vec3 MotionProperties::GetLinearVelocity ( ) const
inline

Get world space linear velocity of the center of mass.

◆ GetLocalSpaceInverseInertia()

Mat44 MotionProperties::GetLocalSpaceInverseInertia ( ) const
inline

Get inverse inertia matrix ( \(I_{body}^{-1}\)). Will be a matrix of zeros for a static or kinematic object.

◆ GetLocalSpaceInverseInertiaUnchecked()

Mat44 MotionProperties::GetLocalSpaceInverseInertiaUnchecked ( ) const
inline

Same as GetLocalSpaceInverseInertia() but doesn't check if the body is dynamic.

◆ GetMaxAngularVelocity()

float MotionProperties::GetMaxAngularVelocity ( ) const
inline

Maximum angular velocity that a body can achieve. Used to prevent the system from exploding.

◆ GetMaxLinearVelocity()

float MotionProperties::GetMaxLinearVelocity ( ) const
inline

Maximum linear velocity that a body can achieve. Used to prevent the system from exploding.

◆ GetMotionQuality()

JPH_OVERRIDE_NEW_DELETE EMotionQuality MotionProperties::GetMotionQuality ( ) const
inline

Motion quality, or how well it detects collisions when it has a high velocity.

◆ GetNumPositionStepsOverride()

uint MotionProperties::GetNumPositionStepsOverride ( ) const
inline

◆ GetNumVelocityStepsOverride()

uint MotionProperties::GetNumVelocityStepsOverride ( ) const
inline

◆ GetPointVelocityCOM()

JPH_INLINE Vec3 MotionProperties::GetPointVelocityCOM ( Vec3Arg  inPointRelativeToCOM) const
inline

Velocity of point inPoint (in center of mass space, e.g. on the surface of the body) of the body (unit: m/s)

◆ LockAngular()

JPH_INLINE Vec3 MotionProperties::LockAngular ( Vec3Arg  inV) const
inline

Takes an angular velocity / torque vector inV and returns a vector where the components that are not allowed by mAllowedDOFs are set to 0.

◆ LockTranslation()

JPH_INLINE Vec3 MotionProperties::LockTranslation ( Vec3Arg  inV) const
inline

Takes a translation vector inV and returns a vector where the components that are not allowed by mAllowedDOFs are set to 0.

◆ MoveKinematic()

JPH_NAMESPACE_BEGIN void MotionProperties::MoveKinematic ( Vec3Arg  inDeltaPosition,
QuatArg  inDeltaRotation,
float  inDeltaTime 
)
inline

Set velocity of body such that it will be rotate/translate by inDeltaPosition/Rotation in inDeltaTime seconds.

◆ MultiplyWorldSpaceInverseInertiaByVector()

Vec3 MotionProperties::MultiplyWorldSpaceInverseInertiaByVector ( QuatArg  inBodyRotation,
Vec3Arg  inV 
) const

Multiply a vector with the inverse world space inertia tensor ( \(I_{world}^{-1}\)). Zero if object is static or kinematic.

◆ ResetForce()

JPH_INLINE void MotionProperties::ResetForce ( )
inline

◆ ResetMotion()

JPH_INLINE void MotionProperties::ResetMotion ( )
inline

◆ ResetSleepTestSpheres()

void MotionProperties::ResetSleepTestSpheres ( const RVec3 inPoints)
inline

Reset spheres to center around inPoints with radius 0.

◆ ResetSleepTestTimer()

void MotionProperties::ResetSleepTestTimer ( )
inline

Reset the sleep test timer without resetting the sleep test spheres.

◆ ResetTorque()

JPH_INLINE void MotionProperties::ResetTorque ( )
inline

◆ RestoreState()

void MotionProperties::RestoreState ( StateRecorder inStream)

Restoring state for replay.

◆ SaveState()

void MotionProperties::SaveState ( StateRecorder inStream) const

Saving state for replay.

◆ ScaleToMass()

void MotionProperties::ScaleToMass ( float  inMass)
inline

Sets the mass to inMass and scale the inertia tensor based on the ratio between the old and new mass. Note that this only works when the current mass is finite (i.e. the body is dynamic and translational degrees of freedom are not restricted).

◆ SetAngularDamping()

void MotionProperties::SetAngularDamping ( float  inAngularDamping)
inline

◆ SetAngularVelocity()

void MotionProperties::SetAngularVelocity ( Vec3Arg  inAngularVelocity)
inline

Set world space angular velocity of the center of mass.

◆ SetAngularVelocityClamped()

void MotionProperties::SetAngularVelocityClamped ( Vec3Arg  inAngularVelocity)
inline

Set world space angular velocity of the center of mass, will make sure the value is clamped against the maximum angular velocity.

◆ SetGravityFactor()

void MotionProperties::SetGravityFactor ( float  inGravityFactor)
inline

◆ SetInverseInertia()

void MotionProperties::SetInverseInertia ( Vec3Arg  inDiagonal,
QuatArg  inRot 
)
inline

Set the inverse inertia tensor in local space by setting the diagonal and the rotation: \(I_{body}^{-1} = R \: D \: R^{-1}\). Note that mass and inertia are linearly related (e.g. inertia of a sphere with mass m and radius r is \(2/5 \: m \: r^2\)). If you change inertia, mass should probably change as well. You can use ScaleToMass to update mass and inertia at the same time. If all your rotation degrees of freedom are restricted, make sure this is zero (see EAllowedDOFs).

◆ SetInverseMass()

void MotionProperties::SetInverseMass ( float  inInverseMass)
inline

Set the inverse mass (1 / mass). Note that mass and inertia are linearly related (e.g. inertia of a sphere with mass m and radius r is \(2/5 \: m \: r^2\)). If you change mass, inertia should probably change as well. You can use ScaleToMass to update mass and inertia at the same time. If all your translation degrees of freedom are restricted, make sure this is zero (see EAllowedDOFs).

◆ SetIslandIndexInternal()

void MotionProperties::SetIslandIndexInternal ( uint32  inIndex)
inline

◆ SetLinearDamping()

void MotionProperties::SetLinearDamping ( float  inLinearDamping)
inline

◆ SetLinearVelocity()

void MotionProperties::SetLinearVelocity ( Vec3Arg  inLinearVelocity)
inline

Set world space linear velocity of the center of mass.

◆ SetLinearVelocityClamped()

void MotionProperties::SetLinearVelocityClamped ( Vec3Arg  inLinearVelocity)
inline

Set world space linear velocity of the center of mass, will make sure the value is clamped against the maximum linear velocity.

◆ SetMassProperties()

JPH_NAMESPACE_BEGIN void MotionProperties::SetMassProperties ( EAllowedDOFs  inAllowedDOFs,
const MassProperties inMassProperties 
)

Set the mass and inertia tensor.

◆ SetMaxAngularVelocity()

void MotionProperties::SetMaxAngularVelocity ( float  inAngularVelocity)
inline

◆ SetMaxLinearVelocity()

void MotionProperties::SetMaxLinearVelocity ( float  inLinearVelocity)
inline

◆ SetNumPositionStepsOverride()

void MotionProperties::SetNumPositionStepsOverride ( uint  inN)
inline

Used only when this body is dynamic and colliding. Override for the number of solver position iterations to run, 0 means use the default in PhysicsSettings::mNumPositionSteps. The number of iterations to use is the max of all contacts and constraints in the island.

◆ SetNumVelocityStepsOverride()

void MotionProperties::SetNumVelocityStepsOverride ( uint  inN)
inline

Used only when this body is dynamic and colliding. Override for the number of solver velocity iterations to run, 0 means use the default in PhysicsSettings::mNumVelocitySteps. The number of iterations to use is the max of all contacts and constraints in the island.

◆ SubAngularVelocityStep()

void MotionProperties::SubAngularVelocityStep ( Vec3Arg  inAngularVelocityChange)
inline

◆ SubLinearVelocityStep()

void MotionProperties::SubLinearVelocityStep ( Vec3Arg  inLinearVelocityChange)
inline

Friends And Related Symbol Documentation

◆ Body

friend class Body
friend

◆ BodyManager

friend class BodyManager
friend

Member Data Documentation

◆ cInactiveIndex

constexpr uint32 MotionProperties::cInactiveIndex = uint32(-1)
staticconstexpr

Constant indicating that body is not active.


The documentation for this class was generated from the following files: