java.lang.Object
com.github.stephengold.joltjni.JoltPhysicsObject
com.github.stephengold.joltjni.NonCopyable
com.github.stephengold.joltjni.Body
- All Implemented Interfaces:
ConstBody
,ConstJoltPhysicsObject
,AutoCloseable
,Comparable<JoltPhysicsObject>
An object with mass, position, and shape that can be added to a
PhysicsSystem
. Bodies may be dynamic, kinematic, or static.-
Constructor Summary
ConstructorsConstructorDescriptionBody
(long bodyVa) Instantiate a body with the specified native object assigned but not owned. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAngularImpulse
(Vec3Arg impulse) Apply the specified angular impulse to the body.void
Apply the specified force to the body's center of mass.void
Apply the specified force at the specified location.void
addImpulse
(float jx, float jy, float jz) Apply the specified impulse to the body's center of mass.void
addImpulse
(Vec3Arg impulse) Apply the specified impulse to the body's center of mass.void
addImpulse
(Vec3Arg impulse, RVec3Arg location) Apply the specified impulse at the specified location.void
Apply the specified torque to the body.boolean
applyBuoyancyImpulse
(RVec3Arg surfacePosition, Vec3Arg surfaceNormal, float buoyancy, float linearDrag, float angularDrag, Vec3Arg fluidVelocity, Vec3Arg gravity, float deltaTime) Apply an impulse that simulates buoyancy and drag.boolean
Test whether the body could be made kinematic or dynamic.Copy the net force acting on the body.Copy the net torque acting on the body.boolean
Test whether the body is allowed to fall asleep.Copy the body's angular velocity.Convert the body to aBodyCreationSettings
object.Return the body type (rigid or soft).int
Return the broadphase layer.Copy the location of the body's center of mass (which might not coincide with its origin).void
getCenterOfMassPosition
(RVec3 storeLocation) Copy the location of the body's center of mass (which might not coincide with its origin).Copy the coordinate transform of the body's center of mass.Access the body's collision group.boolean
Test whether extra effort should be made to remove ghost contacts.float
Return the body's friction ratio.int
getId()
Return the body's ID for use withBodyInterface
.Copy the inverse coordinate transform of the body's center of mass.Copy the body's linear velocity.Access the body's motion properties.Return the body's motion type.int
Return the body's object layer.Copy the location of the body's origin (which might not coincide with its center of mass).void
getPositionAndRotation
(RVec3 storeLocation, Quat storeOrientation) Copy the position of the body.float
Return the body's restitution ratio.Copy the body's orientation.getShape()
Access the body's shape.Convert the body to aSoftBodyCreationSettings
object.Convert the body to aTransformedShape
object.long
Return the body's user data: can be used for anything.Access the body's bounding box.getWorldSpaceSurfaceNormal
(int subShapeId, RVec3Arg location) Copy the surface normal of a particular sub shape at the specified location.Copy the world transform.boolean
isActive()
Test whether the body is deactivated.boolean
Test whether the body is dynamic.boolean
Test whether the body has been added to itsPhysicsSystem
.boolean
Test whether the body is kinematic.boolean
Test whether the body is a rigid body.boolean
isSensor()
Test whether the body is a sensor.boolean
Test whether the body is soft.boolean
isStatic()
Test whether the body is static (non-moving).void
moveKinematic
(RVec3Arg location, QuatArg orientation, float deltaTime) Reposition the body, assuming it's kinematic.void
Reset the body's sleep timer.void
setAllowSleeping
(boolean allow) Alter whether the body is allowed to fall asleep.void
setAngularVelocity
(Vec3Arg omega) Directly alter the body's angular velocity.void
setAngularVelocityClamped
(Vec3Arg omega) Alter the body's angular velocity within limits.void
Assign the body to the specified collision group.void
setEnhancedInternalEdgeRemoval
(boolean enhance) Alter whether extra effort should be made to remove ghost contacts.void
setFriction
(float friction) Alter the body's friction ratio.void
setIsSensor
(boolean setting) Alter whether the body is a sensor.void
setLinearVelocity
(Vec3Arg velocity) Directly alter the body's linear velocity.void
setLinearVelocityClamped
(Vec3Arg velocity) Alter the body's linear velocity within limits.void
setMotionType
(EMotionType motionType) Alter the body's motion type.void
setPositionAndRotationInternal
(RVec3Arg location, QuatArg orientation) Reposition the body and reset its sleep timer.void
setPositionAndRotationInternal
(RVec3Arg location, QuatArg orientation, boolean resetSleepTimer) Reposition the body.void
setRestitution
(float restitution) Alter the body's restitution ratio.void
setUserData
(long value) Alter the body's user data.static Body
Create a dummy body that can be used to attach a constraint to the world.Methods inherited from class com.github.stephengold.joltjni.JoltPhysicsObject
close, compareTo, equals, getContainingObject, hasAssignedNativeObject, hashCode, ownsNativeObject, setVirtualAddress, setVirtualAddress, startCleaner, targetVa, toString, va
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Comparable
compareTo
Methods inherited from interface com.github.stephengold.joltjni.readonly.ConstJoltPhysicsObject
close, hasAssignedNativeObject, ownsNativeObject, targetVa
-
Constructor Details
-
Body
public Body(long bodyVa) Instantiate a body with the specified native object assigned but not owned.For use in custom contact listeners.
- Parameters:
bodyVa
- the virtual address of the native object to assign (not zero)
-
-
Method Details
-
addAngularImpulse
Apply the specified angular impulse to the body.- Parameters:
impulse
- the impulse vector (Newton.meter.seconds in system coordinates, not null, unaffected)
-
addForce
Apply the specified force to the body's center of mass.- Parameters:
force
- the force vector (Newtons in system coordinates, not null, unaffected)
-
addForce
Apply the specified force at the specified location.- Parameters:
force
- the force vector (not null, unaffected)location
- where to apply the force (Newtons in system coordinates not null, unaffected)
-
addImpulse
public void addImpulse(float jx, float jy, float jz) Apply the specified impulse to the body's center of mass.- Parameters:
jx
- the X component of the impulse (kilogram.meters per second in system coordinates)jy
- the Y component of the impulse (kilogram.meters per second in system coordinates)jz
- the Z component of the impulse (kilogram.meters per second in system coordinates)
-
addImpulse
Apply the specified impulse to the body's center of mass.- Parameters:
impulse
- the impulse vector (kilogram.meters per second in system coordinates, not null, unaffected)
-
addImpulse
Apply the specified impulse at the specified location.- Parameters:
impulse
- the impulse vector (kilogram.meters per second in system coordinates, not null, unaffected)location
- where to apply the impulse (not null, unaffected)
-
addTorque
Apply the specified torque to the body.- Parameters:
torque
- the torque vector (Newton.meters in system coordinates, not null, unaffected)
-
applyBuoyancyImpulse
public boolean applyBuoyancyImpulse(RVec3Arg surfacePosition, Vec3Arg surfaceNormal, float buoyancy, float linearDrag, float angularDrag, Vec3Arg fluidVelocity, Vec3Arg gravity, float deltaTime) Apply an impulse that simulates buoyancy and drag.- Parameters:
surfacePosition
- the location of the fluid's surface (in system coordinates, not null, unaffected)surfaceNormal
- the upward normal direction of the fluid's surface (in system coordinates, not null, unaffected)buoyancy
- the mass of the displaced fluid divided by the body's mass (1→neutral buoyancy)linearDrag
- the drag factor for linear motionangularDrag
- the drag factor for angular motionfluidVelocity
- the velocity of the fluid (meters per second in system coordinates, not null, unaffected)gravity
- the gravity vector (in system coordinates, not null, unaffected)deltaTime
- the duration of the simulation step (in seconds)- Returns:
true
if an impulse was applied,false
if not in the fluid
-
moveKinematic
Reposition the body, assuming it's kinematic.- Parameters:
location
- 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)
-
resetSleepTimer
public void resetSleepTimer()Reset the body's sleep timer. This does not activate the body, but allows resetting the system that detects sleeping bodies. -
setAllowSleeping
public void setAllowSleeping(boolean allow) Alter whether the body is allowed to fall asleep.- Parameters:
allow
-true
to allow,false
to inhibit
-
setAngularVelocity
Directly alter the body's angular velocity.- Parameters:
omega
- the desired angular velocity (not null, unaffected, default=(0,0,0))
-
setAngularVelocityClamped
Alter the body's angular velocity within limits.- Parameters:
omega
- the desired angular velocity (not null, unaffected, default=(0,0,0))
-
setCollisionGroup
Assign the body to the specified collision group.- Parameters:
group
- the group to assign (not null, unaffected)
-
setEnhancedInternalEdgeRemoval
public void setEnhancedInternalEdgeRemoval(boolean enhance) Alter whether extra effort should be made to remove ghost contacts.- Parameters:
enhance
-true
for extra effort,false
for ordinary effort (default=false)
-
setFriction
public void setFriction(float friction) Alter the body's friction ratio.- Parameters:
friction
- the desired ratio (typically ≥0 and ≤1, default=0.2)
-
setIsSensor
public void setIsSensor(boolean setting) Alter whether the body is a sensor.- Parameters:
setting
-true
to make it a sensor,false
for a regular body (default=false)
-
setLinearVelocity
Directly alter the body's linear velocity.- Parameters:
velocity
- the desired linear velocity (in meters per second, not null, unaffected, default=(0,0,0))
-
setLinearVelocityClamped
Alter the body's linear velocity within limits.- Parameters:
velocity
- the desired linear velocity (in meters per second, not null, unaffected, default=(0,0,0))
-
setMotionType
Alter the body's motion type.- Parameters:
motionType
- the desired value (not null)
-
setPositionAndRotationInternal
Reposition the body and reset its sleep timer.- Parameters:
location
- the desired location (in system coordinates, not null, unaffected)orientation
- the desired orientation (relative to the system axes, not null, unaffected)
-
setPositionAndRotationInternal
public void setPositionAndRotationInternal(RVec3Arg location, QuatArg orientation, boolean resetSleepTimer) Reposition the body.- Parameters:
location
- the desired location (in system coordinates, not null, unaffected)orientation
- the desired orientation (relative to the system axes, not null, unaffected)resetSleepTimer
-true
to reset the body's sleep timer,false
to leave the timer unchanged
-
setRestitution
public void setRestitution(float restitution) Alter the body's restitution ratio.- Parameters:
restitution
- the desired ratio (typically ≥0 and ≤1, default=0)
-
setUserData
public void setUserData(long value) Alter the body's user data.- Parameters:
value
- the desired value (default=0)
-
sFixedToWorld
Create a dummy body that can be used to attach a constraint to the world.- Returns:
- a new JVM object with the pre-existing native object assigned
-
canBeKinematicOrDynamic
public boolean canBeKinematicOrDynamic()Test whether the body could be made kinematic or dynamic. The body is unaffected.- Specified by:
canBeKinematicOrDynamic
in interfaceConstBody
- Returns:
true
if possible, otherwisefalse
-
getAccumulatedForce
Copy the net force acting on the body. The body is unaffected.- Specified by:
getAccumulatedForce
in interfaceConstBody
- Returns:
- a new force vector (Newtons in system coordinates)
-
getAccumulatedTorque
Copy the net torque acting on the body. The body is unaffected.- Specified by:
getAccumulatedTorque
in interfaceConstBody
- Returns:
- a new torque vector (Newton.meters in system coordinates)
-
getAllowSleeping
public boolean getAllowSleeping()Test whether the body is allowed to fall asleep. The body is unaffected.- Specified by:
getAllowSleeping
in interfaceConstBody
- Returns:
true
if allowed, otherwisefalse
-
getAngularVelocity
Copy the body's angular velocity. The body is unaffected.- Specified by:
getAngularVelocity
in interfaceConstBody
- Returns:
- a new velocity vector (radians per second in system coordinates)
-
getBodyCreationSettings
Convert the body to aBodyCreationSettings
object. The body is unaffected.- Specified by:
getBodyCreationSettings
in interfaceConstBody
- Returns:
- a new object
-
getBodyType
Return the body type (rigid or soft). The body is unaffected.- Specified by:
getBodyType
in interfaceConstBody
- Returns:
- an enum value (not null)
-
getBroadPhaseLayer
public int getBroadPhaseLayer()Return the broadphase layer. The body is unaffected.- Specified by:
getBroadPhaseLayer
in interfaceConstBody
- Returns:
- the layer ID
-
getCenterOfMassPosition
Copy the location of the body's center of mass (which might not coincide with its origin). The body is unaffected.- Specified by:
getCenterOfMassPosition
in interfaceConstBody
- Returns:
- a new location vector (in system coordinates, all components finite)
-
getCenterOfMassPosition
Copy the location of the body's center of mass (which might not coincide with its origin). The body is unaffected.- Specified by:
getCenterOfMassPosition
in interfaceConstBody
- Parameters:
storeLocation
- storage for the location (in system coordinates, not null, modified)
-
getCenterOfMassTransform
Copy the coordinate transform of the body's center of mass. The body is unaffected.- Specified by:
getCenterOfMassTransform
in interfaceConstBody
- Returns:
- a new transform matrix (relative to system coordinates)
-
getCollisionGroup
Access the body's collision group.- Specified by:
getCollisionGroup
in interfaceConstBody
- Returns:
- a new JVM object with the pre-existing native object assigned
-
getEnhancedInternalEdgeRemoval
public boolean getEnhancedInternalEdgeRemoval()Test whether extra effort should be made to remove ghost contacts. The body is unaffected.- Specified by:
getEnhancedInternalEdgeRemoval
in interfaceConstBody
- Returns:
true
for extra effort, otherwisefalse
-
getFriction
public float getFriction()Return the body's friction ratio. The body is unaffected.- Specified by:
getFriction
in interfaceConstBody
- Returns:
- the ratio
-
getId
public int getId()Return the body's ID for use withBodyInterface
. The body is unaffected. (native method: GetID) -
getInverseCenterOfMassTransform
Copy the inverse coordinate transform of the body's center of mass. The body is unaffected.- Specified by:
getInverseCenterOfMassTransform
in interfaceConstBody
- Returns:
- a new transform matrix (relative to local coordinates)
-
getLinearVelocity
Copy the body's linear velocity. The body is unaffected.- Specified by:
getLinearVelocity
in interfaceConstBody
- Returns:
- a new velocity vector (meters per second in system coordinates)
-
getMotionProperties
Access the body's motion properties.- Specified by:
getMotionProperties
in interfaceConstBody
- Returns:
- a new JVM object with the pre-existing native object assigned, or
null
if none
-
getMotionType
Return the body's motion type. The body is unaffected.- Specified by:
getMotionType
in interfaceConstBody
- Returns:
- an enum value (not null)
-
getObjectLayer
public int getObjectLayer()Return the body's object layer. The body is unaffected.- Specified by:
getObjectLayer
in interfaceConstBody
- Returns:
- a layer index (≥0)
-
getPosition
Copy the location of the body's origin (which might not coincide with its center of mass). The body is unaffected.- Specified by:
getPosition
in interfaceConstBody
- Returns:
- a new location vector (in system coordinates, all components finite)
-
getPositionAndRotation
Copy the position of the body. The body is unaffected.- Specified by:
getPositionAndRotation
in interfaceConstBody
- Parameters:
storeLocation
- storage for the location (in system coordinates, not null, modified)storeOrientation
- storage for the orientation (in system coordinates, not null, modified)
-
getRestitution
public float getRestitution()Return the body's restitution ratio. The body is unaffected.- Specified by:
getRestitution
in interfaceConstBody
- Returns:
- the value (typically ≥0 and ≤1)
-
getRotation
Copy the body's orientation. The body is unaffected.- Specified by:
getRotation
in interfaceConstBody
- Returns:
- a new rotation quaternion (relative to the system axes)
-
getShape
Access the body's shape. -
getSoftBodyCreationSettings
Convert the body to aSoftBodyCreationSettings
object. The body is unaffected.- Specified by:
getSoftBodyCreationSettings
in interfaceConstBody
- Returns:
- a new object
-
getTransformedShape
Convert the body to aTransformedShape
object. The body is unaffected.- Specified by:
getTransformedShape
in interfaceConstBody
- Returns:
- a new object
-
getUserData
public long getUserData()Return the body's user data: can be used for anything. The body is unaffected.- Specified by:
getUserData
in interfaceConstBody
- Returns:
- the value
-
getWorldSpaceBounds
Access the body's bounding box. The body is unaffected.- Specified by:
getWorldSpaceBounds
in interfaceConstBody
- Returns:
- a new immutable JVM object with the pre-existing native object assigned
-
getWorldSpaceSurfaceNormal
Copy the surface normal of a particular sub shape at the specified location.- Specified by:
getWorldSpaceSurfaceNormal
in interfaceConstBody
- Parameters:
subShapeId
- the ID of the sub-shape to uselocation
- the location to use (not null, unaffected)- Returns:
- a new direction vector
-
getWorldTransform
Copy the world transform. The body is unaffected.- Specified by:
getWorldTransform
in interfaceConstBody
- Returns:
- a new matrix relative to system coordinates
-
isActive
public boolean isActive()Test whether the body is deactivated. The body is unaffected. -
isDynamic
public boolean isDynamic()Test whether the body is dynamic. The body is unaffected. -
isInBroadPhase
public boolean isInBroadPhase()Test whether the body has been added to itsPhysicsSystem
. The body is unaffected.- Specified by:
isInBroadPhase
in interfaceConstBody
- Returns:
true
if added, otherwisefalse
-
isKinematic
public boolean isKinematic()Test whether the body is kinematic. It is unaffected.- Specified by:
isKinematic
in interfaceConstBody
- Returns:
true
if kinematic, otherwisefalse
-
isRigidBody
public boolean isRigidBody()Test whether the body is a rigid body. It is unaffected.- Specified by:
isRigidBody
in interfaceConstBody
- Returns:
true
if rigid body, otherwisefalse
-
isSensor
public boolean isSensor()Test whether the body is a sensor. It is unaffected. -
isSoftBody
public boolean isSoftBody()Test whether the body is soft. It is unaffected.- Specified by:
isSoftBody
in interfaceConstBody
- Returns:
true
if soft, otherwisefalse
-
isStatic
public boolean isStatic()Test whether the body is static (non-moving). It is unaffected.
-