com.jme3.bullet
Class PhysicsSpace

java.lang.Object
  extended by com.jme3.bullet.PhysicsSpace

public class PhysicsSpace
extends java.lang.Object

PhysicsSpace - The central jbullet-jme physics space


Nested Class Summary
static class PhysicsSpace.BroadphaseType
          interface with Broadphase types
 
Field Summary
static int AXIS_X
           
static int AXIS_Y
           
static int AXIS_Z
           
 
Constructor Summary
PhysicsSpace()
           
PhysicsSpace(PhysicsSpace.BroadphaseType broadphaseType)
           
PhysicsSpace(Vector3f worldMin, Vector3f worldMax)
           
PhysicsSpace(Vector3f worldMin, Vector3f worldMax, PhysicsSpace.BroadphaseType broadphaseType)
           
 
Method Summary
 void add(java.lang.Object obj)
          adds an object to the physics space
 void addAll(Spatial spatial)
          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 events
 void addCollisionObject(PhysicsCollisionObject obj)
           
 void addTickListener(PhysicsTickListener listener)
          Adds the specified listener to the physics tick listeners.
 void create()
          Has to be called from the (designated) physics thread
 void destroy()
          destroys the current PhysicsSpace so that a new one can be created
 void disableDebug()
          Disable debug display
 void distributeEvents()
           
 void enableDebug(AssetManager manager)
          Enable debug display for physics
<V> java.util.concurrent.Future<V>
enqueue(java.util.concurrent.Callable<V> callable)
          calls the callable on the next physics tick (ensuring e.g.
static
<V> java.util.concurrent.Future<V>
enqueueOnThisThread(java.util.concurrent.Callable<V> callable)
           
protected  void finalize()
           
 float getAccuracy()
          get the current accuracy of the physics computation
 PhysicsSpace.BroadphaseType getBroadphaseType()
           
 AssetManager getDebugManager()
           
static PhysicsSpace 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
 long getSpaceId()
          // * used internally // * @return the dynamicsWorld //
 Vector3f getWorldMax()
           
 Vector3f getWorldMin()
           
static void initNativePhysics()
           
 void rayTest_native(Vector3f from, Vector3f to, long physicsSpaceId, java.util.List<PhysicsRayTestResult> results)
           
 java.util.List rayTest(Vector3f from, Vector3f to)
          Performs a ray collision test and returns the results as a list of PhysicsRayTestResults
 java.util.List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to, java.util.List<PhysicsRayTestResult> results)
          Performs a ray collision test and returns the results as a list of PhysicsRayTestResults
 void remove(java.lang.Object obj)
          removes an object from the physics space
 void removeAll(Spatial spatial)
          Removes all physics controls and joints in the given spatial from the physics space (e.g.
 void removeCollisionGroupListener(int collisionGroup)
           
 void removeCollisionListener(PhysicsCollisionListener listener)
          Removes a CollisionListener from the list
 void removeCollisionObject(PhysicsCollisionObject obj)
           
 void removeTickListener(PhysicsTickListener listener)
           
 void setAccuracy(float accuracy)
          sets the accuracy of the physics computation, default=1/60s
 void setBroadphaseType(PhysicsSpace.BroadphaseType broadphaseType)
           
 void setGravity(Vector3f gravity)
          Sets the gravity of the PhysicsSpace, set before adding physics objects!
static void setLocalThreadPhysicsSpace(PhysicsSpace space)
          Used internally
 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.
 void setWorldMax(Vector3f worldMax)
          only applies for AXIS_SWEEP broadphase
 void setWorldMin(Vector3f worldMin)
          only applies for AXIS_SWEEP broadphase
 java.util.List<PhysicsSweepTestResult> sweepTest(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 > 0.4f).
 java.util.List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, java.util.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 > 0.4f).
 void update(float time)
          updates the physics space
 void update(float time, int maxSteps)
          updates the physics space, uses maxSteps
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AXIS_X

public static final int AXIS_X
See Also:
Constant Field Values

AXIS_Y

public static final int AXIS_Y
See Also:
Constant Field Values

AXIS_Z

public static final int AXIS_Z
See Also:
Constant Field Values
Constructor Detail

PhysicsSpace

public PhysicsSpace()

PhysicsSpace

public PhysicsSpace(PhysicsSpace.BroadphaseType broadphaseType)

PhysicsSpace

public PhysicsSpace(Vector3f worldMin,
                    Vector3f worldMax)

PhysicsSpace

public PhysicsSpace(Vector3f worldMin,
                    Vector3f worldMax,
                    PhysicsSpace.BroadphaseType broadphaseType)
Method Detail

getPhysicsSpace

public static PhysicsSpace 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

public static void setLocalThreadPhysicsSpace(PhysicsSpace space)
Used internally

Parameters:
space -

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 value
maxSteps -

distributeEvents

public void distributeEvents()

enqueueOnThisThread

public static <V> java.util.concurrent.Future<V> enqueueOnThisThread(java.util.concurrent.Callable<V> callable)

enqueue

public <V> java.util.concurrent.Future<V> enqueue(java.util.concurrent.Callable<V> callable)
calls the callable on the next physics tick (ensuring e.g. force applying)

Type Parameters:
V -
Parameters:
callable -
Returns:
Future object

add

public void add(java.lang.Object obj)
adds an object to the physics space

Parameters:
obj - the PhysicsControl or Spatial with PhysicsControl to add

addCollisionObject

public void addCollisionObject(PhysicsCollisionObject obj)

remove

public void remove(java.lang.Object obj)
removes an object from the physics space

Parameters:
obj - the PhysicsControl or Spatial with PhysicsControl to remove

removeCollisionObject

public void removeCollisionObject(PhysicsCollisionObject obj)

addAll

public void addAll(Spatial spatial)
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

public void removeAll(Spatial spatial)
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

setGravity

public void setGravity(Vector3f gravity)
Sets the gravity of the PhysicsSpace, set before adding physics objects!

Parameters:
gravity -

addTickListener

public void addTickListener(PhysicsTickListener listener)
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 -

removeTickListener

public void removeTickListener(PhysicsTickListener listener)

addCollisionListener

public void addCollisionListener(PhysicsCollisionListener listener)
Adds a CollisionListener that will be informed about collision events

Parameters:
listener - the CollisionListener to add

removeCollisionListener

public void removeCollisionListener(PhysicsCollisionListener listener)
Removes a CollisionListener from the list

Parameters:
listener - the CollisionListener to remove

addCollisionGroupListener

public 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.

Parameters:
listener -
collisionGroup -

removeCollisionGroupListener

public void removeCollisionGroupListener(int collisionGroup)

rayTest

public java.util.List rayTest(Vector3f from,
                              Vector3f to)
Performs a ray collision test and returns the results as a list of PhysicsRayTestResults


rayTest

public java.util.List<PhysicsRayTestResult> rayTest(Vector3f from,
                                                    Vector3f to,
                                                    java.util.List<PhysicsRayTestResult> results)
Performs a ray collision test and returns the results as a list of PhysicsRayTestResults


rayTest_native

public void rayTest_native(Vector3f from,
                           Vector3f to,
                           long physicsSpaceId,
                           java.util.List<PhysicsRayTestResult> results)

sweepTest

public java.util.List<PhysicsSweepTestResult> sweepTest(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 > 0.4f). SweepTest will not see a collision if it starts INSIDE an object and is moving AWAY from its center.


sweepTest

public java.util.List<PhysicsSweepTestResult> sweepTest(CollisionShape shape,
                                                        Transform start,
                                                        Transform end,
                                                        java.util.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 > 0.4f). SweepTest will not see a collision if it starts INSIDE an object and is moving AWAY from its center.


destroy

public void destroy()
destroys the current PhysicsSpace so that a new one can be created


getSpaceId

public long getSpaceId()
// * used internally // * @return the dynamicsWorld //


getBroadphaseType

public PhysicsSpace.BroadphaseType getBroadphaseType()

setBroadphaseType

public void setBroadphaseType(PhysicsSpace.BroadphaseType broadphaseType)

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 framerates 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 its 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 -

getWorldMin

public Vector3f getWorldMin()

setWorldMin

public void setWorldMin(Vector3f worldMin)
only applies for AXIS_SWEEP broadphase

Parameters:
worldMin -

getWorldMax

public Vector3f getWorldMax()

setWorldMax

public void setWorldMax(Vector3f worldMax)
only applies for AXIS_SWEEP broadphase

Parameters:
worldMax -

enableDebug

public void enableDebug(AssetManager manager)
Enable debug display for physics

Parameters:
manager - AssetManager to use to create debug materials

disableDebug

public void disableDebug()
Disable debug display


getDebugManager

public AssetManager getDebugManager()

initNativePhysics

public static void initNativePhysics()

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable