Package com.github.stephengold.joltjni
Class BodyInterface
java.lang.Object
com.github.stephengold.joltjni.JoltPhysicsObject
com.github.stephengold.joltjni.NonCopyable
com.github.stephengold.joltjni.BodyInterface
- All Implemented Interfaces:
ConstJoltPhysicsObject,AutoCloseable,Comparable<ConstJoltPhysicsObject>
An interface to a
PhysicsSystem that's used to create, add, modify,
query, remove, and delete bodies.-
Method Summary
Modifier and TypeMethodDescriptionvoidactivateBody(ConstBodyId bodyId) Activate the specified body.voidaddBody(ConstBodyId bodyId, EActivation activation) Add the specified body to the physics system.voidaddForce(ConstBodyId bodyId, Vec3Arg force) Apply the specified force to the specified body's center of mass.voidaddForce(ConstBodyId bodyId, Vec3Arg force, RVec3Arg location) Apply the specified force to the specified body at the specified location.voidaddImpulse(ConstBodyId bodyId, Vec3Arg impulse) Apply the specified impulse to the specified body's center of mass.voidaddImpulse(ConstBodyId bodyId, Vec3Arg impulse, RVec3Arg location) Apply the specified impulse to the specified body at the specified location.voidaddTorque(ConstBodyId bodyId, Vec3Arg torque) Apply the specified torque to the specified body.createAndAddBody(BodyCreationSettings settings, EActivation activationMode) Create a body and add it to the physics system.createBody(ConstBodyCreationSettings settings) Create a body using the specified settings.createConstraint(TwoBodyConstraintSettings settings, ConstBodyId body1Id, ConstBodyId body2Id) Create a two-body constraint using the specified settings.voiddeactivateBody(ConstBodyId bodyId) Deactivate the specified body.voiddestroyBody(ConstBodyId bodyId) Destroy the specified body.getAngularVelocity(ConstBodyId bodyId) Return the angular velocity of the specified body.getBodyType(ConstBodyId bodyId) Return the type of the specified body.getCenterOfMassPosition(ConstBodyId bodyId) Locate the center of mass of the specified body.floatgetFriction(ConstBodyId bodyId) Return the friction ratio of the specified body.floatgetGravityFactor(ConstBodyId bodyId) Return the gravity factor of the specified body.getLinearVelocity(ConstBodyId bodyId) Return the linear velocity of the specified body.getMotionType(ConstBodyId bodyId) Return the motion type of the specified body.getPosition(ConstBodyId bodyId) Locate the specified body.voidgetPositionAndRotation(ConstBodyId bodyId, RVec3 storeLocation, Quat storeOrientation) Copy the location and orientation of the specified body.floatgetRestitution(ConstBodyId bodyId) Return the restitution ratio of the specified body.getRotation(ConstBodyId bodyId) Return the orientation of the specified body.getShape(ConstBodyId bodyId) Access the body's shape.Access the underlyingPhysicsSystem.booleanisActive(ConstBodyId bodyId) Test whether the specified body is active.booleanisAdded(ConstBodyId bodyId) Test whether the specified body is added to the system.voidmoveKinematic(ConstBodyId bodyId, RVec3Arg location, QuatArg orientation, float deltaTime) Reposition the specified body, assuming it's kinematic.voidnotifyShapeChanged(ConstBodyId bodyId, Vec3Arg prevCom, boolean updateMassProperties, EActivation activation) Notify all systems that the shape of the specified body has changed.voidremoveBody(ConstBodyId bodyId) Remove the specified body from the physics system.voidsetAngularVelocity(ConstBodyId bodyId, Vec3Arg omega) Alter the linear velocity of the specified body.voidsetFriction(ConstBodyId bodyId, float friction) Alter the friction ratio of the specified body.voidsetGravityFactor(ConstBodyId bodyId, float factor) Alter the gravity factor of the specified body.voidsetLinearAndAngularVelocity(ConstBodyId bodyId, Vec3Arg linearVelocity, Vec3Arg angularVelocity) Alter the linear and angular velocities of the specified body.voidsetLinearVelocity(ConstBodyId bodyId, Vec3Arg velocity) Alter the linear velocity of the specified body.voidsetPositionAndRotation(ConstBodyId bodyId, RVec3Arg location, QuatArg orientation, EActivation activationMode) Alter the location and orientation of the specified body.voidsetRestitution(ConstBodyId bodyId, float restitution) Alter the restitution ratio of the specified body.Methods inherited from class com.github.stephengold.joltjni.JoltPhysicsObject
close, compareTo, equals, hasAssignedNativeObject, hashCode, ownsNativeObject, setVirtualAddress, startCleaner, toString, va
-
Method Details
-
activateBody
Activate the specified body.- Parameters:
bodyId- the ID of the body to activate (not null, unaffected)
-
addBody
Add the specified body to the physics system.- Parameters:
bodyId- the ID of the body to add (not null, unaffected)activation- 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 body (not null, unaffected)force- 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 body (not null, unaffected)force- 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 body (not null, unaffected)impulse- 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 body (not null, unaffected)impulse- 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 body (not null, unaffected)torque- the torque vector (not null, unaffected)
-
createAndAddBody
Create a 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 body using the specified settings.- Parameters:
settings- the settings to use (not null, unaffected)- Returns:
- the new body
-
createConstraint
public TwoBodyConstraint createConstraint(TwoBodyConstraintSettings settings, ConstBodyId body1Id, ConstBodyId 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 body (not null, unaffected)body2Id- the ID of the 2nd body (not null, unaffected)- Returns:
- the new constraint
-
deactivateBody
Deactivate the specified body.- Parameters:
bodyId- the ID of the body to deactivate (not null, unaffected)
-
destroyBody
Destroy the specified body.- Parameters:
bodyId- the ID of the body to destroy (not null)
-
getAngularVelocity
Return the angular velocity of the specified body.- Parameters:
bodyId- the ID of the body (not null)- Returns:
- a new velocity vector (radians per second in physics-system coordinates)
-
getBodyType
Return the type of the specified body.- Parameters:
bodyId- the ID of the body to query (not null)- 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 (not null)- Returns:
- a new location vector (in physics-system coordinates)
-
getFriction
Return the friction ratio of the specified body.- Parameters:
bodyId- the ID of the body (not null)- Returns:
- the ratio
-
getGravityFactor
Return the gravity factor of the specified body.- Parameters:
bodyId- the ID of the body (not null)- Returns:
- the factor
-
getLinearVelocity
Return the linear velocity of the specified body.- Parameters:
bodyId- the ID of the body (not null)- Returns:
- a new velocity vector (meters per second in physics-system coordinates)
-
getMotionType
Return the motion type of the specified body.- Parameters:
bodyId- the ID of the body to query (not null, unaffected)- Returns:
- an enum value (not null)
-
getPosition
Locate the specified body.- Parameters:
bodyId- the ID of the body to locate (not null, unaffected)- Returns:
- a new location vector (in physics-system coordinates)
-
getPositionAndRotation
Copy the location and orientation of the specified body.- Parameters:
bodyId- the ID of the body to locate (not null, unaffected)storeLocation- storage for the location (not null, modified)storeOrientation- storage for the orientation (not null, modified)
-
getRestitution
Return the restitution ratio of the specified body.- Parameters:
bodyId- the ID of the body to query (not null)- Returns:
- the value (typically ≥0 and ≤1)
-
getRotation
Return the orientation of the specified body.- Parameters:
bodyId- the ID of the body (not null, unaffected)- Returns:
- a new rotation quaternion
-
getShape
Access the body's shape.- Parameters:
bodyId- the ID of the body (not null, unaffected)- Returns:
- a new reference
-
getSystem
Access the underlyingPhysicsSystem.- Returns:
- the pre-existing instance
-
isActive
Test whether the specified body is active.- Parameters:
bodyId- the ID of the body to test (not null, unaffected)- Returns:
- true if active, otherwise false
-
isAdded
Test whether the specified body is added to the system.- Parameters:
bodyId- the ID of the body to test (not null, unaffected)- Returns:
- true if added, otherwise false
-
moveKinematic
public void moveKinematic(ConstBodyId bodyId, RVec3Arg location, QuatArg orientation, float deltaTime) Reposition the specified body, assuming it's kinematic.- Parameters:
bodyId- the ID of the body to reposition (not null, unaffected)location- the desired location (in physics-system coordinates, not null, unaffected)orientation- the desired orientation (relative to the physics-system axes, not null, unaffected)deltaTime- time until the desired position is reached (in seconds, >0)
-
notifyShapeChanged
public void notifyShapeChanged(ConstBodyId 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 body (not null, unaffected)prevCom- 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
Remove the specified body from the physics system.- Parameters:
bodyId- the ID of the body to remove (not null, unaffected)
-
setAngularVelocity
Alter the linear velocity of the specified body.- Parameters:
bodyId- the ID of the body to modify (not null, unaffected)omega- the desired rates (not null, unaffected)
-
setFriction
Alter the friction ratio of the specified body.- Parameters:
bodyId- the ID of the body to modify (not null, unaffected)friction- the desired ratio (typically ≥0 and ≤1, default=0.2)
-
setGravityFactor
Alter the gravity factor of the specified body.- Parameters:
bodyId- the ID of the body to modify (not null, unaffected)factor- the desired factor (default=1)
-
setLinearAndAngularVelocity
public void setLinearAndAngularVelocity(ConstBodyId bodyId, Vec3Arg linearVelocity, Vec3Arg angularVelocity) Alter the linear and angular velocities of the specified body.- Parameters:
bodyId- the ID of the body to modify (not null, unaffected)linearVelocity- 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 modify (not null, unaffected)velocity- the desired velocity (not null, unaffected)
-
setPositionAndRotation
public void setPositionAndRotation(ConstBodyId bodyId, RVec3Arg location, QuatArg orientation, EActivation activationMode) Alter the location and orientation of the specified body.- Parameters:
bodyId- the ID of the body to modify (not null, unaffected)location- the desired location (not null, unaffected)orientation- the desired orientation (not null, unaffected)activationMode- whether to activate the body (not null)
-
setRestitution
Alter the restitution ratio of the specified body.- Parameters:
bodyId- the ID of the body to modify (not null, unaffected)restitution- the desired ratio (typically ≥0 and ≤1, default=0)
-