java.lang.Object
com.github.stephengold.joltjni.JoltPhysicsObject
com.github.stephengold.joltjni.NonCopyable
com.github.stephengold.joltjni.PhysicsSystem
- All Implemented Interfaces:
ConstJoltPhysicsObject,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'sBodyInterface.Access a version of the system'sBodyInterfacethat 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, va
-
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 (not null)
-
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 (not null, 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 (not null)renderer- the renderer to use (not null)
-
drawConstraints
Render all constraints in the system, for debugging purposes.- Parameters:
renderer- the renderer to use (not null)
-
drawConstraintLimits
Render the limits of all constraints in the system, for debugging purposes.- Parameters:
renderer- the renderer to use (not null)
-
drawConstraintReferenceFrame
Render the reference frames of all constraints in the system, for debugging purposes.- Parameters:
renderer- the renderer to use (not null)
-
containsConstraint
Test whether the system contains the specified constraint. The system is unaffected.- Parameters:
constraint- the constraint to search for (not null, unaffected)- Returns:
trueif found, otherwisefalse
-
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:
-
getActiveBodies
Enumerate all bodies of the specified type to the specified vector.- Parameters:
bodyType- (not null)storeResult- storage for the result (not null)
-
getBodies
Enumerate all bodies to the specified variable-length vector. The system is unaffected.- Parameters:
storeResult- storage for the result (not null)
-
getBodyActivationListener
Access the system'sBodyActivationListener.- Returns:
- a new JVM object with the pre-existing native object assigned, or
nullif none
-
getBodyInterface
Access the system'sBodyInterface.- Returns:
- the pre-existing JVM object (not null)
-
getBodyInterfaceNoLock
Access a version of the system'sBodyInterfacethat does not use locks.- Returns:
- a new JVM object with the pre-existing native object assigned
-
getBodyLockInterface
Access the system'sBodyLockInterfaceLocking.- Returns:
- a new JVM object with the pre-existing native object assigned
-
getBodyLockInterfaceNoLock
Access the system'sBodyLockInterfaceNoLock.- 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.- Returns:
- a new box
-
getBroadPhaseLayerInterface
Access the (application-provided) interface for mapping object layers to broadphase layers.- Returns:
- the pre-existing instance, or
nullif none
-
getBroadPhaseQuery
Access the system's interface for coarse collision queries.- Returns:
- the pre-existing JVM object, or
nullif the system hasn't been initialized yet
-
getCombineFriction
Access the combining function for friction.- Returns:
- a new JVM object with the pre-existing native object assigned
-
getCombineRestitution
Access the combining function for restitutions.- Returns:
- a new JVM object with the pre-existing native object assigned
-
getConstraints
Enumerate all constraints in the system. The system is unaffected.- Returns:
- a new object
-
getContactListener
Access the (application-provided) contact listener.- 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.- 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.- Parameters:
objectLayer- the index of the object layer to use- Returns:
- a new filter
-
getGravity
Copy the gravity vector. The system is unaffected.- 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.- Returns:
- the count (≥0)
-
getNarrowPhaseQuery
Access the system's interface for fine collision queries.- Returns:
- the pre-existing JVM object (not null)
-
getNarrowPhaseQueryNoLock
Access a version of the system'sNarrowPhaseQuerythat does not lock the bodies.- 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.- Parameters:
bodyType- which type of body to count (not null)- Returns:
- the count (≥0, ≤maxBodies)
-
getNumBodies
public int getNumBodies()Count how many bodies there are in the body manager. The system is unaffected.- Returns:
- the count (≥0, ≤maxBodies)
-
getObjectLayerPairFilter
Access the (application-provided) interface for testing whether 2 objects can collide, based on their object layers.- 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.- 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.- Returns:
- a new JVM object with a new native object assigned
- See Also:
-
getSoftBodyContactListener
Access the (application-provided) soft-body contact listener.- 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- (not null, alias created)ovbFilter- (not null, alias created)ovoFilter- (not null, 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 (not null)
-
removeStepListener
Remove the specified step listener from the system.- Parameters:
listener- the listener to remove (not null)
-
restoreState
Restore the system's state from the specified recorder, for replay.- Parameters:
recorder- where to read the state from (not null)- Returns:
trueif successful, otherwisefalse
-
saveState
Save the system's state to be replayed later.- Parameters:
recorder- where to save the state (not null)
-
saveState
Save the aspects of the system's state to be replayed later.- Parameters:
recorder- where to save the state (not null)bitmask- which aspects of the simulation to save
-
saveState
Save aspects of the system's state to be replayed later.- Parameters:
recorder- where to save the state (not null)bitmask- which aspects of the simulation to savefilter- select which parts to save (unaffected) ornull
-
setBodyActivationListener
Replace the system'sBodyActivationListener.- Parameters:
listener- the desired listener, ornullfor none
-
setCombineFriction
Replace the combining function for friction.- Parameters:
function- the desired function (not null, 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:
-