Class CollisionSpace

All Implemented Interfaces:
Comparable<NativePhysicsObject>
Direct Known Subclasses:
PhysicsSpace

public class CollisionSpace extends NativePhysicsObject
A Bullet-JME collision space with its own btCollisionWorld.
  • Field Details

    • loggerC

      public static final Logger 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

      public void add(Object object)
      Add the specified object to the space.
      Parameters:
      object - the object to add (not null)
    • addCollisionObject

      public void addCollisionObject(PhysicsCollisionObject pco)
      Add the specified collision object to the space.
      Parameters:
      pco - the collision object to add (not null, modified)
    • contactTest

      public int contactTest(PhysicsCollisionObject pco, PhysicsCollisionListener listener)
      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

      public boolean contains(PhysicsCollisionObject pco)
      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

      public PhysicsSpace.BroadphaseType getBroadphaseType()
      Return the type of acceleration structure used for broadphase collision detection.
      Returns:
      an enum value (not null)
    • getCollisionSpace

      public static CollisionSpace getCollisionSpace()
      Access the CollisionSpace associated with the current thread.
      Returns:
      the pre-existing CollisionSpace, or null if none
    • getConfiguration

      public CollisionConfiguration getConfiguration()
      Access the tuning parameters.
      Returns:
      the pre-existing instance (not null)
    • getGhostObjectList

      public Collection<PhysicsGhostObject> 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

      public Collection<PhysicsCollisionObject> 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

      public Vector3f getWorldMax(Vector3f storeResult)
      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

      public Vector3f getWorldMin(Vector3f storeResult)
      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

      public boolean hasClosest(CollisionShape shape0, CollisionShape shape1)
      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

      public boolean hasContact(CollisionShape shape0, CollisionShape shape1)
      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 each update() (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

      public boolean needsCollision(PhysicsCollisionObject pcoA, PhysicsCollisionObject pcoB)
      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

      public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to)
      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

      public List<PhysicsRayTestResult> rayTestRaw(Vector3f from, Vector3f to)
      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

      public void remove(Object object)
      Remove the specified object from the space.
      Parameters:
      object - the object to remove, or null
    • removeCollisionObject

      public void removeCollisionObject(PhysicsCollisionObject pco)
      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 each update() (native field: m_forceUpdateAllAabbs).
      Parameters:
      desiredSetting - true → recompute all AABBs, false → skip inactive objects (default=true)
    • setLocalThreadPhysicsSpace

      public static void setLocalThreadPhysicsSpace(CollisionSpace space)
      Alter the CollisionSpace associated with this thread.
      Parameters:
      space - which space to associate with the current thread, or null 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)