Jolt Physics
A multi core friendly Game Physics Engine
|
#include <BodyInterface.h>
Public Types | |
using | AddState = void * |
Broadphase add state handle, used to keep track of a batch while adding to the broadphase. More... | |
Public Member Functions | |
void | Init (BodyLockInterface &inBodyLockInterface, BodyManager &inBodyManager, BroadPhase &inBroadPhase) |
Initialize the interface (should only be called by PhysicsSystem) More... | |
Body * | CreateBody (const BodyCreationSettings &inSettings) |
Body * | CreateSoftBody (const SoftBodyCreationSettings &inSettings) |
Body * | CreateBodyWithID (const BodyID &inBodyID, const BodyCreationSettings &inSettings) |
Body * | CreateSoftBodyWithID (const BodyID &inBodyID, const SoftBodyCreationSettings &inSettings) |
Create a soft body with specified ID. See comments at CreateBodyWithID. More... | |
Body * | CreateBodyWithoutID (const BodyCreationSettings &inSettings) const |
Body * | CreateSoftBodyWithoutID (const SoftBodyCreationSettings &inSettings) const |
Advanced use only. Creates a body without specifying an ID. See comments at CreateBodyWithoutID. More... | |
void | DestroyBodyWithoutID (Body *inBody) const |
bool | AssignBodyID (Body *ioBody) |
bool | AssignBodyID (Body *ioBody, const BodyID &inBodyID) |
Body * | UnassignBodyID (const BodyID &inBodyID) |
Advanced use only. See UnassignBodyIDs. Unassigns the ID of a single body. More... | |
void | UnassignBodyIDs (const BodyID *inBodyIDs, int inNumber, Body **outBodies) |
void | DestroyBody (const BodyID &inBodyID) |
Destroy a body. More... | |
void | DestroyBodies (const BodyID *inBodyIDs, int inNumber) |
Destroy multiple bodies. More... | |
void | AddBody (const BodyID &inBodyID, EActivation inActivationMode) |
void | RemoveBody (const BodyID &inBodyID) |
Remove body from the physics system. More... | |
bool | IsAdded (const BodyID &inBodyID) const |
Check if a body has been added to the physics system. More... | |
BodyID | CreateAndAddBody (const BodyCreationSettings &inSettings, EActivation inActivationMode) |
BodyID | CreateAndAddSoftBody (const SoftBodyCreationSettings &inSettings, EActivation inActivationMode) |
TwoBodyConstraint * | CreateConstraint (const TwoBodyConstraintSettings *inSettings, const BodyID &inBodyID1, const BodyID &inBodyID2) |
Create a two body constraint. More... | |
void | ActivateConstraint (const TwoBodyConstraint *inConstraint) |
Activate non-static bodies attached to a constraint. More... | |
void | MoveKinematic (const BodyID &inBodyID, RVec3Arg inTargetPosition, QuatArg inTargetRotation, float inDeltaTime) |
Set velocity of body such that it will be positioned at inTargetPosition/Rotation in inDeltaTime seconds (will activate body if needed) More... | |
void | SetLinearAndAngularVelocity (const BodyID &inBodyID, Vec3Arg inLinearVelocity, Vec3Arg inAngularVelocity) |
void | GetLinearAndAngularVelocity (const BodyID &inBodyID, Vec3 &outLinearVelocity, Vec3 &outAngularVelocity) const |
void | SetLinearVelocity (const BodyID &inBodyID, Vec3Arg inLinearVelocity) |
Vec3 | GetLinearVelocity (const BodyID &inBodyID) const |
void | AddLinearVelocity (const BodyID &inBodyID, Vec3Arg inLinearVelocity) |
Add velocity to current velocity. More... | |
void | AddLinearAndAngularVelocity (const BodyID &inBodyID, Vec3Arg inLinearVelocity, Vec3Arg inAngularVelocity) |
Add linear and angular to current velocities. More... | |
void | SetAngularVelocity (const BodyID &inBodyID, Vec3Arg inAngularVelocity) |
Vec3 | GetAngularVelocity (const BodyID &inBodyID) const |
Vec3 | GetPointVelocity (const BodyID &inBodyID, RVec3Arg inPoint) const |
Velocity of point inPoint (in world space, e.g. on the surface of the body) of the body. More... | |
void | SetPositionRotationAndVelocity (const BodyID &inBodyID, RVec3Arg inPosition, QuatArg inRotation, Vec3Arg inLinearVelocity, Vec3Arg inAngularVelocity) |
Mat44 | GetInverseInertia (const BodyID &inBodyID) const |
Get inverse inertia tensor in world space. More... | |
TransformedShape | GetTransformedShape (const BodyID &inBodyID) const |
Get transform and shape for this body, used to perform collision detection. More... | |
uint64 | GetUserData (const BodyID &inBodyID) const |
Get the user data for a body. More... | |
void | SetUserData (const BodyID &inBodyID, uint64 inUserData) const |
const PhysicsMaterial * | GetMaterial (const BodyID &inBodyID, const SubShapeID &inSubShapeID) const |
Get the material for a particular sub shape. More... | |
void | InvalidateContactCache (const BodyID &inBodyID) |
Set the Body::EFlags::InvalidateContactCache flag for the specified body. This means that the collision cache is invalid for any body pair involving that body until the next physics step. More... | |
Batch adding interface, see Broadphase for further documentation. | |
Note that ioBodies array must be kept constant while the add is in progress. | |
AddState | AddBodiesPrepare (BodyID *ioBodies, int inNumber) |
void | AddBodiesFinalize (BodyID *ioBodies, int inNumber, AddState inAddState, EActivation inActivationMode) |
void | AddBodiesAbort (BodyID *ioBodies, int inNumber, AddState inAddState) |
void | RemoveBodies (BodyID *ioBodies, int inNumber) |
Activate / deactivate a body | |
void | ActivateBody (const BodyID &inBodyID) |
void | ActivateBodies (const BodyID *inBodyIDs, int inNumber) |
void | ActivateBodiesInAABox (const AABox &inBox, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter) |
void | DeactivateBody (const BodyID &inBodyID) |
void | DeactivateBodies (const BodyID *inBodyIDs, int inNumber) |
bool | IsActive (const BodyID &inBodyID) const |
Access to the shape of a body | |
RefConst< Shape > | GetShape (const BodyID &inBodyID) const |
Get the current shape. More... | |
void | SetShape (const BodyID &inBodyID, const Shape *inShape, bool inUpdateMassProperties, EActivation inActivationMode) const |
void | NotifyShapeChanged (const BodyID &inBodyID, Vec3Arg inPreviousCenterOfMass, bool inUpdateMassProperties, EActivation inActivationMode) const |
Object layer of a body | |
void | SetObjectLayer (const BodyID &inBodyID, ObjectLayer inLayer) |
ObjectLayer | GetObjectLayer (const BodyID &inBodyID) const |
Position and rotation of a body | |
void | SetPositionAndRotation (const BodyID &inBodyID, RVec3Arg inPosition, QuatArg inRotation, EActivation inActivationMode) |
void | SetPositionAndRotationWhenChanged (const BodyID &inBodyID, RVec3Arg inPosition, QuatArg inRotation, EActivation inActivationMode) |
Will only update the position/rotation and activate the body when the difference is larger than a very small number. This avoids updating the broadphase/waking up a body when the resulting position/orientation doesn't really change. More... | |
void | GetPositionAndRotation (const BodyID &inBodyID, RVec3 &outPosition, Quat &outRotation) const |
void | SetPosition (const BodyID &inBodyID, RVec3Arg inPosition, EActivation inActivationMode) |
RVec3 | GetPosition (const BodyID &inBodyID) const |
RVec3 | GetCenterOfMassPosition (const BodyID &inBodyID) const |
void | SetRotation (const BodyID &inBodyID, QuatArg inRotation, EActivation inActivationMode) |
Quat | GetRotation (const BodyID &inBodyID) const |
RMat44 | GetWorldTransform (const BodyID &inBodyID) const |
RMat44 | GetCenterOfMassTransform (const BodyID &inBodyID) const |
Add forces to the body | |
void | AddForce (const BodyID &inBodyID, Vec3Arg inForce) |
See Body::AddForce. More... | |
void | AddForce (const BodyID &inBodyID, Vec3Arg inForce, RVec3Arg inPoint) |
Applied at inPoint. More... | |
void | AddTorque (const BodyID &inBodyID, Vec3Arg inTorque) |
See Body::AddTorque. More... | |
void | AddForceAndTorque (const BodyID &inBodyID, Vec3Arg inForce, Vec3Arg inTorque) |
A combination of Body::AddForce and Body::AddTorque. More... | |
Add an impulse to the body | |
void | AddImpulse (const BodyID &inBodyID, Vec3Arg inImpulse) |
Applied at center of mass. More... | |
void | AddImpulse (const BodyID &inBodyID, Vec3Arg inImpulse, RVec3Arg inPoint) |
Applied at inPoint. More... | |
void | AddAngularImpulse (const BodyID &inBodyID, Vec3Arg inAngularImpulse) |
Body type | |
EBodyType | GetBodyType (const BodyID &inBodyID) const |
Body motion type | |
void | SetMotionType (const BodyID &inBodyID, EMotionType inMotionType, EActivation inActivationMode) |
EMotionType | GetMotionType (const BodyID &inBodyID) const |
Body motion quality | |
void | SetMotionQuality (const BodyID &inBodyID, EMotionQuality inMotionQuality) |
EMotionQuality | GetMotionQuality (const BodyID &inBodyID) const |
Restitution | |
void | SetRestitution (const BodyID &inBodyID, float inRestitution) |
float | GetRestitution (const BodyID &inBodyID) const |
Friction | |
void | SetFriction (const BodyID &inBodyID, float inFriction) |
float | GetFriction (const BodyID &inBodyID) const |
Gravity factor | |
void | SetGravityFactor (const BodyID &inBodyID, float inGravityFactor) |
float | GetGravityFactor (const BodyID &inBodyID) const |
Manifold reduction | |
void | SetUseManifoldReduction (const BodyID &inBodyID, bool inUseReduction) |
bool | GetUseManifoldReduction (const BodyID &inBodyID) const |
Public Member Functions inherited from NonCopyable | |
NonCopyable ()=default | |
NonCopyable (const NonCopyable &)=delete | |
void | operator= (const NonCopyable &)=delete |
Class that provides operations on bodies using a body ID. Note that if you need to do multiple operations on a single body, it is more efficient to lock the body once and combine the operations. All quantities are in world space unless otherwise specified.
using BodyInterface::AddState = void * |
Broadphase add state handle, used to keep track of a batch while adding to the broadphase.
void BodyInterface::ActivateBodies | ( | const BodyID * | inBodyIDs, |
int | inNumber | ||
) |
void BodyInterface::ActivateBodiesInAABox | ( | const AABox & | inBox, |
const BroadPhaseLayerFilter & | inBroadPhaseLayerFilter, | ||
const ObjectLayerFilter & | inObjectLayerFilter | ||
) |
void BodyInterface::ActivateBody | ( | const BodyID & | inBodyID | ) |
void BodyInterface::ActivateConstraint | ( | const TwoBodyConstraint * | inConstraint | ) |
Activate non-static bodies attached to a constraint.
void BodyInterface::AddBodiesFinalize | ( | BodyID * | ioBodies, |
int | inNumber, | ||
AddState | inAddState, | ||
EActivation | inActivationMode | ||
) |
BodyInterface::AddState BodyInterface::AddBodiesPrepare | ( | BodyID * | ioBodies, |
int | inNumber | ||
) |
void BodyInterface::AddBody | ( | const BodyID & | inBodyID, |
EActivation | inActivationMode | ||
) |
Add body to the physics system. Note that if you need to add multiple bodies, use the AddBodiesPrepare/AddBodiesFinalize function. Adding many bodies, one at a time, results in a really inefficient broadphase until PhysicsSystem::OptimizeBroadPhase is called or when PhysicsSystem::Update rebuilds the tree! After adding, to get a body by ID use the BodyLockRead or BodyLockWrite interface!
See Body::AddForce.
Applied at inPoint.
void BodyInterface::AddForceAndTorque | ( | const BodyID & | inBodyID, |
Vec3Arg | inForce, | ||
Vec3Arg | inTorque | ||
) |
A combination of Body::AddForce and Body::AddTorque.
Applied at center of mass.
Applied at inPoint.
void BodyInterface::AddLinearAndAngularVelocity | ( | const BodyID & | inBodyID, |
Vec3Arg | inLinearVelocity, | ||
Vec3Arg | inAngularVelocity | ||
) |
Add linear and angular to current velocities.
Add velocity to current velocity.
See Body::AddTorque.
bool BodyInterface::AssignBodyID | ( | Body * | ioBody | ) |
Advanced use only. Assigns the next available body ID to a body that was created using CreateBodyWithoutID. After this call, the body can be added to the physics system.
Advanced use only. Assigns a body ID to a body that was created using CreateBodyWithoutID. After this call, the body can be added to the physics system.
BodyID BodyInterface::CreateAndAddBody | ( | const BodyCreationSettings & | inSettings, |
EActivation | inActivationMode | ||
) |
Combines CreateBody and AddBody
BodyID BodyInterface::CreateAndAddSoftBody | ( | const SoftBodyCreationSettings & | inSettings, |
EActivation | inActivationMode | ||
) |
Combines CreateSoftBody and AddBody
JPH_NAMESPACE_BEGIN Body * BodyInterface::CreateBody | ( | const BodyCreationSettings & | inSettings | ) |
Create a rigid body
Body * BodyInterface::CreateBodyWithID | ( | const BodyID & | inBodyID, |
const BodyCreationSettings & | inSettings | ||
) |
Create a rigid body with specified ID. This function can be used if a simulation is to run in sync between clients or if a simulation needs to be restored exactly. The ID created on the server can be replicated to the client and used to create a deterministic simulation.
Body * BodyInterface::CreateBodyWithoutID | ( | const BodyCreationSettings & | inSettings | ) | const |
Advanced use only. Creates a rigid body without specifying an ID. This body cannot be added to the physics system until it has been assigned a body ID. This can be used to decouple allocation from registering the body. A call to CreateBodyWithoutID followed by AssignBodyID is equivalent to calling CreateBodyWithID.
TwoBodyConstraint * BodyInterface::CreateConstraint | ( | const TwoBodyConstraintSettings * | inSettings, |
const BodyID & | inBodyID1, | ||
const BodyID & | inBodyID2 | ||
) |
Create a two body constraint.
Body * BodyInterface::CreateSoftBody | ( | const SoftBodyCreationSettings & | inSettings | ) |
Create a soft body
Body * BodyInterface::CreateSoftBodyWithID | ( | const BodyID & | inBodyID, |
const SoftBodyCreationSettings & | inSettings | ||
) |
Create a soft body with specified ID. See comments at CreateBodyWithID.
Body * BodyInterface::CreateSoftBodyWithoutID | ( | const SoftBodyCreationSettings & | inSettings | ) | const |
Advanced use only. Creates a body without specifying an ID. See comments at CreateBodyWithoutID.
void BodyInterface::DeactivateBodies | ( | const BodyID * | inBodyIDs, |
int | inNumber | ||
) |
void BodyInterface::DeactivateBody | ( | const BodyID & | inBodyID | ) |
void BodyInterface::DestroyBodies | ( | const BodyID * | inBodyIDs, |
int | inNumber | ||
) |
Destroy multiple bodies.
void BodyInterface::DestroyBody | ( | const BodyID & | inBodyID | ) |
Destroy a body.
void BodyInterface::DestroyBodyWithoutID | ( | Body * | inBody | ) | const |
Advanced use only. Destroy a body previously created with CreateBodyWithoutID that hasn't gotten an ID yet through the AssignBodyID function, or a body that has had its body ID unassigned through UnassignBodyIDs. Bodies that have an ID should be destroyed through DestroyBody.
float BodyInterface::GetFriction | ( | const BodyID & | inBodyID | ) | const |
float BodyInterface::GetGravityFactor | ( | const BodyID & | inBodyID | ) | const |
Get inverse inertia tensor in world space.
void BodyInterface::GetLinearAndAngularVelocity | ( | const BodyID & | inBodyID, |
Vec3 & | outLinearVelocity, | ||
Vec3 & | outAngularVelocity | ||
) | const |
const PhysicsMaterial * BodyInterface::GetMaterial | ( | const BodyID & | inBodyID, |
const SubShapeID & | inSubShapeID | ||
) | const |
Get the material for a particular sub shape.
EMotionQuality BodyInterface::GetMotionQuality | ( | const BodyID & | inBodyID | ) | const |
EMotionType BodyInterface::GetMotionType | ( | const BodyID & | inBodyID | ) | const |
ObjectLayer BodyInterface::GetObjectLayer | ( | const BodyID & | inBodyID | ) | const |
Velocity of point inPoint (in world space, e.g. on the surface of the body) of the body.
void BodyInterface::GetPositionAndRotation | ( | const BodyID & | inBodyID, |
RVec3 & | outPosition, | ||
Quat & | outRotation | ||
) | const |
float BodyInterface::GetRestitution | ( | const BodyID & | inBodyID | ) | const |
TransformedShape BodyInterface::GetTransformedShape | ( | const BodyID & | inBodyID | ) | const |
Get transform and shape for this body, used to perform collision detection.
bool BodyInterface::GetUseManifoldReduction | ( | const BodyID & | inBodyID | ) | const |
|
inline |
Initialize the interface (should only be called by PhysicsSystem)
void BodyInterface::InvalidateContactCache | ( | const BodyID & | inBodyID | ) |
Set the Body::EFlags::InvalidateContactCache flag for the specified body. This means that the collision cache is invalid for any body pair involving that body until the next physics step.
bool BodyInterface::IsActive | ( | const BodyID & | inBodyID | ) | const |
bool BodyInterface::IsAdded | ( | const BodyID & | inBodyID | ) | const |
Check if a body has been added to the physics system.
void BodyInterface::MoveKinematic | ( | const BodyID & | inBodyID, |
RVec3Arg | inTargetPosition, | ||
QuatArg | inTargetRotation, | ||
float | inDeltaTime | ||
) |
Set velocity of body such that it will be positioned at inTargetPosition/Rotation in inDeltaTime seconds (will activate body if needed)
void BodyInterface::NotifyShapeChanged | ( | const BodyID & | inBodyID, |
Vec3Arg | inPreviousCenterOfMass, | ||
bool | inUpdateMassProperties, | ||
EActivation | inActivationMode | ||
) | const |
Notify all systems to indicate that a shape has changed (usable for MutableCompoundShapes)
inBodyID | Body ID of body that had its shape changed |
inPreviousCenterOfMass | Center of mass of the shape before the alterations |
inUpdateMassProperties | When true, the mass and inertia tensor is recalculated |
inActivationMode | Weather or not to activate the body |
void BodyInterface::RemoveBodies | ( | BodyID * | ioBodies, |
int | inNumber | ||
) |
void BodyInterface::RemoveBody | ( | const BodyID & | inBodyID | ) |
Remove body from the physics system.
void BodyInterface::SetFriction | ( | const BodyID & | inBodyID, |
float | inFriction | ||
) |
void BodyInterface::SetGravityFactor | ( | const BodyID & | inBodyID, |
float | inGravityFactor | ||
) |
void BodyInterface::SetLinearAndAngularVelocity | ( | const BodyID & | inBodyID, |
Vec3Arg | inLinearVelocity, | ||
Vec3Arg | inAngularVelocity | ||
) |
Linear or angular velocity (functions will activate body if needed). Note that the linear velocity is the velocity of the center of mass, which may not coincide with the position of your object, to correct for this: \(VelocityCOM = Velocity - AngularVelocity \times ShapeCOM\)
void BodyInterface::SetMotionQuality | ( | const BodyID & | inBodyID, |
EMotionQuality | inMotionQuality | ||
) |
void BodyInterface::SetMotionType | ( | const BodyID & | inBodyID, |
EMotionType | inMotionType, | ||
EActivation | inActivationMode | ||
) |
void BodyInterface::SetObjectLayer | ( | const BodyID & | inBodyID, |
ObjectLayer | inLayer | ||
) |
void BodyInterface::SetPosition | ( | const BodyID & | inBodyID, |
RVec3Arg | inPosition, | ||
EActivation | inActivationMode | ||
) |
void BodyInterface::SetPositionAndRotation | ( | const BodyID & | inBodyID, |
RVec3Arg | inPosition, | ||
QuatArg | inRotation, | ||
EActivation | inActivationMode | ||
) |
void BodyInterface::SetPositionAndRotationWhenChanged | ( | const BodyID & | inBodyID, |
RVec3Arg | inPosition, | ||
QuatArg | inRotation, | ||
EActivation | inActivationMode | ||
) |
Will only update the position/rotation and activate the body when the difference is larger than a very small number. This avoids updating the broadphase/waking up a body when the resulting position/orientation doesn't really change.
void BodyInterface::SetPositionRotationAndVelocity | ( | const BodyID & | inBodyID, |
RVec3Arg | inPosition, | ||
QuatArg | inRotation, | ||
Vec3Arg | inLinearVelocity, | ||
Vec3Arg | inAngularVelocity | ||
) |
Set the complete motion state of a body. Note that the linear velocity is the velocity of the center of mass, which may not coincide with the position of your object, to correct for this: \(VelocityCOM = Velocity - AngularVelocity \times ShapeCOM\)
void BodyInterface::SetRestitution | ( | const BodyID & | inBodyID, |
float | inRestitution | ||
) |
void BodyInterface::SetRotation | ( | const BodyID & | inBodyID, |
QuatArg | inRotation, | ||
EActivation | inActivationMode | ||
) |
void BodyInterface::SetShape | ( | const BodyID & | inBodyID, |
const Shape * | inShape, | ||
bool | inUpdateMassProperties, | ||
EActivation | inActivationMode | ||
) | const |
Set a new shape on the body
inBodyID | Body ID of body that had its shape changed |
inShape | The new shape |
inUpdateMassProperties | When true, the mass and inertia tensor is recalculated |
inActivationMode | Weather or not to activate the body |
void BodyInterface::SetUseManifoldReduction | ( | const BodyID & | inBodyID, |
bool | inUseReduction | ||
) |
Advanced use only. See UnassignBodyIDs. Unassigns the ID of a single body.
Advanced use only. Removes a number of body IDs from their bodies and returns the body pointers. Before calling this, the body should have been removed from the physics system. The body can be destroyed through DestroyBodyWithoutID. This can be used to decouple deallocation. A call to UnassignBodyIDs followed by calls to DestroyBodyWithoutID is equivalent to calling DestroyBodies.
inBodyIDs | A list of body IDs |
inNumber | Number of bodies in the list |
outBodies | If not null on input, this will contain a list of body pointers corresponding to inBodyIDs that can be destroyed afterwards (caller assumes ownership over these). |