Package com.github.stephengold.joltjni
Class Body
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<ConstJoltPhysicsObject>
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 TypeMethodDescriptionvoidaddAngularImpulse(Vec3Arg impulse) Apply the specified angular impulse to the body.voidApply the specified force to the body's center of mass.voidApply the specified force at the specified location.voidaddImpulse(Vec3Arg impulse) Apply the specified impulse to the body's center of mass.voidaddImpulse(Vec3Arg impulse, RVec3Arg location) Apply the specified impulse at the specified location.voidApply the specified torque to the body.booleanTest whether the body could be made kinematic or dynamic.Return the net force acting on the body.Return the net torque acting on the body.booleanTest whether the body is allowed to fall asleep.Return the body's angular velocity.Convert the body to aBodyCreationSettingsobject.Return the location of the body's center of mass (which might not coincide with its origin).Access the body's collision group.floatReturn the body's friction ratio.getId()Copy the body's ID for use withBodyInterface.Return the body's linear velocity.Access the body's motion properties.Return the body's motion type.intReturn the body's object layer.Return the location of the body's origin (which might not coincide with its center of mass).floatReturn the body's restitution ratio.Return the body's orientation.getShape()Access the body's shape.longReturn the body's user data: can be used for anything.Access the body's bounding box.booleanisActive()Test whether the body is deactivated.booleanTest whether the body is dynamic.booleanTest whether the body has been added to itsPhysicsSystem.booleanTest whether the body is kinematic.booleanTest whether the body is a rigid body.booleanisSensor()Test whether the body is a sensor.booleanisStatic()Test whether the body is static (non-moving).voidmoveKinematic(RVec3Arg location, QuatArg orientation, float deltaTime) Reposition the body, assuming it's kinematic.voidReset the body's sleep timer.voidsetAllowSleeping(boolean allow) Alter whether the body is allowed to fall asleep.voidsetAngularVelocity(Vec3Arg omega) Directly alter the body's angular velocity.voidsetAngularVelocityClamped(Vec3Arg omega) Alter the body's angular velocity within limits.voidsetCollisionGroup(CollisionGroup group) Assign the body to the specified collision group.voidsetFriction(float friction) Alter the body's friction ratio.voidsetIsSensor(boolean setting) Alter whether the body is a sensor.voidsetLinearVelocity(Vec3Arg velocity) Directly alter the body's linear velocity.voidsetLinearVelocityClamped(Vec3Arg velocity) Alter the body's linear velocity within limits.voidsetMotionType(EMotionType motionType) Alter the body's motion type.voidsetPositionAndRotationInternal(RVec3Arg location, QuatArg orientation) Re-position the body and reset its sleep timer.voidsetPositionAndRotationInternal(RVec3Arg location, QuatArg orientation, boolean resetSleepTimer) Re-position the body.voidsetRestitution(float restitution) Alter the body's restitution ratio.voidsetUserData(long value) Alter the body's user data.static ConstBodyCreate 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, hasAssignedNativeObject, hashCode, ownsNativeObject, setVirtualAddress, startCleaner, toString, vaMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Comparable
compareToMethods inherited from interface com.github.stephengold.joltjni.readonly.ConstJoltPhysicsObject
close, hasAssignedNativeObject, ownsNativeObject, va
-
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
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)
-
getCollisionGroup
Access the body's collision group.- Returns:
- the pre-existing group, or
nullif none
-
getMotionProperties
Access the body's motion properties.- Returns:
- a new JVM object with the pre-existing native object assigned, or
nullif none
-
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, alias created)
-
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/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/second, not null, unaffected, default=(0,0,0))
-
setMotionType
Alter the body's motion type.- Parameters:
motionType- the desired value (not null)
-
setPositionAndRotationInternal
Re-position 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) Re-position 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:
canBeKinematicOrDynamicin interfaceConstBody- Returns:
- true if possible, otherwise false
-
getAccumulatedForce
Return the net force acting on the body. The body is unaffected.- Specified by:
getAccumulatedForcein interfaceConstBody- Returns:
- a new force vector (Newtons in system coordinates)
-
getAccumulatedTorque
Return the net torque acting on the body. The body is unaffected.- Specified by:
getAccumulatedTorquein 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:
getAllowSleepingin interfaceConstBody- Returns:
- true if allowed, otherwise false
-
getAngularVelocity
Return the body's angular velocity. The body is unaffected.- Specified by:
getAngularVelocityin interfaceConstBody- Returns:
- a new velocity vector (radians per second in system coordinates)
-
getBodyCreationSettings
Convert the body to aBodyCreationSettingsobject.- Specified by:
getBodyCreationSettingsin interfaceConstBody- Returns:
- a new object
-
getCenterOfMassPosition
Return the location of the body's center of mass (which might not coincide with its origin). The body is unaffected.- Specified by:
getCenterOfMassPositionin interfaceConstBody- Returns:
- a new location vector (in system coordinates, all components finite)
-
getFriction
public float getFriction()Return the body's friction ratio. The body is unaffected.- Specified by:
getFrictionin interfaceConstBody- Returns:
- the ratio
-
getId
Copy the body's ID for use withBodyInterface. The body is unaffected. -
getLinearVelocity
Return the body's linear velocity. The body is unaffected.- Specified by:
getLinearVelocityin interfaceConstBody- Returns:
- a new velocity vector (meters per second in system coordinates)
-
getMotionType
Return the body's motion type. The body is unaffected.- Specified by:
getMotionTypein interfaceConstBody- Returns:
- an enum value (not null)
-
getObjectLayer
public int getObjectLayer()Return the body's object layer. The body is unaffected.- Specified by:
getObjectLayerin interfaceConstBody- Returns:
- a layer index (≥0)
-
getPosition
Return the location of the body's origin (which might not coincide with its center of mass). The body is unaffected.- Specified by:
getPositionin interfaceConstBody- Returns:
- a new location vector (in system coordinates, all components finite)
-
getRestitution
public float getRestitution()Return the body's restitution ratio. The body is unaffected.- Specified by:
getRestitutionin interfaceConstBody- Returns:
- the value (typically ≥0 and ≤1)
-
getRotation
Return the body's orientation. The body is unaffected.- Specified by:
getRotationin interfaceConstBody- Returns:
- a new rotation quaternion (relative to the system axes)
-
getShape
Access the body's shape. -
getUserData
public long getUserData()Return the body's user data: can be used for anything. The body is unaffected.- Specified by:
getUserDatain interfaceConstBody- Returns:
- the value
-
getWorldSpaceBounds
Access the body's bounding box. The body is unaffected.- Specified by:
getWorldSpaceBoundsin interfaceConstBody- Returns:
- a new immutable JVM object with the pre-existing native object assigned
-
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. -
isKinematic
public boolean isKinematic()Test whether the body is kinematic. It is unaffected.- Specified by:
isKinematicin interfaceConstBody- Returns:
- true if kinematic, otherwise false
-
isInBroadPhase
public boolean isInBroadPhase()Test whether the body has been added to itsPhysicsSystem. The body is unaffected.- Specified by:
isInBroadPhasein interfaceConstBody- Returns:
- true if added, otherwise false
-
isRigidBody
public boolean isRigidBody()Test whether the body is a rigid body. It is unaffected.- Specified by:
isRigidBodyin interfaceConstBody- Returns:
- true if rigid body, otherwise false
-
isSensor
public boolean isSensor()Test whether the body is a sensor. The body is unaffected. -
isStatic
public boolean isStatic()Test whether the body is static (non-moving). It is unaffected.
-