java.lang.Object
com.github.stephengold.joltjni.JoltPhysicsObject
com.github.stephengold.joltjni.NonCopyable
com.github.stephengold.joltjni.PhysicsSystem
- All Implemented Interfaces:
ConstJoltPhysicsObject,ConstPhysicsSystem,AutoCloseable,Comparable<JoltPhysicsObject>
Perform simulation on a collection of physics objects. Bodies are added by
way of a separate interface.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConstraint(Constraint constraint) Add the specified constraint to the system.voidaddConstraint(TwoBodyConstraintRef constraintRef) Add the specified constraint to the system.voidaddConstraint(VehicleConstraintRef constraintRef) Add the specified constraint to the system.voidaddStepListener(PhysicsStepListener listener) Add the specified step listener to the system.booleancontainsConstraint(ConstConstraint constraint) Test whether the system contains the specified constraint.intRemove and destroy all bodies in the system.voiddrawBodies(BodyManagerDrawSettings settings, DebugRenderer renderer) Render the bodies in the system, for debugging purposes.voiddrawConstraintLimits(DebugRenderer renderer) Render the limits of all constraints in the system, for debugging purposes.voiddrawConstraintReferenceFrame(DebugRenderer renderer) Render the reference frames of all constraints in the system, for debugging purposes.voiddrawConstraints(DebugRenderer renderer) Render all constraints in the system, for debugging purposes.static PhysicsSystemfind(long systemVa) Find a pre-existing system given its virtual address.voidforgetMe()Make the current system un-findable, so it can be garbage collected.voidgetActiveBodies(EBodyType bodyType, BodyIdVector storeResult) Enumerate all bodies of the specified type to the specified vector.voidgetBodies(BodyIdVector storeResult) Enumerate all bodies to the specified variable-length vector.Access the system'sBodyActivationListener.Access the system'sBatchBodyInterface.Access a version of the system'sBatchBodyInterfacethat does not use locks.Access the system'sBodyLockInterfaceLocking.Access the system'sBodyLockInterfaceNoLock.Generate a bounding box that contains all the bodies in the system.Access the (application-provided) interface for mapping object layers to broadphase layers.Access the system's interface for coarse collision queries.Access the combining function for friction.Access the combining function for restitutions.Enumerate all constraints in the system.Access the (application-provided) contact listener.getDefaultBroadPhaseLayerFilter(int objectLayer) Generate a broad-phase layer filter using the current pair filter and the specified layer index.getDefaultLayerFilter(int objectLayer) Generate an object layer filter using the current pair filter and the specified layer index.Copy the gravity vector.intReturn the maximum number of bodies the system supports.Access the system's interface for fine collision queries.Access a version of the system'sNarrowPhaseQuerythat does not lock the bodies.intgetNumActiveBodies(EBodyType bodyType) Count how many active bodies of the specified type there are in the body manager.intCount how many bodies there are in the body manager.Access the (application-provided) interface for testing whether 2 objects can collide, based on their object layers.Access the (application-provided) interface for testing whether an object can collide with a broad-phase layer.Copy the system's settings.Access the (application-provided) soft-body contact listener.init(int maxBodies, int numBodyMutexes, int maxBodyPairs, int maxContactConstraints, ConstBroadPhaseLayerInterface map, ConstObjectVsBroadPhaseLayerFilter ovbFilter, ConstObjectLayerPairFilter ovoFilter) Initialize the system with the specified limits.voidImprove the performance of future collision detections.intRemove all bodies from the system, but don't destroy them.intRemove all constraints from the system.voidremoveConstraint(Constraint constraint) Remove the specified constraint from the system.voidremoveStepListener(PhysicsStepListener listener) Remove the specified step listener from the system.booleanrestoreState(StateRecorder recorder) Restore the system's state from the specified recorder, for replay.voidsaveState(StateRecorder recorder) Save the system's state to be replayed later.voidsaveState(StateRecorder recorder, int bitmask) Save the aspects of the system's state to be replayed later.voidsaveState(StateRecorder recorder, int bitmask, StateRecorderFilter filter) Save aspects of the system's state to be replayed later.voidReplace the system'sBodyActivationListener.voidsetCombineFriction(CombineFunction function) Replace the combining function for friction.voidsetCombineRestitution(CombineFunction function) Replace the combining function for restitutions.voidsetContactListener(ContactListener listener) Replace or remove the system's contact listener.voidsetGravity(float x, float y, float z) Alter the system's gravity vector.voidsetGravity(Vec3Arg gravity) Alter the system's gravity vector.voidsetPhysicsSettings(ConstPhysicsSettings settings) Copy the specified settings to the system.voidsetSimCollideBodyVsBody(SimCollideBodyVsBody bodyVsBody) Replace the system's body-vs-body collide function.voidsetSimShapeFilter(SimShapeFilter shapeFilter) Replace or remove the shape filter that will be used during simulation.voidReplace or remove the system's soft-body contact listener.intupdate(float deltaTime, int collisionSteps, TempAllocator tempAllocator, JobSystem jobSystem) Advance the simulation by the specified amount.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
-
PhysicsSystem
public PhysicsSystem()Instantiate an uninitialized physics system.
-
-
Method Details
-
addConstraint
Add the specified constraint to the system.- Parameters:
constraint- the constraint to add (notnull)
-
addConstraint
Add the specified constraint to the system.- Parameters:
constraintRef- a counted reference to the constraint to add (not null)
-
addConstraint
Add the specified constraint to the system.- Parameters:
constraintRef- a counted reference to the constraint to add (not null)
-
addStepListener
Add the specified step listener to the system.Step listeners are limited in what actions they can perform.
- Parameters:
listener- the listener to add (notnull, alias created)
-
destroyAllBodies
public int destroyAllBodies()Remove and destroy all bodies in the system.- Returns:
- the number of bodies destroyed (≥0)
-
drawBodies
Render the bodies in the system, for debugging purposes.- Parameters:
settings- the settings to use (notnull)renderer- the renderer to use (notnull)
-
drawConstraints
Render all constraints in the system, for debugging purposes.- Parameters:
renderer- the renderer to use (notnull)
-
drawConstraintLimits
Render the limits of all constraints in the system, for debugging purposes.- Parameters:
renderer- the renderer to use (notnull)
-
drawConstraintReferenceFrame
Render the reference frames of all constraints in the system, for debugging purposes.- Parameters:
renderer- the renderer to use (notnull)
-
find
Find a pre-existing system given its virtual address.- Parameters:
systemVa- the address to search for- Returns:
- the pre-existing object, or
nullif not found - See Also:
-
forgetMe
public void forgetMe()Make the current system un-findable, so it can be garbage collected.- See Also:
-
getBodyInterface
Access the system'sBatchBodyInterface.- Returns:
- the pre-existing JVM object (not
null)
-
getBodyInterfaceNoLock
Access a version of the system'sBatchBodyInterfacethat does not use locks.- Returns:
- a new JVM object with the pre-existing native object assigned
-
getBroadPhaseLayerInterface
Access the (application-provided) interface for mapping object layers to broadphase layers.- Returns:
- the pre-existing instance, or
nullif none
-
init
public PhysicsSystem init(int maxBodies, int numBodyMutexes, int maxBodyPairs, int maxContactConstraints, ConstBroadPhaseLayerInterface map, ConstObjectVsBroadPhaseLayerFilter ovbFilter, ConstObjectLayerPairFilter ovoFilter) Initialize the system with the specified limits.- Parameters:
maxBodies- the desired maximum number of rigid bodies that can be addednumBodyMutexes- the desired number of mutexes to allocate, or 0 for the default numbermaxBodyPairs- the desired maximum number of body pairs that can be queued at a time (≥3)maxContactConstraints- the desired capacity of the contact-constraint buffermap- (notnull, alias created)ovbFilter- (notnull, alias created)ovoFilter- (notnull, alias created)- Returns:
- the current system (for chaining)
-
optimizeBroadPhase
public void optimizeBroadPhase()Improve the performance of future collision detections. -
removeAllBodies
public int removeAllBodies()Remove all bodies from the system, but don't destroy them.- Returns:
- the number of bodies removed (≥0)
- See Also:
-
removeAllConstraints
public int removeAllConstraints()Remove all constraints from the system.- Returns:
- the number of constraints removed (≥0)
-
removeConstraint
Remove the specified constraint from the system.- Parameters:
constraint- the constraint to remove (notnull)
-
removeStepListener
Remove the specified step listener from the system.- Parameters:
listener- the listener to remove (notnull)
-
restoreState
Restore the system's state from the specified recorder, for replay.- Parameters:
recorder- where to read the state from (notnull)- Returns:
trueif successful, otherwisefalse
-
setBodyActivationListener
Replace the system'sBodyActivationListener.- Parameters:
listener- the desired listener, ornullfor none
-
setCombineFriction
Replace the combining function for friction.- Parameters:
function- the desired function (notnull, default=geometricMean)
-
setCombineRestitution
Replace the combining function for restitutions.- Parameters:
function- the desired function (notnull, default=max)
-
setContactListener
Replace or remove the system's contact listener.- Parameters:
listener- the desired listener, ornullfor none
-
setGravity
public void setGravity(float x, float y, float z) Alter the system's gravity vector.- Parameters:
x- the X component of the desired acceleration vector (in system coordinates)y- the Y component of the desired acceleration vector (in system coordinates)z- the Z component of the desired acceleration vector (in system coordinates)
-
setGravity
Alter the system's gravity vector.- Parameters:
gravity- the desired acceleration vector (in system coordinates, notnull, unaffected, default=(0,-9.81,0))
-
setPhysicsSettings
Copy the specified settings to the system.- Parameters:
settings- the desired settings (notnull, unaffected)- See Also:
-
setSimCollideBodyVsBody
Replace the system's body-vs-body collide function.- Parameters:
bodyVsBody- the desired function (notnull)
-
setSimShapeFilter
Replace or remove the shape filter that will be used during simulation.- Parameters:
shapeFilter- the desired filter, ornullto remove a filter previously set
-
setSoftBodyContactListener
Replace or remove the system's soft-body contact listener.- Parameters:
listener- the desired listener, ornullfor none
-
update
public int update(float deltaTime, int collisionSteps, TempAllocator tempAllocator, JobSystem jobSystem) Advance the simulation by the specified amount.- Parameters:
deltaTime- the total time to advance (in seconds)collisionSteps- the number of simulation steps to performtempAllocator- the allocator to use (notnull)jobSystem- the job system to use (notnull)- Returns:
- a bitmask of error conditions, or-ed together
- See Also:
-
containsConstraint
Test whether the system contains the specified constraint. The system is unaffected.- Specified by:
containsConstraintin interfaceConstPhysicsSystem- Parameters:
constraint- the constraint to search for (notnull, unaffected)- Returns:
trueif found, otherwisefalse
-
getActiveBodies
Enumerate all bodies of the specified type to the specified vector.- Specified by:
getActiveBodiesin interfaceConstPhysicsSystem- Parameters:
bodyType- (notnull)storeResult- storage for the result (notnull)
-
getBodies
Enumerate all bodies to the specified variable-length vector. The system is unaffected.- Specified by:
getBodiesin interfaceConstPhysicsSystem- Parameters:
storeResult- storage for the result (notnull)
-
getBodyActivationListener
Access the system'sBodyActivationListener.- Specified by:
getBodyActivationListenerin interfaceConstPhysicsSystem- Returns:
- a new JVM object with the pre-existing native object assigned, or
nullif none
-
getBodyLockInterface
Access the system'sBodyLockInterfaceLocking.- Specified by:
getBodyLockInterfacein interfaceConstPhysicsSystem- Returns:
- a new JVM object with the pre-existing native object assigned
-
getBodyLockInterfaceNoLock
Access the system'sBodyLockInterfaceNoLock.- Specified by:
getBodyLockInterfaceNoLockin interfaceConstPhysicsSystem- Returns:
- a new JVM object with the pre-existing native object assigned
-
getBounds
Generate a bounding box that contains all the bodies in the system. The system is unaffected.- Specified by:
getBoundsin interfaceConstPhysicsSystem- Returns:
- a new box
-
getBroadPhaseQuery
Access the system's interface for coarse collision queries.- Specified by:
getBroadPhaseQueryin interfaceConstPhysicsSystem- Returns:
- the pre-existing JVM object, or
nullif the system hasn't been initialized yet
-
getCombineFriction
Access the combining function for friction.- Specified by:
getCombineFrictionin interfaceConstPhysicsSystem- Returns:
- a new JVM object with the pre-existing native object assigned
-
getCombineRestitution
Access the combining function for restitutions.- Specified by:
getCombineRestitutionin interfaceConstPhysicsSystem- Returns:
- a new JVM object with the pre-existing native object assigned
-
getConstraints
Enumerate all constraints in the system. The system is unaffected.- Specified by:
getConstraintsin interfaceConstPhysicsSystem- Returns:
- a new object
-
getContactListener
Access the (application-provided) contact listener.- Specified by:
getContactListenerin interfaceConstPhysicsSystem- Returns:
- the pre-existing instance, or
nullif none
-
getDefaultBroadPhaseLayerFilter
Generate a broad-phase layer filter using the current pair filter and the specified layer index.- Specified by:
getDefaultBroadPhaseLayerFilterin interfaceConstPhysicsSystem- Parameters:
objectLayer- the index of the object layer to use- Returns:
- a new filter
-
getDefaultLayerFilter
Generate an object layer filter using the current pair filter and the specified layer index.- Specified by:
getDefaultLayerFilterin interfaceConstPhysicsSystem- Parameters:
objectLayer- the index of the object layer to use- Returns:
- a new filter
-
getGravity
Copy the gravity vector. The system is unaffected.- Specified by:
getGravityin interfaceConstPhysicsSystem- Returns:
- a new acceleration vector (meters per second squared in system coordinates)
-
getMaxBodies
public int getMaxBodies()Return the maximum number of bodies the system supports. The system is unaffected.- Specified by:
getMaxBodiesin interfaceConstPhysicsSystem- Returns:
- the count (≥0)
-
getNarrowPhaseQuery
Access the system's interface for fine collision queries.- Specified by:
getNarrowPhaseQueryin interfaceConstPhysicsSystem- Returns:
- the pre-existing JVM object (not
null)
-
getNarrowPhaseQueryNoLock
Access a version of the system'sNarrowPhaseQuerythat does not lock the bodies.- Specified by:
getNarrowPhaseQueryNoLockin interfaceConstPhysicsSystem- Returns:
- the pre-existing JVM object (not
null)
-
getNumActiveBodies
Count how many active bodies of the specified type there are in the body manager. The system is unaffected.- Specified by:
getNumActiveBodiesin interfaceConstPhysicsSystem- Parameters:
bodyType- which type of body to count (notnull)- Returns:
- the count (≥0, ≤maxBodies)
-
getNumBodies
public int getNumBodies()Count how many bodies there are in the body manager. The system is unaffected.- Specified by:
getNumBodiesin interfaceConstPhysicsSystem- Returns:
- the count (≥0, ≤maxBodies)
-
getObjectLayerPairFilter
Access the (application-provided) interface for testing whether 2 objects can collide, based on their object layers.- Specified by:
getObjectLayerPairFilterin interfaceConstPhysicsSystem- Returns:
- the pre-existing instance, or
nullif none
-
getObjectVsBroadPhaseLayerFilter
Access the (application-provided) interface for testing whether an object can collide with a broad-phase layer.- Specified by:
getObjectVsBroadPhaseLayerFilterin interfaceConstPhysicsSystem- Returns:
- the pre-existing instance, or
nullif none
-
getPhysicsSettings
Copy the system's settings. The system is unaffected.Different semantics from the native
GetPhysicsSettings(), which returns a const reference, not a copy.- Specified by:
getPhysicsSettingsin interfaceConstPhysicsSystem- Returns:
- a new JVM object with a new native object assigned
- See Also:
-
getSoftBodyContactListener
Access the (application-provided) soft-body contact listener.- Specified by:
getSoftBodyContactListenerin interfaceConstPhysicsSystem- Returns:
- the pre-existing instance, or
nullif none
-
saveState
Save the system's state to be replayed later.- Specified by:
saveStatein interfaceConstPhysicsSystem- Parameters:
recorder- where to save the state (notnull)
-
saveState
Save the aspects of the system's state to be replayed later.- Specified by:
saveStatein interfaceConstPhysicsSystem- Parameters:
recorder- where to save the state (notnull)bitmask- which aspects of the simulation to save
-
saveState
Save aspects of the system's state to be replayed later.- Specified by:
saveStatein interfaceConstPhysicsSystem- Parameters:
recorder- where to save the state (notnull)bitmask- which aspects of the simulation to savefilter- select which parts to save (unaffected) ornull
-