java.lang.Object
com.github.stephengold.joltjni.JoltPhysicsObject
com.github.stephengold.joltjni.NonCopyable
com.github.stephengold.joltjni.BodyInterface
- All Implemented Interfaces:
ConstJoltPhysicsObject
,AutoCloseable
,Comparable<JoltPhysicsObject>
An interface to a
PhysicsSystem
that's used to create, add, modify,
query, remove, and delete bodies.-
Method Summary
Modifier and TypeMethodDescriptionvoid
activateBodiesInAaBox
(ConstAaBox box, BroadPhaseLayerFilter bplFilter, ObjectLayerFilter olFilter) Active all bodies within the specified bounds that satisfy the specified filters.void
activateBody
(int bodyId) Activate the specified body.void
activateConstraint
(ConstTwoBodyConstraint constraint) Activate all non-static bodies attached to the specified constraint.void
addAngularImpulse
(int bodyId, Vec3Arg angularImpulse) Apply the specified angular impulse to the specified body.void
addBodiesAbort
(BodyIdArray bodyIds, int numBodies, long addState) Abort adding bodies to the physics system.void
addBodiesFinalize
(BodyIdArray bodyIds, int numBodies, long addState, EActivation activation) Finish adding bodies to the physics system.long
addBodiesPrepare
(BodyIdArray bodyIds, int numBodies) Prepare to add a batch of bodies to the physics system.void
addBody
(int bodyId, EActivation activation) Add the specified body to the physics system.void
addBody
(ConstBody body, EActivation activation) Add the specified body to the physics system.void
Apply the specified force to the specified body's center of mass.void
Apply the specified force to the specified body at the specified location.void
addImpulse
(int bodyId, Vec3Arg impulse) Apply the specified impulse to the specified body's center of mass.void
addImpulse
(int bodyId, Vec3Arg impulse, RVec3Arg location) Apply the specified impulse to the specified body at the specified location.void
Apply the specified torque to the specified body.int
createAndAddBody
(ConstBodyCreationSettings settings, EActivation activationMode) Create a rigid body and add it to the physics system.int
createAndAddSoftBody
(ConstSoftBodyCreationSettings settings, EActivation activationMode) Create a soft body and add it to the physics system.createBody
(ConstBodyCreationSettings settings) Create a rigid body using the specified settings.createConstraint
(TwoBodyConstraintSettings settings, int body1Id, int body2Id) Create a two-body constraint using the specified settings.createSoftBody
(ConstSoftBodyCreationSettings settings) Create a soft body using the specified settings.void
deactivateBody
(int bodyId) Deactivate the specified body.void
destroyBody
(int bodyId) Destroy the specified body.getAngularVelocity
(int bodyId) Return the angular velocity of the specified body.getBodyType
(int bodyId) Return the type of the specified body.getCenterOfMassPosition
(int bodyId) Locate the center of mass of the specified body.getCenterOfMassTransform
(int bodyId) Return the center-of-mass transform of the specified body.float
getFriction
(int bodyId) Return the friction ratio of the specified body.float
getGravityFactor
(int bodyId) Return the gravity factor of the specified body.getLinearVelocity
(int bodyId) Return the linear velocity of the specified body.getMotionQuality
(int bodyId) Return the motion quality.getMotionType
(int bodyId) Return the motion type of the specified body.int
getObjectLayer
(int bodyId) Return the object layer of the specified body.getPosition
(int bodyId) Locate the specified body.void
getPositionAndRotation
(int bodyId, RVec3 storeLocation, Quat storeOrientation) Copy the location and orientation of the specified body.float
getRestitution
(int bodyId) Return the restitution ratio of the specified body.getRotation
(int bodyId) Copy the orientation of the specified body.getShape
(int bodyId) Access the body's shape.Access the underlyingPhysicsSystem
.long
getUserData
(int bodyId) Return the user data of the specified body.boolean
isActive
(int bodyId) Test whether the specified body is active.boolean
isAdded
(int bodyId) Test whether the specified body is added to the system.void
moveKinematic
(int bodyId, RVec3Arg location, QuatArg orientation, float deltaTime) Reposition the specified body, assuming it's kinematic.void
notifyShapeChanged
(int bodyId, Vec3Arg prevCom, boolean updateMassProperties, EActivation activation) Notify all systems that the shape of the specified body has changed.void
removeBody
(int bodyId) Remove the specified body from the physics system, but don't destroy it.void
setAngularVelocity
(int bodyId, Vec3Arg omega) Alter the linear velocity of the specified body.void
setFriction
(int bodyId, float friction) Alter the friction ratio of the specified body.void
setGravityFactor
(int bodyId, float factor) Alter the gravity factor of the specified body.void
setLinearAndAngularVelocity
(int bodyId, Vec3Arg linearVelocity, Vec3Arg angularVelocity) Alter the linear and angular velocities of the specified body.void
setLinearVelocity
(int bodyId, Vec3Arg velocity) Alter the linear velocity of the specified body.void
setMotionQuality
(int bodyId, EMotionQuality quality) Alter the motion quality of the specified body.void
setMotionType
(int bodyId, EMotionType motionType, EActivation activationMode) Alter the motion type of the specified body.void
setObjectLayer
(int bodyId, int layer) Alter the object layer of the specified body.void
setPosition
(int bodyId, RVec3Arg location, EActivation activationMode) Relocate the specified body.void
setPositionAndRotation
(int bodyId, RVec3Arg location, QuatArg orientation, EActivation activationMode) Reposition the specified body.void
setRestitution
(int bodyId, float restitution) Alter the restitution ratio of the specified body.void
setShape
(int bodyId, ConstShape shape, boolean updateMassProperties, EActivation activation) Replace the shape of the specified body.void
setUserData
(int bodyId, long value) Alter the user data of the specified body.Methods inherited from class com.github.stephengold.joltjni.JoltPhysicsObject
close, compareTo, equals, getContainingObject, hasAssignedNativeObject, hashCode, ownsNativeObject, setVirtualAddress, setVirtualAddress, startCleaner, targetVa, toString, va
-
Method Details
-
activateBodiesInAaBox
public void activateBodiesInAaBox(ConstAaBox box, BroadPhaseLayerFilter bplFilter, ObjectLayerFilter olFilter) Active all bodies within the specified bounds that satisfy the specified filters.- Parameters:
box
- the bounds to use (not null, unaffected)bplFilter
- the broadphase layer filter to apply (not null, unaffected)olFilter
- the object-layer filter to apply (not null, unaffected)
-
activateBody
public void activateBody(int bodyId) Activate the specified body.- Parameters:
bodyId
- the ID of the body to activate
-
activateConstraint
Activate all non-static bodies attached to the specified constraint.- Parameters:
constraint
- the constraint to activate (not null)
-
addAngularImpulse
Apply the specified angular impulse to the specified body.- Parameters:
bodyId
- the ID of the bodyangularImpulse
- the impulse vector (not null, unaffected)
-
addBodiesAbort
Abort adding bodies to the physics system.- Parameters:
bodyIds
- the IDs of the bodies to be added (not null, unmodified since the handle was created)numBodies
- the number of bodies to be added (≥0)addState
- the handle returned byaddBodiesPrepare()
-
addBodiesFinalize
public void addBodiesFinalize(BodyIdArray bodyIds, int numBodies, long addState, EActivation activation) Finish adding bodies to the physics system.- Parameters:
bodyIds
- the IDs of the bodies to be added (not null, unmodified since the handle was created)numBodies
- the number of bodies to be added (≥0)addState
- the handle returned byaddBodiesPrepare()
activation
- whether to activate the bodies (not null)
-
addBodiesPrepare
Prepare to add a batch of bodies to the physics system.- Parameters:
bodyIds
- the IDs of the bodies to be added (not null, possibly shuffled)numBodies
- the number of bodies to be added (≥0)- Returns:
- a handle to be passed to
addBodiesFinalize()
oraddBodiesAbort()
-
addBody
Add the specified body to the physics system.To add many bodies at once, use
addBodiesPrepare()
followed byaddBodiesFinalize()
.- Parameters:
body
- the body to add (not null)activation
- whether to activate the body (not null)
-
addBody
Add the specified body to the physics system.- Parameters:
bodyId
- the ID of the body to addactivation
- whether to activate the body (not null)
-
addForce
Apply the specified force to the specified body's center of mass.- Parameters:
bodyId
- the ID of the bodyforce
- the force vector (not null, unaffected)
-
addForce
Apply the specified force to the specified body at the specified location.- Parameters:
bodyId
- the ID of the bodyforce
- the force vector (not null, unaffected)location
- where to apply the force (not null, unaffected)
-
addImpulse
Apply the specified impulse to the specified body's center of mass.- Parameters:
bodyId
- the ID of the bodyimpulse
- the impulse vector (not null, unaffected)
-
addImpulse
Apply the specified impulse to the specified body at the specified location.- Parameters:
bodyId
- the ID of the bodyimpulse
- the impulse vector (not null, unaffected)location
- where to apply the impulse (not null, unaffected)
-
addTorque
Apply the specified torque to the specified body.- Parameters:
bodyId
- the ID of the bodytorque
- the torque vector (not null, unaffected)
-
createAndAddBody
Create a rigid body and add it to the physics system.- Parameters:
settings
- the settings to use (not null, unaffected)activationMode
- whether to activate the body (not null)- Returns:
- the ID of the created body, or an invalid ID when out of bodies
-
createAndAddSoftBody
Create a soft body and add it to the physics system.- Parameters:
settings
- the settings to use (not null, unaffected)activationMode
- whether to activate the body (not null)- Returns:
- the ID of the created body, or an invalid ID when out of bodies
-
createBody
Create a rigid body using the specified settings.- Parameters:
settings
- the settings to use (not null, unaffected)- Returns:
- the new body
-
createConstraint
public TwoBodyConstraint createConstraint(TwoBodyConstraintSettings settings, int body1Id, int body2Id) Create a two-body constraint using the specified settings.- Parameters:
settings
- the settings to use (not null, unaffected)body1Id
- the ID of the first bodybody2Id
- the ID of the 2nd body- Returns:
- the new constraint
-
createSoftBody
Create a soft body using the specified settings.- Parameters:
settings
- the settings to use (not null, unaffected)- Returns:
- the new body
-
deactivateBody
public void deactivateBody(int bodyId) Deactivate the specified body.- Parameters:
bodyId
- the ID of the body to deactivate
-
destroyBody
public void destroyBody(int bodyId) Destroy the specified body. Don't use this on a body that has been added but not removed yet!- Parameters:
bodyId
- the ID of the body to destroy
-
getAngularVelocity
Return the angular velocity of the specified body.- Parameters:
bodyId
- the ID of the body- Returns:
- a new velocity vector (radians per second in system coordinates)
-
getBodyType
Return the type of the specified body.- Parameters:
bodyId
- the ID of the body to query- Returns:
- an enum value (not null)
-
getCenterOfMassPosition
Locate the center of mass of the specified body.- Parameters:
bodyId
- the ID of the body to locate- Returns:
- a new location vector (in system coordinates)
-
getCenterOfMassTransform
Return the center-of-mass transform of the specified body.- Parameters:
bodyId
- the ID of the body to locate- Returns:
- a new transform matrix (relative to system coordinates)
-
getFriction
public float getFriction(int bodyId) Return the friction ratio of the specified body.- Parameters:
bodyId
- the ID of the body- Returns:
- the ratio
-
getGravityFactor
public float getGravityFactor(int bodyId) Return the gravity factor of the specified body.- Parameters:
bodyId
- the ID of the body- Returns:
- the factor
-
getLinearVelocity
Return the linear velocity of the specified body.- Parameters:
bodyId
- the ID of the body- Returns:
- a new velocity vector (meters per second in system coordinates)
-
getMotionQuality
Return the motion quality.- Parameters:
bodyId
- the ID of the body to query- Returns:
- an enum value (not null)
-
getMotionType
Return the motion type of the specified body.- Parameters:
bodyId
- the ID of the body to query- Returns:
- an enum value (not null)
-
getObjectLayer
public int getObjectLayer(int bodyId) Return the object layer of the specified body.- Parameters:
bodyId
- the ID of the body to query- Returns:
- an object-layer index
-
getPosition
Locate the specified body.- Parameters:
bodyId
- the ID of the body to locate- Returns:
- a new location vector (in system coordinates)
-
getPositionAndRotation
Copy the location and orientation of the specified body.- Parameters:
bodyId
- the ID of the body to locatestoreLocation
- storage for the location (not null, modified)storeOrientation
- storage for the orientation (not null, modified)
-
getRestitution
public float getRestitution(int bodyId) Return the restitution ratio of the specified body.- Parameters:
bodyId
- the ID of the body to query- Returns:
- the value (typically ≥0 and ≤1)
-
getRotation
Copy the orientation of the specified body.- Parameters:
bodyId
- the ID of the body- Returns:
- a new rotation quaternion
-
getShape
Access the body's shape. TODO return ConstShape?- Parameters:
bodyId
- the ID of the body- Returns:
- a new reference
-
getSystem
Access the underlyingPhysicsSystem
.- Returns:
- the pre-existing instance
-
getUserData
public long getUserData(int bodyId) Return the user data of the specified body.- Parameters:
bodyId
- the ID of the body- Returns:
- the value
-
isActive
public boolean isActive(int bodyId) Test whether the specified body is active.- Parameters:
bodyId
- the ID of the body to test- Returns:
true
if active, otherwisefalse
-
isAdded
public boolean isAdded(int bodyId) Test whether the specified body is added to the system.- Parameters:
bodyId
- the ID of the body to search for- Returns:
true
if added, otherwisefalse
-
moveKinematic
Reposition the specified body, assuming it's kinematic.- Parameters:
bodyId
- the ID of the body to repositionlocation
- the desired location (in system coordinates, not null, unaffected)orientation
- the desired orientation (relative to the system axes, not null, unaffected)deltaTime
- time until the desired position is reached (in seconds, >0)
-
notifyShapeChanged
public void notifyShapeChanged(int bodyId, Vec3Arg prevCom, boolean updateMassProperties, EActivation activation) Notify all systems that the shape of the specified body has changed.- Parameters:
bodyId
- the ID of the affected bodyprevCom
- center of mass prior to the change (not null, unaffected)updateMassProperties
-true
to recalculate mass and inertiaactivation
- whether to activate the body (not null)
-
removeBody
public void removeBody(int bodyId) Remove the specified body from the physics system, but don't destroy it.- Parameters:
bodyId
- the ID of the body to remove
-
setAngularVelocity
Alter the linear velocity of the specified body.- Parameters:
bodyId
- the ID of the body to modifyomega
- the desired rates (not null, unaffected)
-
setFriction
public void setFriction(int bodyId, float friction) Alter the friction ratio of the specified body.- Parameters:
bodyId
- the ID of the body to modifyfriction
- the desired ratio (typically ≥0 and ≤1, default=0.2)
-
setGravityFactor
public void setGravityFactor(int bodyId, float factor) Alter the gravity factor of the specified body.- Parameters:
bodyId
- the ID of the body to modifyfactor
- the desired factor (default=1)
-
setLinearAndAngularVelocity
public void setLinearAndAngularVelocity(int bodyId, Vec3Arg linearVelocity, Vec3Arg angularVelocity) Alter the linear and angular velocities of the specified body.- Parameters:
bodyId
- the ID of the body to modifylinearVelocity
- the desired linear velocity of body's the center of mass (not null, unaffected)angularVelocity
- the desired angular velocity (not null, unaffected)
-
setLinearVelocity
Alter the linear velocity of the specified body.- Parameters:
bodyId
- the ID of the body to modifyvelocity
- the desired velocity (not null, unaffected)
-
setMotionQuality
Alter the motion quality of the specified body.- Parameters:
bodyId
- the ID of the body to modifyquality
- the desired level of quality (not null)
-
setMotionType
Alter the motion type of the specified body.- Parameters:
bodyId
- the ID of the body to modifymotionType
- the desired motion type (not null)activationMode
- whether to activate the body (not null)
-
setObjectLayer
public void setObjectLayer(int bodyId, int layer) Alter the object layer of the specified body.- Parameters:
bodyId
- the ID of the body to modifylayer
- the index of the desired object layer (≥0, <numObjectLayers, <65536, default=0)
-
setPosition
Relocate the specified body.- Parameters:
bodyId
- the ID of the body to relocatelocation
- the desired location (not null, unaffected)activationMode
- whether to activate the body (not null)
-
setPositionAndRotation
public void setPositionAndRotation(int bodyId, RVec3Arg location, QuatArg orientation, EActivation activationMode) Reposition the specified body.- Parameters:
bodyId
- the ID of the body to modifylocation
- the desired location (not null, unaffected)orientation
- the desired orientation (not null, unaffected)activationMode
- whether to activate the body (not null)
-
setRestitution
public void setRestitution(int bodyId, float restitution) Alter the restitution ratio of the specified body.- Parameters:
bodyId
- the ID of the body to modifyrestitution
- the desired ratio (typically ≥0 and ≤1, default=0)
-
setShape
public void setShape(int bodyId, ConstShape shape, boolean updateMassProperties, EActivation activation) Replace the shape of the specified body.- Parameters:
bodyId
- the ID of the body to reshapeshape
- the desired shape to apply (not null)updateMassProperties
- iftrue
, recalculate the body's mass and inertia, otherwise don't recalculateactivation
- whether to activate the body (not null)
-
setUserData
public void setUserData(int bodyId, long value) Alter the user data of the specified body.- Parameters:
bodyId
- the ID of the body to modifyvalue
- the desired value
-