Class PhysicsSpace
- All Implemented Interfaces:
- ContactListener,- Comparable<NativePhysicsObject>
- Direct Known Subclasses:
- MultiBodySpace,- PhysicsSoftSpace
btDiscreteDynamicsWorld.- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic enumEnumerate the available accelerators for broadphase collision detection.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intindex of the X axisstatic final intindex of the Y axisstatic final intindex of the Z axisstatic final Loggermessage logger for this classFields inherited from class com.jme3.bullet.CollisionSpaceloggerCFields inherited from class com.jme3.bullet.NativePhysicsObjectloggerN
- 
Constructor SummaryConstructorsConstructorDescriptionPhysicsSpace(PhysicsSpace.BroadphaseType broadphaseType) Instantiate a PhysicsSpace with sequential-impulse solvers.PhysicsSpace(Vector3f worldMin, Vector3f worldMax) Instantiate a PhysicsSpace with an AXIS_SWEEP_3 broadphase accelerator and sequential-impulse solvers.PhysicsSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType) Instantiate a PhysicsSpace with sequential-impulse solvers.PhysicsSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType, int numSolvers) Instantiate a PhysicsSpace with the specified number of sequential-impulse solvers.PhysicsSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType, int numSolvers, CollisionConfiguration configuration) Instantiate a PhysicsSpace with the specified number of sequential-impulse solvers.PhysicsSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType, SolverType solverType) Instantiate a PhysicsSpace with the specified contact-and-constraint solver.PhysicsSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType, SolverType solverType, CollisionConfiguration configuration) Instantiate a PhysicsSpace with the specified contact-and-constraint solver.
- 
Method SummaryModifier and TypeMethodDescriptionvoidactivateAll(boolean forceFlag) Activate all rigid bodies in the space.voidAdd the specified object to the space.voidAdd the specified collision object to the space.voidaddJoint(PhysicsJoint joint) Add the specified PhysicsJoint to the space.voidaddTickListener(PhysicsTickListener listener) Register the specified tick listener with the space.booleanTest whether the specified collision object is added to the space.booleancontains(PhysicsJoint joint) Test whether the specified PhysicsJoint is added to the space.intCount the joints in the space.intCount the collision manifolds in the space.intCount the rigid bodies in the space, including vehicles.intCount how many tick listeners are registered with the space.protected voidcreate()Must be invoked on the designated physics thread.voiddestroy()Remove all collision objects and physics joints.floatReturn the simulation accuracy: the time step used when maxSubSteps>0.Enumerate physics characters that have been added to the space and not yet removed.getGravity(Vector3f storeResult) Copy the gravitational acceleration for newly-added bodies.Enumerate physics joints that have been added to the space and not yet removed.protected Map<Long, PhysicsJoint> Access the map from native IDs to physics joints.Enumerate collision objects that have been added to the space and not yet removed.static PhysicsSpaceAccess the PhysicsSpace running on this thread.Enumerate rigid bodies (including vehicles) that have been added to this space and not yet removed.Access parameters used by the contact-and-constraint solver.Return the type of contact-and-constraint solver in use.Enumerate physics vehicles that have been added to the space and not yet removed.protected static intgetWorldType(long spaceId) Determine the type of the underlying btDynamicsWorld.protected voidInitialize the solverInfo field during create().booleanTest whether CCD checks for collisions with static and kinematic bodies (native field: m_ccdWithStaticOnly).booleanisEmpty()Test whether the space is empty.booleanTest whether the space uses Speculative Contact Restitution (native field: m_applySpeculativeContactRestitution).long[]Enumerate the native IDs of all collision manifolds in the space.intReturn the maximum number of simulation steps per frame.floatReturn the maximum time step (imposed when maxSubSteps=0).voidonContactEnded(long manifoldId) Invoked by native code immediately after a contact manifold is destroyed.voidonContactProcessed(PhysicsCollisionObject pcoA, PhysicsCollisionObject pcoB, long pointId) Invoked by native code immediately after a contact point is refreshed without being destroyed.voidonContactStarted(long manifoldId) Invoked by native code immediately after a contact manifold is created.voidRemove the specified object from the space.voidRemove the specified collision object from the space.voidremoveJoint(PhysicsJoint joint) Remove the specified PhysicsJoint from the space.voidremoveTickListener(PhysicsTickListener listener) De-register the specified tick listener.voidsetAccuracy(float accuracy) Alter the accuracy (time step used when maxSubSteps>0).voidsetCcdWithStaticOnly(boolean setting) Alter whether CCD checks for collisions with static and kinematic bodies (native field: m_ccdWithStaticOnly).voidsetGravity(Vector3f gravity) Alter the gravitational acceleration acting on newly-added bodies.voidsetMaxSubSteps(int steps) Alter the maximum number of simulation steps per frame.voidsetMaxTimeStep(float maxTimeStep) Alter the maximum time step (imposed when maxSubSteps=0).voidupdate(float timeInterval) Update the space.voidupdate(float timeInterval, int maxSteps) Update the space.voidupdate(float timeInterval, int maxSteps, boolean doEnded, boolean doProcessed, boolean doStarted) Update the space.protected voidReplace the existing contact-and-constraint solver with a new one of the correct type.voiduseScr(boolean setting) Alter whether the space uses Speculative Contact Restitution (native field: m_applySpeculativeContactRestitution).Methods inherited from class com.jme3.bullet.CollisionSpacecontactTest, countCollisionObjects, countSolvers, getBroadphaseType, getCollisionSpace, getConfiguration, getGhostObjectList, getRayTestFlags, getWorldMax, getWorldMin, hasClosest, hasContact, initThread, isForceUpdateAllAabbs, isUsingDeterministicDispatch, jniEnvId, needsCollision, pairTest, rayTest, rayTest, rayTestDp, rayTestRaw, rayTestRaw, setForceUpdateAllAabbs, setLocalThreadPhysicsSpace, setRayTestFlags, sweepTest, useDeterministicDispatchMethods inherited from class com.jme3.bullet.NativePhysicsObjectcompareTo, countTrackers, dumpTrackers, equals, freeUnusedObjects, hasAssignedNativeObject, hashCode, nativeId, reassignNativeId, setNativeId, setNativeIdNotTracked, toString, unassignNativeObject
- 
Field Details- 
AXIS_Xpublic static final int AXIS_Xindex of the X axis- See Also:
 
- 
AXIS_Ypublic static final int AXIS_Yindex of the Y axis- See Also:
 
- 
AXIS_Zpublic static final int AXIS_Zindex of the Z axis- See Also:
 
- 
loggermessage logger for this class
 
- 
- 
Constructor Details- 
PhysicsSpaceInstantiate a PhysicsSpace with sequential-impulse solvers. Must be invoked on the designated physics thread.- Parameters:
- broadphaseType- which broadphase accelerator to use (not null)
 
- 
PhysicsSpaceInstantiate a PhysicsSpace with an AXIS_SWEEP_3 broadphase accelerator and sequential-impulse solvers. Must be invoked on the designated physics thread.- Parameters:
- worldMin- the desired minimum coordinate values (not null, unaffected)
- worldMax- the desired maximum coordinate values (not null, unaffected)
 
- 
PhysicsSpacepublic PhysicsSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType) Instantiate a PhysicsSpace with sequential-impulse solvers. Must be invoked on the designated physics thread.- Parameters:
- worldMin- the desired minimum coordinate values (not null, unaffected, default=(-10k,-10k,-10k))
- worldMax- the desired maximum coordinate values (not null, unaffected, default=(10k,10k,10k))
- broadphaseType- which broadphase accelerator to use (not null)
 
- 
PhysicsSpacepublic PhysicsSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType, int numSolvers) Instantiate a PhysicsSpace with the specified number of sequential-impulse solvers. Must be invoked on the designated physics thread.- Parameters:
- worldMin- the desired minimum coordinate values (not null, unaffected, default=(-10k,-10k,-10k))
- worldMax- the desired maximum coordinate values (not null, unaffected, default=(10k,10k,10k))
- broadphaseType- which broadphase accelerator to use (not null)
- numSolvers- the desired number of solvers in the thread-safe pool (≥1, ≤64, default=numThreads)
 
- 
PhysicsSpacepublic PhysicsSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType, int numSolvers, CollisionConfiguration configuration) Instantiate a PhysicsSpace with the specified number of sequential-impulse solvers. Must be invoked on the designated physics thread.- Parameters:
- worldMin- the desired minimum coordinate values (not null, unaffected, default=(-10k,-10k,-10k))
- worldMax- the desired maximum coordinate values (not null, unaffected, default=(10k,10k,10k))
- broadphaseType- which broadphase accelerator to use (not null)
- numSolvers- the desired number of solvers in the thread-safe pool (≥1, ≤64, default=numThreads)
- configuration- the desired configuration (not null)
 
- 
PhysicsSpacepublic PhysicsSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType, SolverType solverType) Instantiate a PhysicsSpace with the specified contact-and-constraint solver. Must be invoked on the designated physics thread.- Parameters:
- worldMin- the desired minimum coordinate values (not null, unaffected, default=(-10k,-10k,-10k))
- worldMax- the desired maximum coordinate values (not null, unaffected, default=(10k,10k,10k))
- broadphaseType- which broadphase accelerator to use (not null)
- solverType- the desired contact-and-constraint solver (not null)
 
- 
PhysicsSpacepublic PhysicsSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType, SolverType solverType, CollisionConfiguration configuration) Instantiate a PhysicsSpace with the specified contact-and-constraint solver. Must be invoked on the designated physics thread.- Parameters:
- worldMin- the desired minimum coordinate values (not null, unaffected, default=(-10k,-10k,-10k))
- worldMax- the desired maximum coordinate values (not null, unaffected, default=(10k,10k,10k))
- broadphaseType- which broadphase accelerator to use (not null)
- solverType- the desired contact-and-constraint solver (not null)
- configuration- the desired configuration (not null)
 
 
- 
- 
Method Details- 
activateAllpublic void activateAll(boolean forceFlag) Activate all rigid bodies in the space.- Parameters:
- forceFlag- true to force activation
 
- 
addJointAdd the specified PhysicsJoint to the space.- Parameters:
- joint- the joint to add (not null, alias created)
 
- 
addTickListenerRegister the specified tick listener with the space.Tick listeners are notified before and after each simulation step. A simulation step is not necessarily the same as a frame; it is more influenced by the accuracy of the PhysicsSpace. - Parameters:
- listener- the listener to register (not null, alias created)
- See Also:
 
- 
containsTest whether the specified PhysicsJoint is added to the space.- Parameters:
- joint- the joint to test (not null, unaffected)
- Returns:
- true if currently added, otherwise false
 
- 
countJointspublic int countJoints()Count the joints in the space.- Returns:
- the count (≥0)
 
- 
countManifoldspublic int countManifolds()Count the collision manifolds in the space.- Returns:
- the current number of btPersistentManifolds (≥0)
 
- 
countRigidBodiespublic int countRigidBodies()Count the rigid bodies in the space, including vehicles.- Returns:
- count (≥0)
 
- 
countTickListenerspublic int countTickListeners()Count how many tick listeners are registered with the space.- Returns:
- the count (≥0)
 
- 
getAccuracypublic float getAccuracy()Return the simulation accuracy: the time step used when maxSubSteps>0.- Returns:
- the time step (in seconds, >0)
 
- 
getCharacterListEnumerate physics characters that have been added to the space and not yet removed.- Returns:
- a new unmodifiable collection of pre-existing instances (not null)
 
- 
getGravityCopy the gravitational acceleration for newly-added bodies.- Parameters:
- storeResult- storage for the result (modified if not null)
- Returns:
- the acceleration vector (in physics-space coordinates, either storeResult or a new instance, not null)
 
- 
getJointListEnumerate physics joints that have been added to the space and not yet removed.- Returns:
- a new unmodifiable collection of pre-existing instances (not null)
 
- 
getPhysicsSpaceAccess the PhysicsSpace running on this thread. For parallel physics, this may be invoked from the OpenGL thread.- Returns:
- the pre-existing PhysicsSpace running on this thread
 
- 
getRigidBodyListEnumerate rigid bodies (including vehicles) that have been added to this space and not yet removed.- Returns:
- a new unmodifiable collection of pre-existing instances (not null)
 
- 
getSolverInfoAccess parameters used by the contact-and-constraint solver.- Returns:
- the pre-existing instance (not null)
 
- 
getSolverTypeReturn the type of contact-and-constraint solver in use.- Returns:
- an enum value (not null)
 
- 
getVehicleListEnumerate physics vehicles that have been added to the space and not yet removed.- Returns:
- a new unmodifiable collection of pre-existing instances (not null)
 
- 
isCcdWithStaticOnlypublic boolean isCcdWithStaticOnly()Test whether CCD checks for collisions with static and kinematic bodies (native field: m_ccdWithStaticOnly).- Returns:
- true if checks are limited, false if checking also for collisions with dynamic bodies
 
- 
isUsingScrpublic boolean isUsingScr()Test whether the space uses Speculative Contact Restitution (native field: m_applySpeculativeContactRestitution).- Returns:
- true if using SCR, otherwise false
 
- 
listManifoldIdspublic long[] listManifoldIds()Enumerate the native IDs of all collision manifolds in the space.- Returns:
- a new array (not null, may be empty)
- See Also:
 
- 
maxSubStepspublic int maxSubSteps()Return the maximum number of simulation steps per frame.- Returns:
- the number of steps (>1) or 0 for a variable time step
 
- 
maxTimeSteppublic float maxTimeStep()Return the maximum time step (imposed when maxSubSteps=0).- Returns:
- the maximum time step (in seconds, >0, default=0.1)
 
- 
removeJointRemove the specified PhysicsJoint from the space.- Parameters:
- joint- the joint to remove (not null)
 
- 
removeTickListenerDe-register the specified tick listener.- Parameters:
- listener- the listener to de-register (not null, unaffected)
- See Also:
 
- 
setAccuracypublic void setAccuracy(float accuracy) Alter the accuracy (time step used when maxSubSteps>0).In general, the smaller the time step, the more accurate (and compute-intensive) the simulation will be. - Parameters:
- accuracy- the desired time step (in seconds, >0, default=1/60)
 
- 
setCcdWithStaticOnlypublic void setCcdWithStaticOnly(boolean setting) Alter whether CCD checks for collisions with static and kinematic bodies (native field: m_ccdWithStaticOnly).- Parameters:
- setting- true to limit checking, false to check also for collisions with dynamic bodies (default=false)
 
- 
setGravityAlter the gravitational acceleration acting on newly-added bodies.Typically, when a body is added to a space, the body's gravity gets set to that of the space. Thus, it is preferable to set the space's gravity before adding any bodies. - Parameters:
- gravity- the desired acceleration vector (in physics-space coordinates, not null, unaffected, default=(0,-9.81,0))
 
- 
setMaxSubStepspublic void setMaxSubSteps(int steps) Alter the maximum number of simulation steps per frame.Extra simulation steps help maintain determinism when the render fps drops below 1/accuracy. For example a value of 2 can compensate for frame rates as low as 30fps, assuming the physics has an accuracy of 1/60 sec. Setting this value too high can depress the frame rate. - Parameters:
- steps- the desired maximum number of steps (≥1) or 0 for a variable time step (default=4)
 
- 
setMaxTimeSteppublic void setMaxTimeStep(float maxTimeStep) Alter the maximum time step (imposed when maxSubSteps=0).In general, the smaller the time step, the more accurate (and compute-intensive) the simulation will be. - Parameters:
- maxTimeStep- the desired maximum time step (in seconds, >0, default=0.1)
 
- 
updatepublic void update(float timeInterval) Update the space. Can be used to single-step the physics simulation, if maxSubSteps is set to 0 or 1. This method should be invoked on the thread that created the space.- Parameters:
- timeInterval- the time interval to simulate (in seconds, ≥0)
- See Also:
 
- 
updatepublic void update(float timeInterval, int maxSteps) Update the space. This method should be invoked on the thread that created the space.- Parameters:
- timeInterval- the time interval to simulate (in seconds, ≥0)
- maxSteps- the maximum number of steps of size- accuracy(≥1) or 0 for a single step of size- timeInterval
 
- 
updatepublic void update(float timeInterval, int maxSteps, boolean doEnded, boolean doProcessed, boolean doStarted) Update the space. This method should be invoked from the thread that created the space.- Parameters:
- timeInterval- the time interval to simulate (in seconds, ≥0)
- maxSteps- the maximum number of steps of size- accuracy(≥1) or 0 for a single step of size- timeInterval
- doEnded- true to enable- onContactEnded()callbacks, false to skip them
- doProcessed- true to enable- onContactProcessed()callbacks, false to skip them
- doStarted- true to enable- onContactStarted()callbacks, false to skip them
 
- 
useScrpublic void useScr(boolean setting) Alter whether the space uses Speculative Contact Restitution (native field: m_applySpeculativeContactRestitution).- Parameters:
- setting- true to enable SCR, false to disable it (default=false)
 
- 
getJointMapAccess the map from native IDs to physics joints.- Returns:
- the pre-existing instance (not null)
 
- 
getWorldTypeprotected static int getWorldType(long spaceId) Determine the type of the underlying btDynamicsWorld.- Parameters:
- spaceId- the Bullet identifier of the space (non-zero)
- Returns:
- 2 (for a discrete world) or 4 (for a soft-rigid world)
 
- 
initSolverInfoprotected void initSolverInfo()Initialize the solverInfo field during create().
- 
updateSolverprotected void updateSolver()Replace the existing contact-and-constraint solver with a new one of the correct type.
- 
addAdd the specified object to the space.- Overrides:
- addin class- CollisionSpace
- Parameters:
- object- the collision object or PhysicsJoint to add (not null)
 
- 
addCollisionObjectAdd the specified collision object to the space.- Overrides:
- addCollisionObjectin class- CollisionSpace
- Parameters:
- pco- the collision object to add (not null)
 
- 
containsTest whether the specified collision object is added to the space.- Overrides:
- containsin class- CollisionSpace
- Parameters:
- pco- the object to test (not null, unaffected)
- Returns:
- true if currently added, otherwise false
 
- 
createprotected void create()Must be invoked on the designated physics thread.- Overrides:
- createin class- CollisionSpace
 
- 
destroypublic void destroy()Remove all collision objects and physics joints.- Overrides:
- destroyin class- CollisionSpace
 
- 
getPcoListEnumerate collision objects that have been added to the space and not yet removed.- Overrides:
- getPcoListin class- CollisionSpace
- Returns:
- a new modifiable collection of pre-existing instances (not null)
 
- 
isEmptypublic boolean isEmpty()Test whether the space is empty.- Overrides:
- isEmptyin class- CollisionSpace
- Returns:
- true if empty, otherwise false
 
- 
removeRemove the specified object from the space.- Overrides:
- removein class- CollisionSpace
- Parameters:
- object- the collision object or PhysicsJoint to remove, or null
 
- 
removeCollisionObjectRemove the specified collision object from the space.- Overrides:
- removeCollisionObjectin class- CollisionSpace
- Parameters:
- pco- the collision object to remove (not null)
 
- 
onContactEndedpublic void onContactEnded(long manifoldId) Invoked by native code immediately after a contact manifold is destroyed. Skipped if stepSimulation() was invoked with doEnded=false.Override this method to customize how contacts are handled. - Specified by:
- onContactEndedin interface- ContactListener
- Parameters:
- manifoldId- the native ID of the- btPersistentManifold(not zero)
 
- 
onContactProcessedpublic void onContactProcessed(PhysicsCollisionObject pcoA, PhysicsCollisionObject pcoB, long pointId) Invoked by native code immediately after a contact point is refreshed without being destroyed. Skipped for Sphere-Sphere contacts. Skipped if stepSimulation() was invoked with doProcessed=false.Override this method to customize how contacts are handled. - Specified by:
- onContactProcessedin interface- ContactListener
- Parameters:
- pcoA- the first involved object (not null)
- pcoB- the 2nd involved object (not null)
- pointId- the native ID of the- btManifoldPoint(not zero)
 
- 
onContactStartedpublic void onContactStarted(long manifoldId) Invoked by native code immediately after a contact manifold is created. Skipped if stepSimulation() was invoked with doStarted=false.Override this method to customize how contacts are handled. - Specified by:
- onContactStartedin interface- ContactListener
- Parameters:
- manifoldId- the native ID of the- btPersistentManifold(not zero)
 
 
-