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.Body(JoltPhysicsObject container, long bodyVa) Instantiate with the specified container and native object. -
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(float jx, float jy, float jz) Apply the specified impulse to the body's center of mass.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.booleanapplyBuoyancyImpulse(RVec3Arg surfacePosition, Vec3Arg surfaceNormal, float buoyancy, float linearDrag, float angularDrag, Vec3Arg fluidVelocity, Vec3Arg gravity, float deltaTime) Apply an impulse that simulates buoyancy and drag.booleanTest 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.booleanTest whether the body is allowed to fall asleep.Copy the body's angular velocity.Generate settings to reconstruct the (rigid) body.Return the body type (rigid or soft).intReturn the broadphase layer.Copy the location of the body's center of mass (which might not coincide with its origin).voidgetCenterOfMassPosition(RVec3 storeLocation) Copy the location of the body's center of mass (which might not coincide with its origin).voidgetCenterOfMassPosition(DoubleBuffer storeResult) 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.booleanTest whether extra effort should be made to remove ghost contacts.floatReturn the body's friction ratio.intgetId()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.intReturn the body's object layer.Copy the location of the body's origin (which might not coincide with its center of mass).voidgetPositionAndRotation(RVec3 storeLocation, Quat storeOrientation) Copy the position of the body.floatReturn the body's restitution ratio.Copy the body's orientation.getShape()Access the body's shape.voidUpdate the specified counted reference to refer to the body's shape.Generate settings to reconstruct the (soft) body.Convert the body to aTransformedShapeobject.longReturn 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 subshape at the specified location.Copy the world transform.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.booleanTest whether the body is soft.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(float wx, float wy, float wz) Directly alter the body's angular velocity.voidsetAngularVelocity(Vec3Arg omega) Directly alter the body's angular velocity.voidsetAngularVelocityClamped(Vec3Arg omega) Alter the body's angular velocity within limits.voidAssign the body to the specified collision group.voidsetEnhancedInternalEdgeRemoval(boolean enhance) Alter whether extra effort should be made to remove ghost contacts.voidsetFriction(float friction) Alter the body's friction ratio.voidsetIsSensor(boolean setting) Alter whether the body is a sensor.voidsetLinearVelocity(float vx, float vy, float vz) Directly alter the body's linear velocity.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) Reposition the body and reset its sleep timer.voidsetPositionAndRotationInternal(RVec3Arg location, QuatArg orientation, boolean resetSleepTimer) Reposition the body.voidsetRestitution(float restitution) Alter the body's restitution ratio.voidsetUserData(long value) Alter the body's user data.static BodyCreate 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, isCleanerStarted, ownsNativeObject, setVirtualAddress, setVirtualAddress, startCleaner, targetVa, 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, targetVa
-
Constructor Details
-
Body
Instantiate with the specified container and native object.For use in custom contact listeners.
- Parameters:
container- the containingPhysicsSystemorBodyManagerbodyVa- the virtual address of the native object to assign (not zero)
-
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, notnull, unaffected)
-
addForce
Apply the specified force to the body's center of mass.- Parameters:
force- the force vector (Newtons in system coordinates, notnull, unaffected)
-
addForce
Apply the specified force at the specified location.- Parameters:
force- the force vector (notnull, unaffected)location- where to apply the force (Newtons in system coordinates notnull, 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, notnull, unaffected)
-
addImpulse
Apply the specified impulse at the specified location.- Parameters:
impulse- the impulse vector (kilogram.meters per second in system coordinates, notnull, unaffected)location- where to apply the impulse (notnull, unaffected)
-
addTorque
Apply the specified torque to the body.- Parameters:
torque- the torque vector (Newton.meters in system coordinates, notnull, 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, notnull, unaffected)surfaceNormal- the upward normal direction of the fluid's surface (in system coordinates, notnull, 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, notnull, unaffected)gravity- the gravity vector (in system coordinates, notnull, unaffected)deltaTime- the duration of the simulation step (in seconds)- Returns:
trueif an impulse was applied,falseif not in the fluid
-
moveKinematic
Reposition the body, assuming it's kinematic.- Parameters:
location- the desired location (in system coordinates, notnull, unaffected)orientation- the desired orientation (relative to the system axes, notnull, 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-trueto allow,falseto inhibit
-
setAngularVelocity
public void setAngularVelocity(float wx, float wy, float wz) Directly alter the body's angular velocity.- Parameters:
wx- the X component of the desired angular velocity (radians per second in system coordinates, default=0)wy- the Y component of the desired angular velocity (radians per second in system coordinates, default=0)wz- the Z component of the desired angular velocity (radians per second in system coordinates, default=0)
-
setAngularVelocity
Directly alter the body's angular velocity.- Parameters:
omega- the desired angular velocity (radians per second in system coordinates, notnull, unaffected, default=(0,0,0))
-
setAngularVelocityClamped
Alter the body's angular velocity within limits.- Parameters:
omega- the desired angular velocity (notnull, unaffected, default=(0,0,0))
-
setCollisionGroup
Assign the body to the specified collision group.- Parameters:
group- the group to assign (notnull, unaffected)
-
setEnhancedInternalEdgeRemoval
public void setEnhancedInternalEdgeRemoval(boolean enhance) Alter whether extra effort should be made to remove ghost contacts.- Parameters:
enhance-truefor extra effort,falsefor 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-trueto make it a sensor,falsefor a regular body (default=false)
-
setLinearVelocity
public void setLinearVelocity(float vx, float vy, float vz) Directly alter the body's linear velocity.- Parameters:
vx- the X component of the desired velocity (meters per second in system coordinates, default=0)vy- the Y component of the desired velocity (meters per second in system coordinates, default=0)vz- the Z component of the desired velocity (meters per second in system coordinates, default=0)
-
setLinearVelocity
Directly alter the body's linear velocity.- Parameters:
velocity- the desired velocity (meters per second in system coordinates, notnull, unaffected, default=(0,0,0))
-
setLinearVelocityClamped
Alter the body's linear velocity within limits.- Parameters:
velocity- the desired linear velocity (in meters per second, notnull, unaffected, default=(0,0,0))
-
setMotionType
Alter the body's motion type.- Parameters:
motionType- the desired value (notnull)
-
setPositionAndRotationInternal
Reposition the body and reset its sleep timer.- Parameters:
location- the desired location (in system coordinates, notnull, unaffected)orientation- the desired orientation (relative to the system axes, notnull, unaffected)
-
setPositionAndRotationInternal
public void setPositionAndRotationInternal(RVec3Arg location, QuatArg orientation, boolean resetSleepTimer) Reposition the body.- Parameters:
location- the desired location (in system coordinates, notnull, unaffected)orientation- the desired orientation (relative to the system axes, notnull, unaffected)resetSleepTimer-trueto reset the body's sleep timer,falseto 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:
trueif possible, otherwisefalse
-
getAccumulatedForce
Copy 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
Copy 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:
trueif allowed, otherwisefalse
-
getAngularVelocity
Copy 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
Generate settings to reconstruct the (rigid) body. The body is unaffected.- Specified by:
getBodyCreationSettingsin interfaceConstBody- Returns:
- a new object
-
getBodyType
Return the body type (rigid or soft). The body is unaffected.- Specified by:
getBodyTypein interfaceConstBody- Returns:
- an enum value (not
null)
-
getBroadPhaseLayer
public int getBroadPhaseLayer()Return the broadphase layer. The body is unaffected.- Specified by:
getBroadPhaseLayerin 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:
getCenterOfMassPositionin 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:
getCenterOfMassPositionin interfaceConstBody- Parameters:
storeResult- storage for the location in system coordinates (notnull, modified)
-
getCenterOfMassPosition
Copy the location of the body's center of mass (which might not coincide with its origin). The body is unaffected.- Specified by:
getCenterOfMassPositionin interfaceConstBody- Parameters:
storeLocation- storage for the location (in system coordinates, notnull, modified)
-
getCenterOfMassTransform
Copy the coordinate transform of the body's center of mass. The body is unaffected.- Specified by:
getCenterOfMassTransformin interfaceConstBody- Returns:
- a new transform matrix (relative to system coordinates)
-
getCollisionGroup
Access the body's collision group.- Specified by:
getCollisionGroupin 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:
getEnhancedInternalEdgeRemovalin interfaceConstBody- Returns:
truefor extra effort, otherwisefalse
-
getFriction
public float getFriction()Return the body's friction ratio. The body is unaffected.- Specified by:
getFrictionin interfaceConstBody- Returns:
- the ratio
-
getId
public int getId()Return the body's ID for use withBodyInterface. The body is unaffected. (native function: GetID) -
getInverseCenterOfMassTransform
Copy the inverse coordinate transform of the body's center of mass. The body is unaffected.- Specified by:
getInverseCenterOfMassTransformin interfaceConstBody- Returns:
- a new transform matrix (relative to local coordinates)
-
getLinearVelocity
Copy the body's linear velocity. The body is unaffected.- Specified by:
getLinearVelocityin interfaceConstBody- Returns:
- a new velocity vector (meters per second in system coordinates)
-
getMotionProperties
Access the body's motion properties.- Specified by:
getMotionPropertiesin interfaceConstBody- Returns:
- a new JVM object with the pre-existing native object assigned, or
nullif none
-
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
Copy 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)
-
getPositionAndRotation
Copy the position of the body. The body is unaffected.- Specified by:
getPositionAndRotationin interfaceConstBody- Parameters:
storeLocation- storage for the location (in system coordinates, notnull, modified)storeOrientation- storage for the orientation (in system coordinates, notnull, modified)
-
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
Copy 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. The body is unaffected. -
getShape
Update the specified counted reference to refer to the body's shape. The body is unaffected. -
getSoftBodyCreationSettings
Generate settings to reconstruct the (soft) body. The body is unaffected.- Specified by:
getSoftBodyCreationSettingsin interfaceConstBody- Returns:
- a new object
-
getTransformedShape
Convert the body to aTransformedShapeobject. The body is unaffected.- Specified by:
getTransformedShapein 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:
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
-
getWorldSpaceSurfaceNormal
Copy the surface normal of a particular subshape at the specified location. The body is unaffected.- Specified by:
getWorldSpaceSurfaceNormalin interfaceConstBody- Parameters:
subShapeId- the ID of the sub-shape to uselocation- the location to use (notnull, unaffected)- Returns:
- a new direction vector
-
getWorldTransform
Copy the world transform. The body is unaffected.- Specified by:
getWorldTransformin 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:
isInBroadPhasein interfaceConstBody- Returns:
trueif added, otherwisefalse
-
isKinematic
public boolean isKinematic()Test whether the body is kinematic. It is unaffected.- Specified by:
isKinematicin interfaceConstBody- Returns:
trueif kinematic, otherwisefalse
-
isRigidBody
public boolean isRigidBody()Test whether the body is a rigid body. It is unaffected.- Specified by:
isRigidBodyin interfaceConstBody- Returns:
trueif 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:
isSoftBodyin interfaceConstBody- Returns:
trueif soft, otherwisefalse
-
isStatic
public boolean isStatic()Test whether the body is static (non-moving). It is unaffected.
-