Package com.jme3.bullet
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumerate threading modes. -
Field Summary
Fields inherited from class com.jme3.app.state.AbstractAppState
initialized
-
Constructor Summary
ConstructorDescriptionInstantiate an enabled app state to manage a new space with the DBVT broadphase collision-detection algorithm.BulletAppState
(PhysicsSpace.BroadphaseType broadphaseType) Instantiate an enabled app state to manage a new PhysicsSpace.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.BulletAppState
(com.jme3.math.Vector3f worldMin, com.jme3.math.Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType) Instantiate an enabled AppState to manage a new space. -
Method Summary
Modifier and TypeMethodDescriptionvoid
cleanup()
Transition this state from terminating to detached.int
Count the solvers in the thread-safe pool.protected BulletDebugAppState
Create the configured debug-visualization app state.protected PhysicsSpace
createPhysicsSpace
(com.jme3.math.Vector3f min, com.jme3.math.Vector3f max, PhysicsSpace.BroadphaseType type) Create the configuredPhysicsSpace
.float
Determine the length of the debug axis arrows.float
Determine the line width of the debug axis arrows.Determine which broadphase collision-detection algorithm the PhysicsSpace will use.Return the collision configuration that will be used to instantiate the PhysicsSpace.protected BulletDebugAppState
Access the AppState to manage the debug visualization.com.jme3.renderer.Camera
Access the Camera used for debug visualization.protected DebugConfiguration
Access the configuration for debug visualization.Access the PhysicsSpace managed by this state.Determine which constraint solver the PhysicsSpace will use.float
getSpeed()
Return the physics-simulation speed.Determine 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 first update.boolean
Test whether debug visualization is enabled.boolean
Test whether the physics simulation is running (started but not yet stopped).void
physicsTick
(PhysicsSpace space, float timeStep) Callback invoked just after the physics has been stepped.void
Update this state after all rendering commands are flushed.void
prePhysicsTick
(PhysicsSpace space, float timeStep) Callback invoked just before the physics is stepped.void
render
(com.jme3.renderer.RenderManager rm) Render this state.void
setBroadphaseType
(PhysicsSpace.BroadphaseType broadphaseType) Alter the broadphase type the PhysicsSpace will use.void
setCollisionConfiguration
(CollisionConfiguration configuration) Replace the collision configuration that will be used to instantiate the PhysicsSpace.void
Alter which angular velocities are included in the debug visualization.void
setDebugAxisLength
(float length) Alter the length of the debug axis arrows.void
setDebugAxisLineWidth
(float width) Alter the line width for debug axis arrows.void
Alter which bounding boxes are included in the debug visualization.void
setDebugCamera
(com.jme3.renderer.Camera camera) Replace the Camera used for debug visualization.void
setDebugEnabled
(boolean debugEnabled) Enable or disable debug visualization.void
Alter which objects are included in the debug visualization.void
Alter which gravity vectors are included in the debug visualization.void
setDebugInitListener
(DebugInitListener listener) Replace or remove the init listener for the BulletDebugAppState.void
setDebugJointLineWidth
(float width) Alter the line width for PhysicsJoint debug arrows.void
setDebugShadowMode
(com.jme3.renderer.queue.RenderQueue.ShadowMode mode) Alter the shadow mode of the debug root node.void
Alter which swept spheres are included in the debug visualization.void
Alter which velocity vectors are included in the debug visualization.void
setDebugViewPorts
(com.jme3.renderer.ViewPort... viewPorts) Alter which view ports will render the debug visualization.void
setNumSolvers
(int numSolvers) Alter the number of solvers in the thread-safe pool.protected void
setPhysicsSpace
(PhysicsSpace newSpace) Alter which PhysicsSpace is managed by this state.protected void
setRunning
(boolean desiredSetting) Alter whether the physics simulation is running (started but not yet stopped).void
setSolverType
(SolverType solver) Alter which constraint solver the PhysicsSpace will use.void
setSpeed
(float speed) Alter the physics simulation speed.void
setThreadingType
(BulletAppState.ThreadingType threadingType) Alter which type of threading this app state uses.void
setTransformSpatial
(com.jme3.scene.Spatial spatial) Alter the conversion from physics-space coordinates to world coordinates.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 PhysicsSpace and start simulating physics.protected boolean
Allocate the PhysicsSpace and start simulating physics using ThreadingType.PARALLEL.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.com.jme3.math.Vector3f
worldMax()
Copy the maximum coordinate values for AXIS_SWEEP.com.jme3.math.Vector3f
worldMin()
Copy the minimum coordinate values for AXIS_SWEEP.Methods inherited from class com.jme3.app.state.AbstractAppState
getId, isEnabled, isInitialized, setEnabled, setId, stateDetached
-
Field Details
-
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
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
Determine which broadphase collision-detection algorithm the PhysicsSpace will use.- Returns:
- enum value (not null)
-
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 configuredPhysicsSpace
.- 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
Access the AppState to manage the debug visualization.- Returns:
- the pre-existing instance, or null if none
-
getDebugConfiguration
Access the configuration for debug visualization.- Returns:
- the pre-existing instance (not null)
-
setPhysicsSpace
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 interfacecom.jme3.app.state.AppState
- Overrides:
cleanup
in classcom.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 interfacecom.jme3.app.state.AppState
- Overrides:
initialize
in classcom.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 interfacecom.jme3.app.state.AppState
- Overrides:
postRender
in classcom.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 interfacecom.jme3.app.state.AppState
- Overrides:
render
in classcom.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 interfacecom.jme3.app.state.AppState
- Overrides:
stateAttached
in classcom.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 interfacecom.jme3.app.state.AppState
- Overrides:
update
in classcom.jme3.app.state.AbstractAppState
- Parameters:
tpf
- the time interval between frames (in seconds, ≥0)
-
physicsTick
Callback invoked just after the physics has been stepped. A good time to clear/apply forces. Meant to be overridden.- Specified by:
physicsTick
in interfacePhysicsTickListener
- Parameters:
space
- the space that was just stepped (not null)timeStep
- the duration of the simulation step (in seconds, ≥0)
-
prePhysicsTick
Callback invoked just before the physics is stepped. A good time to clear/apply forces. Meant to be overridden.- Specified by:
prePhysicsTick
in interfacePhysicsTickListener
- Parameters:
space
- the space that's about to be stepped (not null)timeStep
- the duration of the simulation step (in seconds, ≥0)
-