Class PhysicsSpace

java.lang.Object
com.jme3.bullet.PhysicsSpace

public class PhysicsSpace extends Object

PhysicsSpace - The central jbullet-jme physics space

  • Field Details

  • Constructor Details

  • Method Details

    • getPhysicsSpace

      public static PhysicsSpace getPhysicsSpace()
      Get the current PhysicsSpace running on this thread
      For parallel physics, this can also be called from the OpenGL thread to receive the PhysicsSpace
      Returns:
      the PhysicsSpace running on this thread
    • setLocalThreadPhysicsSpace

      public static void setLocalThreadPhysicsSpace(PhysicsSpace space)
      Used internally
      Parameters:
      space - which space to simulate on the current thread
    • create

      public void create()
      Has to be called from the (designated) physics thread
    • update

      public void update(float time)
      updates the physics space
      Parameters:
      time - the current time value
    • update

      public void update(float time, int maxSteps)
      updates the physics space, uses maxSteps
      Parameters:
      time - the current time value
      maxSteps - the maximum number of steps of size accuracy (≥1) or 0 for a single step of size timeInterval
    • distributeEvents

      public void distributeEvents()
    • enqueueOnThisThread

      public static <V> Future<V> enqueueOnThisThread(Callable<V> callable)
    • enqueue

      public <V> Future<V> enqueue(Callable<V> callable)
      calls the callable on the next physics tick (ensuring e.g. force applying)
      Type Parameters:
      V - the return type of the Callable
      Parameters:
      callable - the Callable to invoke
      Returns:
      a new AppTask
    • add

      public void add(Object obj)
      adds an object to the physics space
      Parameters:
      obj - the PhysicsControl or Spatial with PhysicsControl to add
    • addCollisionObject

      public void addCollisionObject(PhysicsCollisionObject obj)
    • remove

      public void remove(Object obj)
      removes an object from the physics space
      Parameters:
      obj - the PhysicsControl or Spatial with PhysicsControl to remove
    • removeCollisionObject

      public void removeCollisionObject(PhysicsCollisionObject obj)
    • addAll

      public void addAll(Spatial spatial)
      adds all physics controls and joints in the given spatial node to the physics space (e.g. after loading from disk) - recursive if node
      Parameters:
      spatial - the rootnode containing the physics objects
    • removeAll

      public void removeAll(Spatial spatial)
      Removes all physics controls and joints in the given spatial from the physics space (e.g. before saving to disk) - recursive if node
      Parameters:
      spatial - the rootnode containing the physics objects
    • getRigidBodyList

      public Collection<PhysicsRigidBody> getRigidBodyList()
    • getGhostObjectList

      public Collection<PhysicsGhostObject> getGhostObjectList()
    • getCharacterList

      public Collection<PhysicsCharacter> getCharacterList()
    • getJointList

      public Collection<PhysicsJoint> getJointList()
    • getVehicleList

      public Collection<PhysicsVehicle> getVehicleList()
    • setGravity

      public void setGravity(Vector3f gravity)
      Sets the gravity of the PhysicsSpace, set before adding physics objects!
      Parameters:
      gravity - the desired acceleration vector (in physics-space coordinates, not null, unaffected, default=0,-10,0)
    • getGravity

      public Vector3f getGravity(Vector3f gravity)
      Gets the gravity of the PhysicsSpace
      Parameters:
      gravity - storage for the result (modified if not null)
      Returns:
      the acceleration vector (in physics-space coordinates, either gravity or a new instance)
    • applyGravity

      public void applyGravity()
      applies gravity value to all objects
    • clearForces

      public void clearForces()
      clears forces of all objects
    • addTickListener

      public void addTickListener(PhysicsTickListener listener)
      Adds the specified listener to the physics tick listeners. The listeners are called on each physics step, which is not necessarily each frame but is determined by the accuracy of the physics space.
      Parameters:
      listener - the listener to register (not null, alias created)
    • removeTickListener

      public void removeTickListener(PhysicsTickListener listener)
    • addCollisionListener

      public void addCollisionListener(PhysicsCollisionListener listener)
      Adds a CollisionListener that will be informed about collision events
      Parameters:
      listener - the CollisionListener to add
    • removeCollisionListener

      public void removeCollisionListener(PhysicsCollisionListener listener)
      Removes a CollisionListener from the list
      Parameters:
      listener - the CollisionListener to remove
    • addCollisionGroupListener

      public void addCollisionGroupListener(PhysicsCollisionGroupListener listener, int collisionGroup)
      Adds a listener for a specific collision group, such a listener can disable collisions when they happen.
      There can be only one listener per collision group.
      Parameters:
      listener - the listener to register (not null, alias created)
      collisionGroup - which group it should listen for (bitmask with exactly one bit set)
    • removeCollisionGroupListener

      public void removeCollisionGroupListener(int collisionGroup)
    • rayTest

      public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to)
      Performs a ray collision test and returns the results as a list of PhysicsRayTestResults
      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 results (not null)
    • rayTest

      public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results)
      Performs a ray collision test and returns the results as a list of PhysicsRayTestResults
      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
    • sweepTest

      public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end)
      Performs a sweep collision test and returns the results as a list of PhysicsSweepTestResults
      You have to use different Transforms for start and end (at least distance greater than 0.4f). SweepTest will not see a collision if it starts INSIDE an object and is moving AWAY from its center.
      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(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results)
      Performs a sweep collision test and returns the results as a list of PhysicsSweepTestResults
      You have to use different Transforms for start and end (at least distance greater than 0.4f). SweepTest will not see a collision if it starts INSIDE an object and is moving AWAY from its center.
      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
    • destroy

      public void destroy()
      destroys the current PhysicsSpace so that a new one can be created
    • getDynamicsWorld

      public com.bulletphysics.dynamics.DynamicsWorld getDynamicsWorld()
      used internally
      Returns:
      the dynamicsWorld
    • getBroadphaseType

      public PhysicsSpace.BroadphaseType getBroadphaseType()
    • setBroadphaseType

      public void setBroadphaseType(PhysicsSpace.BroadphaseType broadphaseType)
    • setMaxSubSteps

      public void setMaxSubSteps(int steps)
      Sets the maximum amount of extra steps that will be used to step the physics when the fps is below the physics fps. Doing this maintains determinism in physics. For example a maximum number of 2 can compensate for frame rates as low as 30fps when the physics has the default accuracy of 60 fps. Note that setting this value too high can make the physics drive down its own fps in case it's overloaded.
      Parameters:
      steps - The maximum number of extra steps, default is 4.
    • getAccuracy

      public float getAccuracy()
      get the current accuracy of the physics computation
      Returns:
      the current accuracy
    • setAccuracy

      public void setAccuracy(float accuracy)
      sets the accuracy of the physics computation, default=1/60s
      Parameters:
      accuracy - the desired time step (in seconds, default=1/60)
    • getWorldMin

      public Vector3f getWorldMin()
    • setWorldMin

      public void setWorldMin(Vector3f worldMin)
      only applies for AXIS_SWEEP broadphase
      Parameters:
      worldMin - the desired minimum coordinates values (not null, unaffected, default=-10k,-10k,-10k)
    • getWorldMax

      public Vector3f getWorldMax()
    • setWorldMax

      public void setWorldMax(Vector3f worldMax)
      only applies for AXIS_SWEEP broadphase
      Parameters:
      worldMax - the desired maximum coordinates values (not null, unaffected, default=10k,10k,10k)
    • setSolverNumIterations

      public void setSolverNumIterations(int numIterations)
      Set the number of iterations used by the contact solver. The default is 10. Use 4 for low quality, 20 for high quality.
      Parameters:
      numIterations - The number of iterations used by the contact and constraint solver.
    • getSolverNumIterations

      public int getSolverNumIterations()