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 TypeMethodDescriptionvoid
addConstraint
(Constraint constraint) Add the specified constraint to the system.void
addConstraint
(TwoBodyConstraintRef constraintRef) Add the specified constraint to the system.void
addStepListener
(PhysicsStepListener listener) Add the specified step listener to the system.boolean
containsConstraint
(ConstConstraint constraint) Test whether the system contains the specified constraint.int
Remove and destroy all bodies in the system.void
drawBodies
(BodyManagerDrawSettings settings, DebugRenderer renderer) Render the bodies in the system, for debugging purposes.void
drawConstraintLimits
(DebugRenderer renderer) Render the limits of all constraints in the system, for debugging purposes.void
drawConstraintReferenceFrame
(DebugRenderer renderer) Render the reference frames of all constraints in the system, for debugging purposes.void
drawConstraints
(DebugRenderer renderer) Render all constraints in the system, for debugging purposes.static PhysicsSystem
find
(long systemVa) Find a pre-existing system given its virtual address.void
getActiveBodies
(EBodyType bodyType, BodyIdVector storeResult) Enumerate all bodies of the specified type to the specified vector.void
getBodies
(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'sBodyInterface
that does not use locks.Access the system'sBodyLockInterfaceLocking
.Access the system'sBodyLockInterfaceNoLock
.Return 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.int
Return the maximum number of bodies the system supports.Access the system's interface for fine collision queries.Access a version of the system'sNarrowPhaseQuery
that does not lock the bodies.int
getNumActiveBodies
(EBodyType bodyType) Count how many active bodies of the specified type there are in the body manager.int
Count how many bodies there are in the body manager.Access the (application-provided) interface for testing whether an object can collide with a broad-phase layer.Access the (application-provided) interface for testing whether 2 objects can collide, based on their object layers.Copy the system's settings.Access the (application-provided) soft-body contact listener.void
init
(int maxBodies, int numBodyMutexes, int maxBodyPairs, int maxContactConstraints, ConstBroadPhaseLayerInterface map, ConstObjectVsBroadPhaseLayerFilter ovbFilter, ConstObjectLayerPairFilter ovoFilter) Initialize the system with the specified limits.void
Improve the performance of future collision detections.int
Remove all bodies from the system, but don't destroy them.int
Remove all constraints from the system.void
removeConstraint
(Constraint constraint) Remove the specified constraint from the system.void
removeStepListener
(PhysicsStepListener listener) Remove the specified step listener from the system.boolean
restoreState
(StateRecorder recorder) Restore the system's state from the specified recorder, for replay.void
saveState
(StateRecorder recorder) Save the system's state to be replayed later.void
saveState
(StateRecorder recorder, int bitmask) Save the aspects of the system's state to be replayed later.void
saveState
(StateRecorder recorder, int bitmask, StateRecorderFilter filter) Save aspects of the system's state to be replayed later.void
Replace the system'sBodyActivationListener
.void
setCombineFriction
(CombineFunction function) Replace the combining function for friction.void
setCombineRestitution
(CombineFunction function) Replace the combining function for restitutions.void
setContactListener
(ContactListener listener) Replace the system's contact listener.void
setGravity
(float x, float y, float z) Alter the system's gravity vector.void
setGravity
(Vec3Arg gravity) Alter the system's gravity vector.void
setPhysicsSettings
(PhysicsSettings settings) Copy the specified settings to the system.void
Replace the system's soft-body contact listener.int
update
(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, 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)
-
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:
true
if 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
null
if not found
-
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
null
if none
-
getBodyInterface
Access the system'sBodyInterface
.- Returns:
- the pre-existing JVM object (not null)
-
getBodyInterfaceNoLock
Access a version of the system'sBodyInterface
that 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
Return 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
null
if none
-
getBroadPhaseQuery
Access the system's interface for coarse collision queries.- Returns:
- the pre-existing JVM object, or
null
if 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
null
if 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'sNarrowPhaseQuery
that 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)
-
getOvbFilter
Access the (application-provided) interface for testing whether an object can collide with a broad-phase layer.- Returns:
- the pre-existing instance, or
null
if none
-
getOvoFilter
Access the (application-provided) interface for testing whether 2 objects can collide, based on their object layers.- Returns:
- the pre-existing instance, or
null
if none
-
getPhysicsSettings
Copy the system's settings. The system is unaffected.- 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
null
if none
-
init
public void 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 timemaxContactConstraints
- the desired capacity of the contact-constraint buffermap
- (not null, alias created)ovbFilter
- (not null, alias created)ovoFilter
- (not null, alias created)
-
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:
true
if 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
-
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 (not null, default=max)
-
setContactListener
Replace the system's contact listener.- Parameters:
listener
- the desired listener
-
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, not null, unaffected, default=(0,-9.81,0))
-
setPhysicsSettings
Copy the specified settings to the system.- Parameters:
settings
- the desired settings (not null, unaffected)- See Also:
-
setSoftBodyContactListener
Replace the system's soft-body contact listener.- Parameters:
listener
- the desired listener
-
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 (not null)jobSystem
- the job system to use (not null)- Returns:
- a bitmask of error conditions, or-ed together
- See Also:
-