Package com.jme3.bullet
Class CollisionSpace
java.lang.Object
com.jme3.bullet.NativePhysicsObject
com.jme3.bullet.CollisionSpace
- All Implemented Interfaces:
Comparable<NativePhysicsObject>
- Direct Known Subclasses:
PhysicsSpace
A Bullet-JME collision space with its own
btCollisionWorld
.-
Field Summary
Fields inherited from class com.jme3.bullet.NativePhysicsObject
loggerN
-
Constructor Summary
ModifierConstructorDescriptionCollisionSpace
(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType) Instantiate a CollisionSpace.protected
CollisionSpace
(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType, int numSolvers) Used internally.protected
CollisionSpace
(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType, int numSolvers, CollisionConfiguration configuration) Used internally. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add the specified object to the space.void
Add the specified collision object to the space.int
contactTest
(PhysicsCollisionObject pco, PhysicsCollisionListener listener) Perform a contact test.boolean
Test whether the specified collision object is added to the space.int
Count the collision objects in the space.int
Count the worker threads.protected void
create()
Must be invoked on the designated physics thread.void
destroy()
Remove all collision objects and physics joints.Return the type of acceleration structure used for broadphase collision detection.static CollisionSpace
Access the CollisionSpace associated with the current thread.Access the tuning parameters.Enumerate ghost objects that have been added to the space and not yet removed.Enumerate collision objects that have been added to the space and not yet removed.int
Return the flags used in ray tests (native field: m_flags).getWorldMax
(Vector3f storeResult) Copy the maximum coordinate values for the space.getWorldMin
(Vector3f storeResult) Copy the minimum coordinate values for the space.boolean
hasClosest
(CollisionShape shape0, CollisionShape shape1) Test whether a nontrivial closest-points algorithm is registered for the specified collision shapes.boolean
hasContact
(CollisionShape shape0, CollisionShape shape1) Test whether a nontrivial contact-points algorithm is registered for the specified collision shapes.protected void
initThread
(long spaceId) Must be invoked on the designated physics thread.boolean
isEmpty()
Test whether the space is empty.boolean
Test whether the bounding boxes of inactive collision objects should be recomputed during eachupdate()
(native field: m_forceUpdateAllAabbs).boolean
Test whether the "deterministic overlapping pairs" option is enabled in the collision dispatcher (native field: m_deterministicOverlappingPairs).long
jniEnvId()
Return the address of the JNIEnv that the space uses for callbacks.boolean
Callback to determine whether the specified objects should be allowed to collide.int
pairTest
(PhysicsCollisionObject pcoA, PhysicsCollisionObject pcoB, PhysicsCollisionListener listener) Perform a pair test.Perform a ray-collision test (raycast) and sort the results by ascending hitFraction.rayTest
(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results) Perform a ray-collision test (raycast) and sort the results by ascending hitFraction.rayTestDp
(Vec3d from, Vec3d to, List<PhysicsRayTestResult> results) Perform a ray-collision test (raycast) and sort the results by ascending hitFraction.rayTestRaw
(Vector3f from, Vector3f to) Perform a ray-collision test (raycast) and return the results in arbitrary order.rayTestRaw
(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results) Perform a ray-collision test (raycast) and return the results in arbitrary order.void
Remove the specified object from the space.void
Remove the specified collision object from the space.void
setForceUpdateAllAabbs
(boolean desiredSetting) Alter whether the bounding boxes of inactive collision objects should be recomputed during eachupdate()
(native field: m_forceUpdateAllAabbs).static void
Alter the CollisionSpace associated with this thread.void
setRayTestFlags
(int flags) Alter the flags used in ray tests (native field: m_flags).sweepTest
(ConvexShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results, float allowedCcdPenetration) Perform a sweep-collision test and store the results in an existing list, in arbitrary order.void
useDeterministicDispatch
(boolean desiredSetting) Enable or disable the "deterministic overlapping pairs" option in the collision dispatcher (native field: m_deterministicOverlappingPairs).Methods inherited from class com.jme3.bullet.NativePhysicsObject
compareTo, countTrackers, dumpTrackers, equals, freeUnusedObjects, hasAssignedNativeObject, hashCode, nativeId, reassignNativeId, setNativeId, setNativeIdNotTracked, toString, unassignNativeObject
-
Field Details
-
loggerC
message logger for this class
-
-
Constructor Details
-
CollisionSpace
public CollisionSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType) Instantiate a CollisionSpace. 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)
-
CollisionSpace
protected CollisionSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType, int numSolvers) Used internally.- 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 number of contact-and-constraint solvers in the thread-safe pool (≥1, ≤64, default=1)
-
CollisionSpace
protected CollisionSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType, int numSolvers, CollisionConfiguration configuration) Used internally.- 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 number of contact-and-constraint solvers in the thread-safe pool (≥1, ≤64, default=1)configuration
- the desired configuration (not null)
-
-
Method Details
-
add
Add the specified object to the space.- Parameters:
object
- the object to add (not null)
-
addCollisionObject
Add the specified collision object to the space.- Parameters:
pco
- the collision object to add (not null, modified)
-
contactTest
Perform a contact test. This will not detect contacts with soft bodies.- Parameters:
pco
- the collision object to test (not null, unaffected)listener
- the callback for reporting contacts (may be null)- Returns:
- the number of times the listener was invoked, or would have been if it weren't null (≥0)
-
contains
Test whether the specified collision object is added to the space.- Parameters:
pco
- the object to test (not null, unaffected)- Returns:
- true if currently added, otherwise false
-
countCollisionObjects
public int countCollisionObjects()Count the collision objects in the space.- Returns:
- the count (≥0)
-
countSolvers
public int countSolvers()Count the worker threads.- Returns:
- the count (≥1, ≤64)
-
destroy
public void destroy()Remove all collision objects and physics joints. Meant to be overridden. -
getBroadphaseType
Return the type of acceleration structure used for broadphase collision detection.- Returns:
- an enum value (not null)
-
getCollisionSpace
Access the CollisionSpace associated with the current thread.- Returns:
- the pre-existing CollisionSpace, or
null
if none
-
getConfiguration
Access the tuning parameters.- Returns:
- the pre-existing instance (not null)
-
getGhostObjectList
Enumerate ghost objects that have been added to the space and not yet removed.- Returns:
- a new unmodifiable collection of pre-existing instances (not null)
-
getPcoList
Enumerate collision objects that have been added to the space and not yet removed.- Returns:
- a new modifiable collection of pre-existing instances (not null)
-
getRayTestFlags
public int getRayTestFlags()Return the flags used in ray tests (native field: m_flags).- Returns:
- which flags are used
- See Also:
-
getWorldMax
Copy the maximum coordinate values for the space.- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- the maximum coordinates (either storeResult or a new vector, not null)
-
getWorldMin
Copy the minimum coordinate values for the space.- Parameters:
storeResult
- storage for the result (modified if not null)- Returns:
- the minimum coordinates (either storeResult or a new vector, not null)
-
hasClosest
Test whether a nontrivial closest-points algorithm is registered for the specified collision shapes.- Parameters:
shape0
- the first shape to test (not null, unaffected)shape1
- the 2nd shape to test (not null, unaffected)- Returns:
- true if registered, otherwise false
-
hasContact
Test whether a nontrivial contact-points algorithm is registered for the specified collision shapes.- Parameters:
shape0
- the first shape to test (not null, unaffected)shape1
- the 2nd shape to test (not null, unaffected)- Returns:
- true if registered, otherwise false
-
isEmpty
public boolean isEmpty()Test whether the space is empty.- Returns:
- true if empty, otherwise false
-
isForceUpdateAllAabbs
public boolean isForceUpdateAllAabbs()Test whether the bounding boxes of inactive collision objects should be recomputed during eachupdate()
(native field: m_forceUpdateAllAabbs).- Returns:
- true to recompute all AABBs, false to skip inactive objects
-
isUsingDeterministicDispatch
public boolean isUsingDeterministicDispatch()Test whether the "deterministic overlapping pairs" option is enabled in the collision dispatcher (native field: m_deterministicOverlappingPairs).- Returns:
- true if using sorted/deterministic order, otherwise false
-
jniEnvId
public long jniEnvId()Return the address of the JNIEnv that the space uses for callbacks. For debugging and testing.- Returns:
- the virtual address of the (native) object (not zero)
-
needsCollision
Callback to determine whether the specified objects should be allowed to collide. Invoked during broadphase, after axis-aligned bounding boxes, ignore lists, and collision groups have been checked. Override this method to implement dynamic collision filtering.- Parameters:
pcoA
- the first collision object (not null)pcoB
- the 2nd collision object (not null)- Returns:
- true to simulate collisions between pcoA and pcoB, false to ignore such collisions during this simulation step
-
pairTest
public int pairTest(PhysicsCollisionObject pcoA, PhysicsCollisionObject pcoB, PhysicsCollisionListener listener) Perform a pair test. The collision objects need not be added to the space.- Parameters:
pcoA
- the first collision object to test (not null, unaffected)pcoB
- the 2nd collision object to test (not null, unaffected)listener
- the callback for reporting contacts (may be null)- Returns:
- the number of times the listener was invoked, or would have been if it weren't null (≥0)
-
rayTest
Perform a ray-collision test (raycast) and sort the results by ascending hitFraction.- Parameters:
from
- the starting location (physics-space coordinates, not null, unaffected)to
- the ending location (in physics-space coordinates, not null, unaffected)- Returns:
- a new list of sorted results (not null)
-
rayTest
public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results) Perform a ray-collision test (raycast) and sort the results by ascending hitFraction.- Parameters:
from
- the starting location (in physics-space coordinates, not null, unaffected)to
- the ending location (in physics-space coordinates, not null, unaffected)results
- the list to hold results (not null, modified)- Returns:
- results (sorted)
-
rayTestDp
public List<PhysicsRayTestResult> rayTestDp(Vec3d from, Vec3d to, List<PhysicsRayTestResult> results) Perform a ray-collision test (raycast) and sort the results by ascending hitFraction.- Parameters:
from
- the starting location (in physics-space coordinates, not null, unaffected)to
- the ending location (in physics-space coordinates, not null, unaffected)results
- the list to hold results (not null, modified)- Returns:
- results (sorted)
-
rayTestRaw
Perform a ray-collision test (raycast) and return the results in arbitrary order.- Parameters:
from
- the starting location (in physics-space coordinates, not null, unaffected)to
- the ending location (in physics-space coordinates, not null, unaffected)- Returns:
- a new list of unsorted results (not null)
-
rayTestRaw
public List<PhysicsRayTestResult> rayTestRaw(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results) Perform a ray-collision test (raycast) and return the results in arbitrary order.- Parameters:
from
- the starting location (in physics-space coordinates, not null, unaffected)to
- the ending location (in physics-space coordinates, not null, unaffected)results
- the list to hold results (not null, modified)- Returns:
- results (unsorted)
-
remove
Remove the specified object from the space.- Parameters:
object
- the object to remove, or null
-
removeCollisionObject
Remove the specified collision object from the space.- Parameters:
pco
- the collision object to remove (not null, modified)
-
setForceUpdateAllAabbs
public void setForceUpdateAllAabbs(boolean desiredSetting) Alter whether the bounding boxes of inactive collision objects should be recomputed during eachupdate()
(native field: m_forceUpdateAllAabbs).- Parameters:
desiredSetting
- true → recompute all AABBs, false → skip inactive objects (default=true)
-
setLocalThreadPhysicsSpace
Alter the CollisionSpace associated with this thread.- Parameters:
space
- which space to associate with the current thread, ornull
for none
-
setRayTestFlags
public void setRayTestFlags(int flags) Alter the flags used in ray tests (native field: m_flags).- Parameters:
flags
- the desired flags, ORed together (default=SubSimplexRaytest)- See Also:
-
sweepTest
public List<PhysicsSweepTestResult> sweepTest(ConvexShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results, float allowedCcdPenetration) Perform a sweep-collision test and store the results in an existing list, in arbitrary order.The starting and ending locations must be at least 0.4 physics-space units apart.
A sweep test will miss a collision if it starts inside an object and sweeps away from the object's center. Also, sweep tests do not detect soft bodies.
- Parameters:
shape
- the shape to sweep (not null, convex, unaffected)start
- the starting physics-space transform (not null, unaffected)end
- the ending physics-space transform (not null, unaffected)results
- the list to hold results (not null, modified)allowedCcdPenetration
- (in physics-space units)- Returns:
- results
-
useDeterministicDispatch
public void useDeterministicDispatch(boolean desiredSetting) Enable or disable the "deterministic overlapping pairs" option in the collision dispatcher (native field: m_deterministicOverlappingPairs).- Parameters:
desiredSetting
- true → sorted/deterministic order, false → hashed/arbitrary order (default=false)
-
create
protected void create()Must be invoked on the designated physics thread. -
initThread
protected void initThread(long spaceId) Must be invoked on the designated physics thread.- Parameters:
spaceId
- the Bullet identifier for the space (non-zero)
-