Package com.jme3.bullet
Class PhysicsSpace
java.lang.Object
com.jme3.bullet.PhysicsSpace
PhysicsSpace - The central jbullet-jme physics space
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
interface with Broadphase types -
Field Summary
-
Constructor Summary
ConstructorDescriptionPhysicsSpace
(PhysicsSpace.BroadphaseType broadphaseType) PhysicsSpace
(Vector3f worldMin, Vector3f worldMax) PhysicsSpace
(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType) -
Method Summary
Modifier and TypeMethodDescriptionvoid
adds an object to the physics spacevoid
adds all physics controls and joints in the given spatial node to the physics space (e.g.void
addCollisionGroupListener
(PhysicsCollisionGroupListener listener, int collisionGroup) Adds a listener for a specific collision group, such a listener can disable collisions when they happen.
There can be only one listener per collision group.void
addCollisionListener
(PhysicsCollisionListener listener) Adds a CollisionListener that will be informed about collision eventsvoid
void
addTickListener
(PhysicsTickListener listener) Adds the specified listener to the physics tick listeners.void
applies gravity value to all objectsvoid
clears forces of all objectsvoid
create()
Has to be called from the (designated) physics threadvoid
destroy()
destroys the current PhysicsSpace so that a new one can be createdvoid
<V> Future<V>
calls the callable on the next physics tick (ensuring e.g.static <V> Future<V>
enqueueOnThisThread
(Callable<V> callable) float
get the current accuracy of the physics computationcom.bulletphysics.dynamics.DynamicsWorld
used internallygetGravity
(Vector3f gravity) Gets the gravity of the PhysicsSpacestatic PhysicsSpace
Get the current PhysicsSpace running on this thread
For parallel physics, this can also be called from the OpenGL thread to receive the PhysicsSpaceint
Performs a ray collision test and returns the results as a list of PhysicsRayTestResultsrayTest
(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results) Performs a ray collision test and returns the results as a list of PhysicsRayTestResultsvoid
removes an object from the physics spacevoid
Removes all physics controls and joints in the given spatial from the physics space (e.g.void
removeCollisionGroupListener
(int collisionGroup) void
Removes a CollisionListener from the listvoid
void
removeTickListener
(PhysicsTickListener listener) void
setAccuracy
(float accuracy) sets the accuracy of the physics computation, default=1/60svoid
setBroadphaseType
(PhysicsSpace.BroadphaseType broadphaseType) void
setGravity
(Vector3f gravity) Sets the gravity of the PhysicsSpace, set before adding physics objects!static void
Used internallyvoid
setMaxSubSteps
(int steps) Sets the maximum amount of extra steps that will be used to step the physics when the fps is below the physics fps.void
setSolverNumIterations
(int numIterations) Set the number of iterations used by the contact solver.void
setWorldMax
(Vector3f worldMax) only applies for AXIS_SWEEP broadphasevoid
setWorldMin
(Vector3f worldMin) only applies for AXIS_SWEEP broadphasesweepTest
(CollisionShape shape, Transform start, Transform end) Performs a sweep collision test and returns the results as a list of PhysicsSweepTestResults
You have to use different Transforms for start and end (at least distance greater than 0.4f).sweepTest
(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results) Performs a sweep collision test and returns the results as a list of PhysicsSweepTestResults
You have to use different Transforms for start and end (at least distance greater than 0.4f).void
update
(float time) updates the physics spacevoid
update
(float time, int maxSteps) updates the physics space, uses maxSteps
-
Field Details
-
AXIS_X
public static final int AXIS_Xindex of the X axis- See Also:
-
AXIS_Y
public static final int AXIS_Yindex of the Y axis- See Also:
-
AXIS_Z
public static final int AXIS_Zindex of the Z axis- See Also:
-
-
Constructor Details
-
PhysicsSpace
public PhysicsSpace() -
PhysicsSpace
-
PhysicsSpace
-
PhysicsSpace
public PhysicsSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType)
-
-
Method Details
-
getPhysicsSpace
Get the current PhysicsSpace running on this thread
For parallel physics, this can also be called from the OpenGL thread to receive the PhysicsSpace- Returns:
- the PhysicsSpace running on this thread
-
setLocalThreadPhysicsSpace
Used internally- Parameters:
space
- which space to simulate on the current thread
-
create
public void create()Has to be called from the (designated) physics thread -
update
public void update(float time) updates the physics space- Parameters:
time
- the current time value
-
update
public void update(float time, int maxSteps) updates the physics space, uses maxSteps- Parameters:
time
- the current time valuemaxSteps
- the maximum number of steps of size accuracy (≥1) or 0 for a single step of size timeInterval
-
distributeEvents
public void distributeEvents() -
enqueueOnThisThread
-
enqueue
calls the callable on the next physics tick (ensuring e.g. force applying)- Type Parameters:
V
- the return type of the Callable- Parameters:
callable
- the Callable to invoke- Returns:
- a new AppTask
-
add
adds an object to the physics space- Parameters:
obj
- the PhysicsControl or Spatial with PhysicsControl to add
-
addCollisionObject
-
remove
removes an object from the physics space- Parameters:
obj
- the PhysicsControl or Spatial with PhysicsControl to remove
-
removeCollisionObject
-
addAll
adds all physics controls and joints in the given spatial node to the physics space (e.g. after loading from disk) - recursive if node- Parameters:
spatial
- the rootnode containing the physics objects
-
removeAll
Removes all physics controls and joints in the given spatial from the physics space (e.g. before saving to disk) - recursive if node- Parameters:
spatial
- the rootnode containing the physics objects
-
getRigidBodyList
-
getGhostObjectList
-
getCharacterList
-
getJointList
-
getVehicleList
-
setGravity
Sets the gravity of the PhysicsSpace, set before adding physics objects!- Parameters:
gravity
- the desired acceleration vector (in physics-space coordinates, not null, unaffected, default=0,-10,0)
-
getGravity
Gets the gravity of the PhysicsSpace- Parameters:
gravity
- storage for the result (modified if not null)- Returns:
- the acceleration vector (in physics-space coordinates, either gravity or a new instance)
-
applyGravity
public void applyGravity()applies gravity value to all objects -
clearForces
public void clearForces()clears forces of all objects -
addTickListener
Adds the specified listener to the physics tick listeners. The listeners are called on each physics step, which is not necessarily each frame but is determined by the accuracy of the physics space.- Parameters:
listener
- the listener to register (not null, alias created)
-
removeTickListener
-
addCollisionListener
Adds a CollisionListener that will be informed about collision events- Parameters:
listener
- the CollisionListener to add
-
removeCollisionListener
Removes a CollisionListener from the list- Parameters:
listener
- the CollisionListener to remove
-
addCollisionGroupListener
Adds a listener for a specific collision group, such a listener can disable collisions when they happen.
There can be only one listener per collision group.- Parameters:
listener
- the listener to register (not null, alias created)collisionGroup
- which group it should listen for (bitmask with exactly one bit set)
-
removeCollisionGroupListener
public void removeCollisionGroupListener(int collisionGroup) -
rayTest
Performs a ray collision test and returns the results as a list of PhysicsRayTestResults- Parameters:
from
- the starting location (physics-space coordinates, not null, unaffected)to
- the ending location (in physics-space coordinates, not null, unaffected)- Returns:
- a new list of results (not null)
-
rayTest
public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results) Performs a ray collision test and returns the results as a list of PhysicsRayTestResults- Parameters:
from
- the starting location (in physics-space coordinates, not null, unaffected)to
- the ending location (in physics-space coordinates, not null, unaffected)results
- the list to hold results (not null, modified)- Returns:
- results
-
sweepTest
Performs a sweep collision test and returns the results as a list of PhysicsSweepTestResults
You have to use different Transforms for start and end (at least distance greater than 0.4f). SweepTest will not see a collision if it starts INSIDE an object and is moving AWAY from its center.- Parameters:
shape
- the shape to sweep (not null, convex, unaffected)start
- the starting physics-space transform (not null, unaffected)end
- the ending physics-space transform (not null, unaffected)- Returns:
- a new list of results
-
sweepTest
public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results) Performs a sweep collision test and returns the results as a list of PhysicsSweepTestResults
You have to use different Transforms for start and end (at least distance greater than 0.4f). SweepTest will not see a collision if it starts INSIDE an object and is moving AWAY from its center.- Parameters:
shape
- the shape to sweep (not null, convex, unaffected)start
- the starting physics-space transform (not null, unaffected)end
- the ending physics-space transform (not null, unaffected)results
- the list to hold results (not null, modified)- Returns:
- results
-
destroy
public void destroy()destroys the current PhysicsSpace so that a new one can be created -
getDynamicsWorld
public com.bulletphysics.dynamics.DynamicsWorld getDynamicsWorld()used internally- Returns:
- the dynamicsWorld
-
getBroadphaseType
-
setBroadphaseType
-
setMaxSubSteps
public void setMaxSubSteps(int steps) Sets the maximum amount of extra steps that will be used to step the physics when the fps is below the physics fps. Doing this maintains determinism in physics. For example a maximum number of 2 can compensate for frame rates as low as 30fps when the physics has the default accuracy of 60 fps. Note that setting this value too high can make the physics drive down its own fps in case it's overloaded.- Parameters:
steps
- The maximum number of extra steps, default is 4.
-
getAccuracy
public float getAccuracy()get the current accuracy of the physics computation- Returns:
- the current accuracy
-
setAccuracy
public void setAccuracy(float accuracy) sets the accuracy of the physics computation, default=1/60s- Parameters:
accuracy
- the desired time step (in seconds, default=1/60)
-
getWorldMin
-
setWorldMin
only applies for AXIS_SWEEP broadphase- Parameters:
worldMin
- the desired minimum coordinates values (not null, unaffected, default=-10k,-10k,-10k)
-
getWorldMax
-
setWorldMax
only applies for AXIS_SWEEP broadphase- Parameters:
worldMax
- the desired maximum coordinates values (not null, unaffected, default=10k,10k,10k)
-
setSolverNumIterations
public void setSolverNumIterations(int numIterations) Set the number of iterations used by the contact solver. The default is 10. Use 4 for low quality, 20 for high quality.- Parameters:
numIterations
- The number of iterations used by the contact and constraint solver.
-
getSolverNumIterations
public int getSolverNumIterations()
-