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(com.jme3.math.Vector3f worldMin, com.jme3.math.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(com.jme3.math.Vector3f worldMin, com.jme3.math.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(com.jme3.math.Vector3f worldMin, com.jme3.math.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 this space.
      Parameters:
      object - the collision object to add (not null)
    • addCollisionGroupListener

      public void addCollisionGroupListener(PhysicsCollisionGroupListener listener, int collisionGroup)
      Register the specified collision-group listener with the specified collision group of this space. For compatibility with the jme3-jbullet library.

      Such a listener can disable collisions when they occur. There can be only one listener per collision group per space.

      Parameters:
      listener - the listener to register (not null, alias created)
      collisionGroup - which group it should listen for (bitmask with exactly one bit set)
    • addCollisionObject

      public void addCollisionObject(PhysicsCollisionObject pco)
      Add the specified collision object to this 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 this space.
      Parameters:
      pco - the object to test (not null, unaffected)
      Returns:
      true if currently added, otherwise false
    • countCollisionGroupListeners

      public int countCollisionGroupListeners()
      Count how many collision-group listeners are registered with this space.
      Returns:
      the count (≥0)
    • countCollisionObjects

      public int countCollisionObjects()
      Count the collision objects in this space.
      Returns:
      the count (≥0)
    • countSolvers

      public int countSolvers()
      Count the solvers.
      Returns:
      the count (≥1, ≤64)
    • destroy

      public void destroy()
      Remove all collision objects and physics joints.
    • getBroadphaseType

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

      public static CollisionSpace getCollisionSpace()
      Access the CollisionSpace running on this thread. For parallel physics, this may be invoked from the OpenGL thread.
      Returns:
      the pre-existing CollisionSpace running on this thread
    • 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 this 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 this 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 com.jme3.math.Vector3f getWorldMax(com.jme3.math.Vector3f storeResult)
      Copy the maximum coordinate values for this 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 com.jme3.math.Vector3f getWorldMin(com.jme3.math.Vector3f storeResult)
      Copy the minimum coordinate values for this 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 this 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 this 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(com.jme3.math.Vector3f from, com.jme3.math.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(com.jme3.math.Vector3f from, com.jme3.math.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(com.simsilica.mathd.Vec3d from, com.simsilica.mathd.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(com.jme3.math.Vector3f from, com.jme3.math.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(com.jme3.math.Vector3f from, com.jme3.math.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 this space.
      Parameters:
      object - the collision object to remove, or null
    • removeCollisionGroupListener

      public void removeCollisionGroupListener(int collisionGroup)
      De-register the specified collision-group listener. For compatibility with the jme3-jbullet library.
      Parameters:
      collisionGroup - the group of the listener to de-register (bitmask with exactly one bit set)
      See Also:
    • removeCollisionObject

      public void removeCollisionObject(PhysicsCollisionObject pco)
      Remove the specified collision object from this 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)
    • 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, com.jme3.math.Transform start, com.jme3.math.Transform end)
      For compatibility with the jme3-jbullet library.
      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)
      Returns:
      a new list of results
    • sweepTest

      public List<PhysicsSweepTestResult> sweepTest(ConvexShape shape, com.jme3.math.Transform start, com.jme3.math.Transform end, List<PhysicsSweepTestResult> results)
      For compatibility with the jme3-jbullet library.
      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)
      Returns:
      results
    • sweepTest

      public List<PhysicsSweepTestResult> sweepTest(ConvexShape shape, com.jme3.math.Transform start, com.jme3.math.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 this space (non-zero)