Class BulletAppState

java.lang.Object
com.jme3.app.state.AbstractAppState
com.jme3.bullet.BulletAppState
All Implemented Interfaces:
com.jme3.app.state.AppState, PhysicsTickListener

public class BulletAppState extends com.jme3.app.state.AbstractAppState implements PhysicsTickListener
An app state to manage a single Bullet physics space.

This class is shared between JBullet and Native Bullet.

Author:
normenhansen
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Enumerate threading modes.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    true if-and-only-if this state is enabled
    protected com.jme3.app.Application
     
    broadphase collision-detection algorithm for the physics space to use (not null)
    app state to manage the debug visualization, or null if none
    protected boolean
    true if-and-only-if debug visualization is enabled
    executor service for physics tasks, or null if parallel simulation is not running
    protected boolean
    true if-and-only-if the physics simulation is running (started but not yet stopped)
    protected Future
    current physics task, or null if none
    protected PhysicsSpace
    physics space managed by this state, or null if no simulation running
    protected float
    simulation speed multiplier (default=1, paused=0)
    protected com.jme3.app.state.AppStateManager
    manager that manages this state, set during attach
    threading mode to use (not null)
    protected float
    time interval between frames (in seconds) from the most recent update
    protected com.jme3.math.Vector3f
    maximum coordinate values for the physics space when using AXIS_SWEEP broadphase algorithms (not null)
    protected com.jme3.math.Vector3f
    minimum coordinate values for the physics space when using AXIS_SWEEP broadphase algorithms (not null)

    Fields inherited from class com.jme3.app.state.AbstractAppState

    initialized
  • Constructor Summary

    Constructors
    Constructor
    Description
    Instantiate an app state to manage a new PhysicsSpace with DBVT collision detection.
    Instantiate an app state to manage a new PhysicsSpace.
    BulletAppState(com.jme3.math.Vector3f worldMin, com.jme3.math.Vector3f worldMax)
    Instantiate an app state to manage a new PhysicsSpace with AXIS_SWEEP_3 collision detection.
    BulletAppState(com.jme3.math.Vector3f worldMin, com.jme3.math.Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType)
    Instantiate an app state to manage a new PhysicsSpace.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Transition this state from terminating to detached.
    Access the PhysicsSpace managed by this state.
    float
    Read the simulation speed.
    Read which type of threading this app state uses.
    void
    initialize(com.jme3.app.state.AppStateManager stateManager, com.jme3.app.Application app)
    Initialize this state prior to its 1st update.
    boolean
    Test whether debug visualization is enabled.
    void
    physicsTick(PhysicsSpace space, float f)
    Callback from Bullet, invoked just after the physics is stepped.
    void
    Update this state after all rendering commands are flushed.
    void
    prePhysicsTick(PhysicsSpace space, float f)
    Callback from Bullet, invoked just before the physics is stepped.
    void
    render(com.jme3.renderer.RenderManager rm)
    Render this state.
    void
    Alter the broadphase type the physics space will use.
    void
    setDebugEnabled(boolean debugEnabled)
    Alter whether debug visualization is enabled.
    void
    setSpeed(float speed)
    Alter the simulation speed.
    void
    Alter which type of threading this app state uses.
    void
    setWorldMax(com.jme3.math.Vector3f worldMax)
    Alter the coordinate range.
    void
    setWorldMin(com.jme3.math.Vector3f worldMin)
    Alter the coordinate range.
    void
    Allocate a physics space and start physics.
    void
    stateAttached(com.jme3.app.state.AppStateManager stateManager)
    Transition this state from detached to initializing.
    void
    Stop physics after this state is detached.
    void
    update(float tpf)
    Update this state prior to rendering.

    Methods inherited from class com.jme3.app.state.AbstractAppState

    getId, isEnabled, isInitialized, setEnabled, setId, stateDetached

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • isRunning

      protected volatile boolean isRunning
      true if-and-only-if the physics simulation is running (started but not yet stopped)
    • app

      protected com.jme3.app.Application app
    • stateManager

      protected com.jme3.app.state.AppStateManager stateManager
      manager that manages this state, set during attach
    • executor

      protected ScheduledThreadPoolExecutor executor
      executor service for physics tasks, or null if parallel simulation is not running
    • pSpace

      protected PhysicsSpace pSpace
      physics space managed by this state, or null if no simulation running
    • threadingType

      protected BulletAppState.ThreadingType threadingType
      threading mode to use (not null)
    • broadphaseType

      protected PhysicsSpace.BroadphaseType broadphaseType
      broadphase collision-detection algorithm for the physics space to use (not null)
    • worldMin

      protected com.jme3.math.Vector3f worldMin
      minimum coordinate values for the physics space when using AXIS_SWEEP broadphase algorithms (not null)
    • worldMax

      protected com.jme3.math.Vector3f worldMax
      maximum coordinate values for the physics space when using AXIS_SWEEP broadphase algorithms (not null)
    • speed

      protected float speed
      simulation speed multiplier (default=1, paused=0)
    • active

      protected boolean active
      true if-and-only-if this state is enabled
    • debugEnabled

      protected boolean debugEnabled
      true if-and-only-if debug visualization is enabled
    • debugAppState

      protected BulletDebugAppState debugAppState
      app state to manage the debug visualization, or null if none
    • tpf

      protected float tpf
      time interval between frames (in seconds) from the most recent update
    • physicsFuture

      protected Future physicsFuture
      current physics task, or null if none
  • Constructor Details

    • BulletAppState

      public BulletAppState()
      Instantiate an app state to manage a new PhysicsSpace with DBVT collision detection.

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

    • BulletAppState

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

      Use getStateManager().addState(bulletAppState) to start 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 app state to manage a new PhysicsSpace with AXIS_SWEEP_3 collision detection.

      Use getStateManager().addState(bulletAppState) to start 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 app state to manage a new PhysicsSpace.

      Use getStateManager().addState(bulletAppState) to enable 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

    • 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
    • startPhysics

      public void startPhysics()
      Allocate a physics space and start physics.

      Physics 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.
    • initialize

      public void initialize(com.jme3.app.state.AppStateManager stateManager, com.jme3.app.Application app)
      Initialize this state prior to its 1st 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)
    • setDebugEnabled

      public void setDebugEnabled(boolean debugEnabled)
      Alter whether debug visualization is enabled.
      Parameters:
      debugEnabled - true → enable, false → disable
    • isDebugEnabled

      public boolean isDebugEnabled()
      Test whether debug visualization is enabled.
      Returns:
      true if enabled, otherwise false
    • 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 - (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)
    • 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)
    • 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
    • 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
    • getThreadingType

      public BulletAppState.ThreadingType getThreadingType()
      Read which type of threading this app state uses.
      Returns:
      the threadingType (not null)
    • 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)
    • setBroadphaseType

      public void setBroadphaseType(PhysicsSpace.BroadphaseType broadphaseType)
      Alter the broadphase type the physics space will use. Not allowed after attaching the app state.
      Parameters:
      broadphaseType - an enum value (not null, default=DBVT)
    • 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, alias created, default=-10k,-10k,-10k)
    • 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, alias created, default=10k,10k,10k)
    • getSpeed

      public float getSpeed()
      Read the simulation speed.
      Returns:
      speed (≥0, default=1)
    • setSpeed

      public void setSpeed(float speed)
      Alter the simulation speed.
      Parameters:
      speed - the desired speed (≥0, default=1)
    • prePhysicsTick

      public void prePhysicsTick(PhysicsSpace space, float f)
      Callback from Bullet, invoked just before the physics is stepped. A good time to clear/apply forces.
      Specified by:
      prePhysicsTick in interface PhysicsTickListener
      Parameters:
      space - the space that is about to be stepped (not null)
      f - the time per physics step (in seconds, ≥0)
    • physicsTick

      public void physicsTick(PhysicsSpace space, float f)
      Callback from Bullet, invoked just after the physics is stepped. A good time to clear/apply forces.
      Specified by:
      physicsTick in interface PhysicsTickListener
      Parameters:
      space - the space that is about to be stepped (not null)
      f - the time per physics step (in seconds, ≥0)