Package com.github.stephengold.joltjni
Class PhysicsSystem
java.lang.Object
com.github.stephengold.joltjni.JoltPhysicsObject
com.github.stephengold.joltjni.NonCopyable
com.github.stephengold.joltjni.PhysicsSystem
- All Implemented Interfaces:
ConstJoltPhysicsObject,AutoCloseable,Comparable<ConstJoltPhysicsObject>
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.voidaddStepListener(PhysicsStepListener listener) Add the specified step listener to the system.voiddrawBodies(BodyManagerDrawSettings settings, DebugRenderer renderer) Render the state of the system, for debugging purposes.static PhysicsSystemfind(long systemVa) Find a pre-existing system given its virtual address.voidgetActiveBodies(EBodyType bodyType, BodyIdVector storeResult) Enumerate 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.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 the 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 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.voidinit(int maxBodies, int numBodyMutexes, int maxBodyPairs, int maxContactConstraints, ConstBroadPhaseLayerInterface map, ConstObjectVsBroadPhaseLayerFilter ovbFilter, ConstObjectLayerPairFilter ovoFilter) Initialize the physics system with the specified limits.voidImprove the performance of future collision detections.voidremoveConstraint(Constraint constraint) Remove the specified constraint 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 the system's contact listener.voidsetGravity(Vec3Arg gravity) Alter the system's gravity vector.voidsetPhysicsSettings(PhysicsSettings settings) Copy the specified settings to the system.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, hasAssignedNativeObject, hashCode, ownsNativeObject, setVirtualAddress, startCleaner, 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)
-
addStepListener
Add the specified step listener to the system.- Parameters:
listener- the listener to add (not null, alias created)
-
drawBodies
Render the state of the system, for debugging purposes.- Parameters:
settings- the settings to use (not null)renderer- the renderer to use (not null)
-
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
-
getActiveBodies
Enumerate 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
Return a bounding box that contains all the bodies in the system.- 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 null if the system hasn't be 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 the constraints in the system.- 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 physics system is unaffected.- Returns:
- a new acceleration vector (meters per second squared in physics-system coordinates)
-
getMaxBodies
public int getMaxBodies()Return the maximum number of bodies the system supports. The physics 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 physics 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 physics 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
nullif 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
nullif none
-
getPhysicsSettings
Copy the system's settings.- Returns:
- a new JVM object with a new native object assigned
- See Also:
-
init
public void init(int maxBodies, int numBodyMutexes, int maxBodyPairs, int maxContactConstraints, ConstBroadPhaseLayerInterface map, ConstObjectVsBroadPhaseLayerFilter ovbFilter, ConstObjectLayerPairFilter ovoFilter) Initialize the physics 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. -
removeConstraint
Remove the specified constraint from the system.- Parameters:
constraint- the constraint 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, otherwise false
-
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 (may be null, unaffected)
-
setBodyActivationListener
Replace the system'sBodyActivationListener.- Parameters:
listener- the desired listener
-
setCombineFriction
Replace the combining function for friction.- Parameters:
function- the desired function (not null)
-
setCombineRestitution
Replace the combining function for restitutions.- Parameters:
function- the desired function (not null)
-
setContactListener
Replace the system's contact listener.- Parameters:
listener- the desired listener
-
setGravity
Alter the system's gravity vector.- Parameters:
gravity- the desired acceleration vector (in system coordinates, not null, unaffected)
-
setPhysicsSettings
Copy the specified settings to the system.- Parameters:
settings- the desired settings (not null, unaffected)- See Also:
-
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:
-