Package com.jme3.bullet
Class BulletAppState
java.lang.Object
com.jme3.app.state.AbstractAppState
com.jme3.bullet.BulletAppState
- All Implemented Interfaces:
AppState
,PhysicsTickListener
An app state to manage a single Bullet physics space.
This class is shared between JBullet and Native Bullet.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumerate threading modes. -
Field Summary
Modifier and TypeFieldDescriptionprotected boolean
true if-and-only-if this state is enabledprotected Application
protected PhysicsSpace.BroadphaseType
broadphase collision-detection algorithm for the physics space to use (not null)protected BulletDebugAppState
app state to manage the debug visualization, or null if noneprotected boolean
true if-and-only-if debug visualization is enabledprotected ScheduledThreadPoolExecutor
executor service for physics tasks, or null if parallel simulation is not runningprotected boolean
true if-and-only-if the physics simulation is running (started but not yet stopped)protected Future
current physics task, or null if noneprotected PhysicsSpace
physics space managed by this state, or null if no simulation runningprotected float
simulation speed multiplier (default=1, paused=0)protected AppStateManager
manager that manages this state, set during attachprotected BulletAppState.ThreadingType
threading mode to use (not null)protected float
time interval between frames (in seconds) from the most recent updateprotected Vector3f
maximum coordinate values for the physics space when using AXIS_SWEEP broadphase algorithms (not null)protected 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
ConstructorDescriptionInstantiate an app state to manage a new PhysicsSpace with DBVT collision detection.BulletAppState
(PhysicsSpace.BroadphaseType broadphaseType) Instantiate an app state to manage a new PhysicsSpace.BulletAppState
(Vector3f worldMin, Vector3f worldMax) Instantiate an app state to manage a new PhysicsSpace with AXIS_SWEEP_3 collision detection.BulletAppState
(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType) Instantiate an app state to manage a new PhysicsSpace. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanup()
Transition this state from terminating to detached.Access the PhysicsSpace managed by this state.float
getSpeed()
Read the simulation speed.Read which type of threading this app state uses.void
initialize
(AppStateManager stateManager, 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
(RenderManager rm) Render this state.void
setBroadphaseType
(PhysicsSpace.BroadphaseType broadphaseType) 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
setThreadingType
(BulletAppState.ThreadingType threadingType) Alter which type of threading this app state uses.void
setWorldMax
(Vector3f worldMax) Alter the coordinate range.void
setWorldMin
(Vector3f worldMin) Alter the coordinate range.void
Allocate a physics space and start physics.void
stateAttached
(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
-
Field Details
-
isRunning
protected volatile boolean isRunningtrue if-and-only-if the physics simulation is running (started but not yet stopped) -
app
-
stateManager
manager that manages this state, set during attach -
executor
executor service for physics tasks, or null if parallel simulation is not running -
pSpace
physics space managed by this state, or null if no simulation running -
threadingType
threading mode to use (not null) -
broadphaseType
broadphase collision-detection algorithm for the physics space to use (not null) -
worldMin
minimum coordinate values for the physics space when using AXIS_SWEEP broadphase algorithms (not null) -
worldMax
maximum coordinate values for the physics space when using AXIS_SWEEP broadphase algorithms (not null) -
speed
protected float speedsimulation speed multiplier (default=1, paused=0) -
active
protected boolean activetrue if-and-only-if this state is enabled -
debugEnabled
protected boolean debugEnabledtrue if-and-only-if debug visualization is enabled -
debugAppState
app state to manage the debug visualization, or null if none -
tpf
protected float tpftime interval between frames (in seconds) from the most recent update -
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
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
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(Vector3f worldMin, 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
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
Initialize this state prior to its 1st update. Should be invoked only by a subclass or by the AppStateManager.- Specified by:
initialize
in interfaceAppState
- Overrides:
initialize
in classAbstractAppState
- 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
Transition this state from detached to initializing. Should be invoked only by a subclass or by the AppStateManager.- Specified by:
stateAttached
in interfaceAppState
- Overrides:
stateAttached
in classAbstractAppState
- 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 interfaceAppState
- Overrides:
update
in classAbstractAppState
- Parameters:
tpf
- the time interval between frames (in seconds, ≥0)
-
render
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 interfaceAppState
- Overrides:
render
in classAbstractAppState
- 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 interfaceAppState
- Overrides:
postRender
in classAbstractAppState
-
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 timeinitialize(com.jme3.app.state.AppStateManager, com.jme3.app.Application)
is invoked.- Specified by:
cleanup
in interfaceAppState
- Overrides:
cleanup
in classAbstractAppState
-
getThreadingType
Read which type of threading this app state uses.- Returns:
- the threadingType (not null)
-
setThreadingType
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
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
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
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
Callback from Bullet, invoked just before the physics is stepped. A good time to clear/apply forces.- Specified by:
prePhysicsTick
in interfacePhysicsTickListener
- Parameters:
space
- the space that is about to be stepped (not null)f
- the time per physics step (in seconds, ≥0)
-
physicsTick
Callback from Bullet, invoked just after the physics is stepped. A good time to clear/apply forces.- Specified by:
physicsTick
in interfacePhysicsTickListener
- Parameters:
space
- the space that is about to be stepped (not null)f
- the time per physics step (in seconds, ≥0)
-