Class BulletAppState

java.lang.Object
com.jme3.app.state.AbstractAppState
com.jme3.bullet.BulletAppState
All Implemented Interfaces:
com.jme3.app.state.AppState, PhysicsTickListener
Direct Known Subclasses:
MultiBodyAppState, SoftPhysicsAppState

public class BulletAppState extends com.jme3.app.state.AbstractAppState implements PhysicsTickListener
An AppState to manage a single PhysicsSpace.
  • Field Details

    • logger

      public static final Logger logger
      message logger for this class
  • Constructor Details

    • BulletAppState

      public BulletAppState()
      Instantiate an enabled app state to manage a new space with the DBVT broadphase collision-detection algorithm.

      Use getStateManager().addState(bulletAppState) to start simulating physics.

    • BulletAppState

      public BulletAppState(PhysicsSpace.BroadphaseType broadphaseType)
      Instantiate an enabled app state to manage a new PhysicsSpace.

      Use getStateManager().addState(bulletAppState) to start simulating physics.

      Parameters:
      broadphaseType - which broadphase collision-detection algorithm to use (not null)
    • BulletAppState

      public BulletAppState(com.jme3.math.Vector3f worldMin, com.jme3.math.Vector3f worldMax)
      Instantiate an enabled app state to manage a new space with the AXIS_SWEEP_3 broadphase collision-detection algorithm.

      Use getStateManager().addState(bulletAppState) to start simulating physics.

      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)
    • BulletAppState

      public BulletAppState(com.jme3.math.Vector3f worldMin, com.jme3.math.Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType)
      Instantiate an enabled AppState to manage a new space.

      Use getStateManager().addState(bulletAppState) to start simulating physics.

      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 collision-detection algorithm to use (not null)
  • Method Details

    • countSolvers

      public int countSolvers()
      Count the solvers in the thread-safe pool.
      Returns:
      the count
    • debugAxisLength

      public float debugAxisLength()
      Determine the length of the debug axis arrows.
      Returns:
      length (in physics-space units, ≥0)
    • debugAxisLineWidth

      public float debugAxisLineWidth()
      Determine the line width of the debug axis arrows.
      Returns:
      width (in pixels, ≥1) or 0 for solid arrows
    • getBroadphaseType

      public PhysicsSpace.BroadphaseType getBroadphaseType()
      Determine which broadphase collision-detection algorithm the PhysicsSpace will use.
      Returns:
      enum value (not null)
    • getCollisionConfiguration

      public CollisionConfiguration getCollisionConfiguration()
      Return the collision configuration that will be used to instantiate the PhysicsSpace.
      Returns:
      the pre-existing instance (not null)
    • getDebugCamera

      public com.jme3.renderer.Camera getDebugCamera()
      Access the Camera used for debug visualization.
      Returns:
      the pre-existing instance, or null if unknown
    • getPhysicsSpace

      public PhysicsSpace getPhysicsSpace()
      Access the PhysicsSpace managed by this state. Normally there is none until the state is attached.
      Returns:
      the pre-existing instance, or null if no simulation running
    • getSolverType

      public SolverType getSolverType()
      Determine which constraint solver the PhysicsSpace will use.
      Returns:
      the enum value (not null)
    • getSpeed

      public float getSpeed()
      Return the physics-simulation speed.
      Returns:
      the speedup factor (≥0, default=1, 0→paused)
    • getThreadingType

      public BulletAppState.ThreadingType getThreadingType()
      Determine which type of threading this app state uses.
      Returns:
      the threadingType (not null)
    • isDebugEnabled

      public boolean isDebugEnabled()
      Test whether debug visualization is enabled.
      Returns:
      true if enabled, otherwise false
    • isRunning

      public boolean isRunning()
      Test whether the physics simulation is running (started but not yet stopped).
      Returns:
      true if running, otherwise false
    • setBroadphaseType

      public void setBroadphaseType(PhysicsSpace.BroadphaseType broadphaseType)
      Alter the broadphase type the PhysicsSpace will use. Not allowed after attaching the app state.
      Parameters:
      broadphaseType - an enum value (not null, default=DBVT)
    • setCollisionConfiguration

      public void setCollisionConfiguration(CollisionConfiguration configuration)
      Replace the collision configuration that will be used to instantiate the PhysicsSpace. Not allowed after attaching the app state.
      Parameters:
      configuration - the desired configuration (not null)
    • setDebugAngularVelocityFilter

      public void setDebugAngularVelocityFilter(BulletDebugAppState.DebugAppStateFilter filter)
      Alter which angular velocities are included in the debug visualization.
      Parameters:
      filter - the filter to use (alias created) or null to visualize no angular velocities (default=null)
    • setDebugAxisLength

      public void setDebugAxisLength(float length)
      Alter the length of the debug axis arrows.
      Parameters:
      length - the desired length (in physics-space units, ≥0)
    • setDebugAxisLineWidth

      public void setDebugAxisLineWidth(float width)
      Alter the line width for debug axis arrows.
      Parameters:
      width - the desired width (in pixels, ≥1) or 0 for solid arrows (default=1)
    • setDebugBoundingBoxFilter

      public void setDebugBoundingBoxFilter(BulletDebugAppState.DebugAppStateFilter filter)
      Alter which bounding boxes are included in the debug visualization.
      Parameters:
      filter - the filter to use (alias created) or null to visualize no bounding boxes (default=null)
    • setDebugCamera

      public void setDebugCamera(com.jme3.renderer.Camera camera)
      Replace the Camera used for debug visualization.
      Parameters:
      camera - the Camera to use (alias created) or null for unknown (defaults to the application's main camera)
    • setDebugEnabled

      public void setDebugEnabled(boolean debugEnabled)
      Enable or disable debug visualization. Changes take effect on the next update.
      Parameters:
      debugEnabled - true → enable, false → disable (default=false)
    • setDebugFilter

      public void setDebugFilter(BulletDebugAppState.DebugAppStateFilter filter)
      Alter which objects are included in the debug visualization.
      Parameters:
      filter - the filter to use (alias created) or null to visualize all objects (default=null)
    • setDebugGravityVectorFilter

      public void setDebugGravityVectorFilter(BulletDebugAppState.DebugAppStateFilter filter)
      Alter which gravity vectors are included in the debug visualization.
      Parameters:
      filter - the filter to use (alias created) or null to visualize no gravity vectors (default=null)
    • setDebugInitListener

      public void setDebugInitListener(DebugInitListener listener)
      Replace or remove the init listener for the BulletDebugAppState.
      Parameters:
      listener - the listener to register, or null to de-register the current listener (default=null)
    • setDebugJointLineWidth

      public void setDebugJointLineWidth(float width)
      Alter the line width for PhysicsJoint debug arrows.
      Parameters:
      width - (in pixels, ≥1, default=1)
    • setDebugShadowMode

      public void setDebugShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode mode)
      Alter the shadow mode of the debug root node.
      Parameters:
      mode - the desired value (not null, default=Off)
    • setDebugSweptSphereFilter

      public void setDebugSweptSphereFilter(BulletDebugAppState.DebugAppStateFilter filter)
      Alter which swept spheres are included in the debug visualization.
      Parameters:
      filter - the filter to use (alias created) or null to visualize no swept spheres (default=null)
    • setDebugVelocityVectorFilter

      public void setDebugVelocityVectorFilter(BulletDebugAppState.DebugAppStateFilter filter)
      Alter which velocity vectors are included in the debug visualization.
      Parameters:
      filter - the filter to use (alias created) or null to visualize no velocity vectors (default=null)
    • setDebugViewPorts

      public void setDebugViewPorts(com.jme3.renderer.ViewPort... viewPorts)
      Alter which view ports will render the debug visualization.
      Parameters:
      viewPorts - (not null, aliases created)
    • setNumSolvers

      public void setNumSolvers(int numSolvers)
      Alter the number of solvers in the thread-safe pool.
      Parameters:
      numSolvers - the desired number of solvers in the thread-safe pool (≥1, ≤64, default=numThreads)
    • setSolverType

      public void setSolverType(SolverType solver)
      Alter which constraint solver the PhysicsSpace will use. Not allowed after attaching the AppState.
      Parameters:
      solver - an enum value (not null, default=SI)
    • setSpeed

      public void setSpeed(float speed)
      Alter the physics simulation speed.
      Parameters:
      speed - the desired speedup factor (≥0, default=1, 0→paused)
    • setThreadingType

      public void setThreadingType(BulletAppState.ThreadingType threadingType)
      Alter which type of threading this app state uses. Not allowed after attaching the app state.
      Parameters:
      threadingType - the desired type (not null, default=SEQUENTIAL)
    • setTransformSpatial

      public void setTransformSpatial(com.jme3.scene.Spatial spatial)
      Alter the conversion from physics-space coordinates to world coordinates.
      Parameters:
      spatial - the Spatial to use for coordinate transformations (alias created) or null for physics=world (default=null)
    • setWorldMax

      public void setWorldMax(com.jme3.math.Vector3f worldMax)
      Alter the coordinate range. Not allowed after attaching the app state.
      Parameters:
      worldMax - the desired maximum coordinate values when using AXIS_SWEEP broadphase algorithms (not null, unaffected, default=(10k,10k,10k))
    • setWorldMin

      public void setWorldMin(com.jme3.math.Vector3f worldMin)
      Alter the coordinate range. Not allowed after attaching the app state.
      Parameters:
      worldMin - the desired minimum coordinate values when using AXIS_SWEEP broadphase algorithms (not null, unaffected, default=(-10k,-10k,-10k))
    • startPhysics

      public void startPhysics()
      Allocate a PhysicsSpace and start simulating physics.

      Simulation starts automatically after the state is attached. To start it sooner, invoke this method.

    • stopPhysics

      public void stopPhysics()
      Stop physics after this state is detached.
    • worldMax

      public com.jme3.math.Vector3f worldMax()
      Copy the maximum coordinate values for AXIS_SWEEP.
      Returns:
      a new location vector (in physics-space coordinates, not null)
    • worldMin

      public com.jme3.math.Vector3f worldMin()
      Copy the minimum coordinate values for AXIS_SWEEP.
      Returns:
      a new location vector (in physics-space coordinates, not null)
    • createDebugAppState

      protected BulletDebugAppState createDebugAppState()
      Create the configured debug-visualization app state.
      Returns:
      a new instance (not null)
    • createPhysicsSpace

      protected PhysicsSpace createPhysicsSpace(com.jme3.math.Vector3f min, com.jme3.math.Vector3f max, PhysicsSpace.BroadphaseType type)
      Create the configured PhysicsSpace.
      Parameters:
      min - the minimum coordinate values (not null, unaffected)
      max - the maximum coordinate values (not null, unaffected)
      type - the broadphase collision-detection algorithm (not null)
      Returns:
      a new instance (not null)
    • getDebugAppState

      protected BulletDebugAppState getDebugAppState()
      Access the AppState to manage the debug visualization.
      Returns:
      the pre-existing instance, or null if none
    • getDebugConfiguration

      protected DebugConfiguration getDebugConfiguration()
      Access the configuration for debug visualization.
      Returns:
      the pre-existing instance (not null)
    • setPhysicsSpace

      protected void setPhysicsSpace(PhysicsSpace newSpace)
      Alter which PhysicsSpace is managed by this state.
      Parameters:
      newSpace - the space to be managed (may be null)
    • setRunning

      protected void setRunning(boolean desiredSetting)
      Alter whether the physics simulation is running (started but not yet stopped).
      Parameters:
      desiredSetting - true→running, false→not running
    • startPhysicsOnExecutor

      protected boolean startPhysicsOnExecutor()
      Allocate the PhysicsSpace and start simulating physics using ThreadingType.PARALLEL.
      Returns:
      true if successful, otherwise false
    • cleanup

      public void cleanup()
      Transition this state from terminating to detached. Should be invoked only by a subclass or by the AppStateManager.

      Invoked once for each time initialize(com.jme3.app.state.AppStateManager, com.jme3.app.Application) is invoked.

      Specified by:
      cleanup in interface com.jme3.app.state.AppState
      Overrides:
      cleanup in class com.jme3.app.state.AbstractAppState
    • initialize

      public void initialize(com.jme3.app.state.AppStateManager stateManager, com.jme3.app.Application app)
      Initialize this state prior to its first update. Should be invoked only by a subclass or by the AppStateManager.
      Specified by:
      initialize in interface com.jme3.app.state.AppState
      Overrides:
      initialize in class com.jme3.app.state.AbstractAppState
      Parameters:
      stateManager - the manager for this state (not null)
      app - the application which owns this state (not null)
    • postRender

      public void postRender()
      Update this state after all rendering commands are flushed. Should be invoked only by a subclass or by the AppStateManager. Invoked once per frame, provided the state is attached and enabled.
      Specified by:
      postRender in interface com.jme3.app.state.AppState
      Overrides:
      postRender in class com.jme3.app.state.AbstractAppState
    • render

      public void render(com.jme3.renderer.RenderManager rm)
      Render this state. Should be invoked only by a subclass or by the AppStateManager. Invoked once per frame, provided the state is attached and enabled.
      Specified by:
      render in interface com.jme3.app.state.AppState
      Overrides:
      render in class com.jme3.app.state.AbstractAppState
      Parameters:
      rm - the render manager (not null)
    • stateAttached

      public void stateAttached(com.jme3.app.state.AppStateManager stateManager)
      Transition this state from detached to initializing. Should be invoked only by a subclass or by the AppStateManager.
      Specified by:
      stateAttached in interface com.jme3.app.state.AppState
      Overrides:
      stateAttached in class com.jme3.app.state.AbstractAppState
      Parameters:
      stateManager - the manager instance (not null)
    • update

      public void update(float tpf)
      Update this state prior to rendering. Should be invoked only by a subclass or by the AppStateManager. Invoked once per frame, provided the state is attached and enabled.
      Specified by:
      update in interface com.jme3.app.state.AppState
      Overrides:
      update in class com.jme3.app.state.AbstractAppState
      Parameters:
      tpf - the time interval between frames (in seconds, ≥0)
    • physicsTick

      public void physicsTick(PhysicsSpace space, float timeStep)
      Callback invoked just after the physics has been stepped. A good time to clear/apply forces. Meant to be overridden.
      Specified by:
      physicsTick in interface PhysicsTickListener
      Parameters:
      space - the space that was just stepped (not null)
      timeStep - the duration of the simulation step (in seconds, ≥0)
    • prePhysicsTick

      public void prePhysicsTick(PhysicsSpace space, float timeStep)
      Callback invoked just before the physics is stepped. A good time to clear/apply forces. Meant to be overridden.
      Specified by:
      prePhysicsTick in interface PhysicsTickListener
      Parameters:
      space - the space that's about to be stepped (not null)
      timeStep - the duration of the simulation step (in seconds, ≥0)