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
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumerate threading modes. -
Field Summary
FieldsFields inherited from class com.jme3.app.state.AbstractAppState
initialized -
Constructor Summary
ConstructorsConstructorDescriptionInstantiate 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 TypeMethodDescriptionvoidcleanup()Transition this state from terminating to detached.intCount the solvers in the thread-safe pool.protected BulletDebugAppStateCreate the configured debug-visualization app state.protected PhysicsSpacecreatePhysicsSpace(com.jme3.math.Vector3f min, com.jme3.math.Vector3f max, PhysicsSpace.BroadphaseType type) Create the configuredPhysicsSpace.floatDetermine the length of the debug axis arrows.floatDetermine 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 BulletDebugAppStateAccess the AppState to manage the debug visualization.com.jme3.renderer.CameraAccess the Camera used for debug visualization.protected DebugConfigurationAccess the configuration for debug visualization.Access the PhysicsSpace managed by this state.Determine which constraint solver the PhysicsSpace will use.floatgetSpeed()Return the physics-simulation speed.Determine which type of threading this app state uses.voidinitialize(com.jme3.app.state.AppStateManager stateManager, com.jme3.app.Application app) Initialize this state prior to its first update.booleanTest whether debug visualization is enabled.booleanTest whether the physics simulation is running (started but not yet stopped).voidphysicsTick(PhysicsSpace space, float timeStep) Callback invoked just after the physics has been stepped.voidUpdate this state after all rendering commands are flushed.voidprePhysicsTick(PhysicsSpace space, float timeStep) Callback invoked just before the physics is stepped.voidrender(com.jme3.renderer.RenderManager rm) Render this state.voidsetBroadphaseType(PhysicsSpace.BroadphaseType broadphaseType) Alter the broadphase type the PhysicsSpace will use.voidsetCollisionConfiguration(CollisionConfiguration configuration) Replace the collision configuration that will be used to instantiate the PhysicsSpace.voidAlter which angular velocities are included in the debug visualization.voidsetDebugAxisLength(float length) Alter the length of the debug axis arrows.voidsetDebugAxisLineWidth(float width) Alter the line width for debug axis arrows.voidAlter which bounding boxes are included in the debug visualization.voidsetDebugCamera(com.jme3.renderer.Camera camera) Replace the Camera used for debug visualization.voidsetDebugEnabled(boolean debugEnabled) Enable or disable debug visualization.voidAlter which objects are included in the debug visualization.voidAlter which gravity vectors are included in the debug visualization.voidsetDebugInitListener(DebugInitListener listener) Replace or remove the init listener for the BulletDebugAppState.voidsetDebugJointLineWidth(float width) Alter the line width for PhysicsJoint debug arrows.voidsetDebugShadowMode(com.jme3.renderer.queue.RenderQueue.ShadowMode mode) Alter the shadow mode of the debug root node.voidAlter which swept spheres are included in the debug visualization.voidAlter which velocity vectors are included in the debug visualization.voidsetDebugViewPorts(com.jme3.renderer.ViewPort... viewPorts) Alter which view ports will render the debug visualization.voidsetNumSolvers(int numSolvers) Alter the number of solvers in the thread-safe pool.protected voidsetPhysicsSpace(PhysicsSpace newSpace) Alter which PhysicsSpace is managed by this state.protected voidsetRunning(boolean desiredSetting) Alter whether the physics simulation is running (started but not yet stopped).voidsetSolverType(SolverType solver) Alter which constraint solver the PhysicsSpace will use.voidsetSpeed(float speed) Alter the physics simulation speed.voidsetThreadingType(BulletAppState.ThreadingType threadingType) Alter which type of threading this app state uses.voidsetTransformSpatial(com.jme3.scene.Spatial spatial) Alter the conversion from physics-space coordinates to world coordinates.voidsetWorldMax(com.jme3.math.Vector3f worldMax) Alter the coordinate range.voidsetWorldMin(com.jme3.math.Vector3f worldMin) Alter the coordinate range.voidAllocate a PhysicsSpace and start simulating physics.protected booleanAllocate the PhysicsSpace and start simulating physics using ThreadingType.PARALLEL.voidstateAttached(com.jme3.app.state.AppStateManager stateManager) Transition this state from detached to initializing.voidStop physics after this state is detached.voidupdate(float tpf) Update this state prior to rendering.com.jme3.math.Vector3fworldMax()Copy the maximum coordinate values for AXIS_SWEEP.com.jme3.math.Vector3fworldMin()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:
cleanupin interfacecom.jme3.app.state.AppState- Overrides:
cleanupin 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:
initializein interfacecom.jme3.app.state.AppState- Overrides:
initializein 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:
postRenderin interfacecom.jme3.app.state.AppState- Overrides:
postRenderin 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:
renderin interfacecom.jme3.app.state.AppState- Overrides:
renderin 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:
stateAttachedin interfacecom.jme3.app.state.AppState- Overrides:
stateAttachedin 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:
updatein interfacecom.jme3.app.state.AppState- Overrides:
updatein 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:
physicsTickin 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:
prePhysicsTickin interfacePhysicsTickListener- Parameters:
space- the space that's about to be stepped (not null)timeStep- the duration of the simulation step (in seconds, ≥0)
-