public class BulletAppState extends AbstractAppState implements PhysicsTickListener
This class is shared between JBullet and Native Bullet.
Modifier and Type | Class and Description |
---|---|
static class |
BulletAppState.ThreadingType
Enumerate threading modes.
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
active
true if-and-only-if this state is enabled
|
protected Application |
app |
protected PhysicsSpace.BroadphaseType |
broadphaseType
broadphase collision-detection algorithm for the physics space to use
(not null)
|
protected BulletDebugAppState |
debugAppState
app state to manage the debug visualization, or null if none
|
protected boolean |
debugEnabled
true if-and-only-if debug visualization is enabled
|
protected java.util.concurrent.ScheduledThreadPoolExecutor |
executor
executor service for physics tasks, or null if parallel simulation is not
running
|
protected boolean |
isRunning
true if-and-only-if the physics simulation is running (started but not
yet stopped)
|
protected java.util.concurrent.Future |
physicsFuture
current physics task, or null if none
|
protected PhysicsSpace |
pSpace
physics space managed by this state, or null if no simulation running
|
protected float |
speed
simulation speed multiplier (default=1, paused=0)
|
protected AppStateManager |
stateManager
manager that manages this state, set during attach
|
protected BulletAppState.ThreadingType |
threadingType
threading mode to use (not null)
|
protected float |
tpf
time interval between frames (in seconds) from the most recent update
|
protected Vector3f |
worldMax
maximum coordinate values for the physics space when using AXIS_SWEEP
broadphase algorithms (not null)
|
protected Vector3f |
worldMin
minimum coordinate values for the physics space when using AXIS_SWEEP
broadphase algorithms (not null)
|
initialized
Constructor and Description |
---|
BulletAppState()
Instantiate 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.
|
Modifier and Type | Method and Description |
---|---|
void |
cleanup()
Transition this state from terminating to detached.
|
PhysicsSpace |
getPhysicsSpace()
Access the PhysicsSpace managed by this state.
|
float |
getSpeed()
Read the simulation speed.
|
BulletAppState.ThreadingType |
getThreadingType()
Read which type of threading this app state uses.
|
void |
initialize(AppStateManager stateManager,
Application app)
Initialize this state prior to its 1st update.
|
boolean |
isDebugEnabled()
Test whether debug visualization is enabled.
|
void |
physicsTick(PhysicsSpace space,
float f)
Callback from Bullet, invoked just after the physics is stepped.
|
void |
postRender()
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 |
startPhysics()
Allocate a physics space and start physics.
|
void |
stateAttached(AppStateManager stateManager)
Transition this state from detached to initializing.
|
void |
stopPhysics()
Stop physics after this state is detached.
|
void |
update(float tpf)
Update this state prior to rendering.
|
getId, isEnabled, isInitialized, setEnabled, setId, stateDetached
protected volatile boolean isRunning
protected Application app
protected AppStateManager stateManager
protected java.util.concurrent.ScheduledThreadPoolExecutor executor
protected PhysicsSpace pSpace
protected BulletAppState.ThreadingType threadingType
protected PhysicsSpace.BroadphaseType broadphaseType
protected Vector3f worldMin
protected Vector3f worldMax
protected float speed
protected boolean active
protected boolean debugEnabled
protected BulletDebugAppState debugAppState
protected float tpf
protected java.util.concurrent.Future physicsFuture
public BulletAppState()
Use getStateManager().addState(bulletAppState) to start physics.
public BulletAppState(PhysicsSpace.BroadphaseType broadphaseType)
Use getStateManager().addState(bulletAppState) to start physics.
broadphaseType
- which broadphase collision-detection algorithm to
use (not null)public BulletAppState(Vector3f worldMin, Vector3f worldMax)
Use getStateManager().addState(bulletAppState) to start physics.
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)public BulletAppState(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType)
Use getStateManager().addState(bulletAppState) to enable physics.
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)public PhysicsSpace getPhysicsSpace()
public void startPhysics()
Physics starts automatically after the state is attached. To start it sooner, invoke this method.
public void stopPhysics()
public void initialize(AppStateManager stateManager, Application app)
initialize
in interface AppState
initialize
in class AbstractAppState
stateManager
- the manager for this state (not null)app
- the application which owns this state (not null)public void setDebugEnabled(boolean debugEnabled)
debugEnabled
- true → enable, false → disablepublic boolean isDebugEnabled()
public void stateAttached(AppStateManager stateManager)
stateAttached
in interface AppState
stateAttached
in class AbstractAppState
stateManager
- (not null)public void update(float tpf)
update
in interface AppState
update
in class AbstractAppState
tpf
- the time interval between frames (in seconds, ≥0)public void render(RenderManager rm)
render
in interface AppState
render
in class AbstractAppState
rm
- the render manager (not null)public void postRender()
postRender
in interface AppState
postRender
in class AbstractAppState
public void cleanup()
initialize(com.jme3.app.state.AppStateManager, com.jme3.app.Application)
is invoked.cleanup
in interface AppState
cleanup
in class AbstractAppState
public BulletAppState.ThreadingType getThreadingType()
public void setThreadingType(BulletAppState.ThreadingType threadingType)
threadingType
- the desired type (not null, default=SEQUENTIAL)public void setBroadphaseType(PhysicsSpace.BroadphaseType broadphaseType)
broadphaseType
- an enum value (not null, default=DBVT)public void setWorldMin(Vector3f worldMin)
worldMin
- the desired minimum coordinate values when using
AXIS_SWEEP broadphase algorithms (not null, alias created,
default=-10k,-10k,-10k)public void setWorldMax(Vector3f worldMax)
worldMax
- the desired maximum coordinate values when using
AXIS_SWEEP broadphase algorithms (not null, alias created,
default=10k,10k,10k)public float getSpeed()
public void setSpeed(float speed)
speed
- the desired speed (≥0, default=1)public void prePhysicsTick(PhysicsSpace space, float f)
prePhysicsTick
in interface PhysicsTickListener
space
- the space that is about to be stepped (not null)f
- the time per physics step (in seconds, ≥0)public void physicsTick(PhysicsSpace space, float f)
physicsTick
in interface PhysicsTickListener
space
- the space that is about to be stepped (not null)f
- the time per physics step (in seconds, ≥0)