com.jmex.physics
Class PhysicsSpace

java.lang.Object
  extended by com.jmex.physics.PhysicsSpace

public abstract class PhysicsSpace
extends java.lang.Object

PhysicsSpace is the central class of the jME Physics API. PhysicsNodes from the same space can interact with each other. Multiple spaces can be used to model independent physics simulation parts.
PhysicsSpace is used to create PhysicNodes via the createDynamicNode() and createStaticNode() methods.

The application must frequently call update(float) to let the simulation advance. While update is not called the simulation is paused.

Author:
Irrisor

Nested Class Summary
protected static interface PhysicsSpace.Factory
          Interface for subclasses to register a factory for them.
 
Field Summary
static java.lang.String LOGGER_NAME
           
 
Constructor Summary
protected PhysicsSpace()
          Default constructor.
 
Method Summary
protected  int addCollisionGroup(CollisionGroup value)
          add group
protected  void addJoint(Joint joint)
          Adds a Joint to this space.
protected  void addNode(PhysicsNode node)
          Adds a PhysicsNode to this space.
 boolean addToUpdateCallbacks(PhysicsUpdateCallback value)
           
protected  void adjustContact(PendingContact contact)
          Called by update(float) to determine contact details.
static void chooseImplementation(java.lang.String implementationName)
          Choose an implementation by name to be used in the next call to create().
abstract  boolean collide(PhysicsSpatial spatial1, PhysicsSpatial spatial2)
           
protected  void collisionEvent(ContactInfo info)
          Called by subclasses upon each collision event that could be processed by the application.
static PhysicsSpace create()
          Create an implementation specific instance of PhysicsSpace.
protected  PhysicsBox createBox(java.lang.String name, PhysicsNode node)
          Create a physics box.
protected  PhysicsCapsule createCapsule(java.lang.String name, PhysicsNode node)
          Create a physics capsule.
abstract  CollisionGroup createCollisionGroup(java.lang.String name)
          Create a CollisionGroup.
protected  PhysicsCylinder createCylinder(java.lang.String name, PhysicsNode node)
          Create a physics cylinder.
abstract  DynamicPhysicsNode createDynamicNode()
           
abstract  Joint createJoint()
           
protected  PhysicsMesh createMesh(java.lang.String name, PhysicsNode node)
          Create a physics mesh.
protected  PhysicsRay createRay(java.lang.String name, PhysicsNode node)
          Create a physics ray.
protected  PhysicsSphere createSphere(java.lang.String name, PhysicsNode node)
          Create a physics sphere.
abstract  StaticPhysicsNode createStaticNode()
           
abstract  void delete()
          Delete all physics for this space.
 void drawImplementationSpecificPhysics(com.jme.renderer.Renderer renderer)
           
static java.util.Set<java.lang.String> getAvailableImplementations()
           
 com.jme.input.util.SyntheticButton getCollisionEventHandler()
          All phyics collisions are reported to this synthetic button to allow the application to react on collisions.
 java.util.List<? extends CollisionGroup> getCollisionGroups()
           
 java.util.List<ContactCallback> getContactCallbacks()
          Add/Remove/Query callbacks for specifying contact details.
abstract  CollisionGroup getDefaultCollisionGroup()
           
 Material getDefaultMaterial()
          The default material used for nodes without material set.
abstract  com.jme.math.Vector3f getDirectionalGravity(com.jme.math.Vector3f store)
          Query the gravity in this space.
protected static PhysicsSpace.Factory getFactory()
           
protected  PhysicsUpdateCallback getFromUpdateCallbacks(int index)
          Get an element from the updateCallbacks association.
abstract  java.util.List<? extends Joint> getJoints()
           
abstract  java.util.List<? extends PhysicsNode> getNodes()
           
abstract  CollisionGroup getStaticCollisionGroup()
          Note: this method might return the same group like getDefaultCollisionGroup().
abstract  void pick(PhysicsSpatial spatial)
           
 void removeAllFromUpdateCallbacks()
           
protected  void removeCollisionGroup(CollisionGroup value)
           
 boolean removeFromUpdateCallbacks(PhysicsUpdateCallback value)
           
protected  void removeJoint(Joint joint)
          Removes a Joint from this space.
protected  void removeNode(PhysicsNode node)
          Removes a PhysicsNode from this space.
abstract  void setAccuracy(float value)
          Change the accuracy of the underlying physics simulation.
abstract  void setAutoRestThreshold(float threshold)
          This method sets the "rest" threshold, if the implementation supports ignoring dynamic physics nodes that do not move.
 void setDefaultMaterial(Material value)
          Change default material for nodes without a material set.
abstract  void setDirectionalGravity(com.jme.math.Vector3f gravity)
          Specify the overall directional gravity in this space.
protected static void setFactory(PhysicsSpace.Factory value)
           
 void setupBinaryClassLoader(com.jme.util.export.binary.BinaryImporter importer)
           
protected  int sizeOfUpdateCallbacks()
           
abstract  void update(float time)
          This method is called by the application to process a simulation timestep.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER_NAME

public static final java.lang.String LOGGER_NAME
See Also:
Constant Field Values
Constructor Detail

PhysicsSpace

protected PhysicsSpace()
Default constructor.

Method Detail

update

public abstract void update(float time)
This method is called by the application to process a simulation timestep. This method also calls the methods from PhysicsUpdateCallback according to their contract.

Parameters:
time - time the simulation should advance

adjustContact

protected void adjustContact(PendingContact contact)
Called by update(float) to determine contact details. The default implementation iterates the contactCallbacks (descending indexes) to determine the details.

Parameters:
contact - contact that needs details
See Also:
PendingContact, getContactCallbacks(), ContactCallback

getContactCallbacks

public final java.util.List<ContactCallback> getContactCallbacks()
Add/Remove/Query callbacks for specifying contact details.

See Also:
adjustContact(com.jmex.physics.contact.PendingContact)

addNode

protected void addNode(PhysicsNode node)
Adds a PhysicsNode to this space. A newly created PhysicsNode is automatically added.

Parameters:
node - the PhysicsNode to add

addJoint

protected void addJoint(Joint joint)
Adds a Joint to this space. A newly created Joint is automatically added.

Parameters:
joint - the Joint to add

removeNode

protected void removeNode(PhysicsNode node)
Removes a PhysicsNode from this space. Use addNode(PhysicsNode) to add it again.

Parameters:
node - the PhysicsNode to remove

removeJoint

protected void removeJoint(Joint joint)
Removes a Joint from this space. Use addJoint(Joint) to add it again.

Parameters:
joint - the PhysicsJoint to remove

getDefaultMaterial

public Material getDefaultMaterial()
The default material used for nodes without material set.

Returns:
current default material

setDefaultMaterial

public void setDefaultMaterial(Material value)
Change default material for nodes without a material set.

Parameters:
value - new default material
Throws:
java.lang.IllegalArgumentException - if parameter is null

getNodes

public abstract java.util.List<? extends PhysicsNode> getNodes()
Returns:
an immutable list of physics nodes in this space

getJoints

public abstract java.util.List<? extends Joint> getJoints()

delete

public abstract void delete()
Delete all physics for this space.


pick

public abstract void pick(PhysicsSpatial spatial)

collide

public abstract boolean collide(PhysicsSpatial spatial1,
                                PhysicsSpatial spatial2)

setAutoRestThreshold

public abstract void setAutoRestThreshold(float threshold)
This method sets the "rest" threshold, if the implementation supports ignoring dynamic physics nodes that do not move.

Parameters:
threshold - if this threashold for linear or rotational velocity is not reaching during several simulation steps the physics node rests until it collides, is moved or altered in another way
See Also:
DynamicPhysicsNode.rest(), DynamicPhysicsNode.unrest()

drawImplementationSpecificPhysics

public void drawImplementationSpecificPhysics(com.jme.renderer.Renderer renderer)

getFactory

protected static PhysicsSpace.Factory getFactory()
Returns:
factory for creating PhysicsSpaces
See Also:
PhysicsSpace.Factory

setFactory

protected static void setFactory(PhysicsSpace.Factory value)
Parameters:
value - factory for creating PhysicsSpaces
See Also:
PhysicsSpace.Factory

getAvailableImplementations

public static java.util.Set<java.lang.String> getAvailableImplementations()
Returns:
a set of available implementation names
See Also:
chooseImplementation(String)

chooseImplementation

public static void chooseImplementation(java.lang.String implementationName)
Choose an implementation by name to be used in the next call to create().

Parameters:
implementationName - implemntation name
See Also:
getAvailableImplementations()

create

public static PhysicsSpace create()
Create an implementation specific instance of PhysicsSpace.

Returns:
new instance of this class

createDynamicNode

public abstract DynamicPhysicsNode createDynamicNode()
Returns:
a new dynamic physics node

createStaticNode

public abstract StaticPhysicsNode createStaticNode()
Returns:
a new static physics node

createJoint

public abstract Joint createJoint()
Returns:
a new Joint

setDirectionalGravity

public abstract void setDirectionalGravity(com.jme.math.Vector3f gravity)
Specify the overall directional gravity in this space.

Parameters:
gravity - new gravity in this space

getDirectionalGravity

public abstract com.jme.math.Vector3f getDirectionalGravity(com.jme.math.Vector3f store)
Query the gravity in this space. The passed Vector3f will be populated with the values, and then returned.

Parameters:
store - where to store the gravity (null to create a new vector)
Returns:
store

createSphere

protected PhysicsSphere createSphere(java.lang.String name,
                                     PhysicsNode node)
Create a physics sphere. This is a convenience method for physics implementations which don't need different geometry creation for different PhysicsNodes - is overridden in this case.

Parameters:
name - name of the Spatial
node - physics node which becomes parent of the geometry, null allowed if implementation supports geoms without a parent
Returns:
a new physics sphere
See Also:
PhysicsCollisionGeometry, PhysicsSphere

createBox

protected PhysicsBox createBox(java.lang.String name,
                               PhysicsNode node)
Create a physics box. This is a convenience method for physics implementations which don't need different geometry creation for different PhysicsNodes.

Parameters:
name - name of the Spatial
node - physics node which becomes parent of the geometry, null allowed if implementation supports geoms without a parent
Returns:
a new physics box
See Also:
PhysicsCollisionGeometry, PhysicsBox

createCylinder

protected PhysicsCylinder createCylinder(java.lang.String name,
                                         PhysicsNode node)
Create a physics cylinder. This is a convenience method for physics implementations which don't need different geometry creation for different PhysicsNodes.

Parameters:
name - name of the Spatial
node - physics node which becomes parent of the geometry, null allowed if implementation supports geoms without a parent
Returns:
a new physics cylinder
See Also:
PhysicsCollisionGeometry, PhysicsCylinder

createCapsule

protected PhysicsCapsule createCapsule(java.lang.String name,
                                       PhysicsNode node)
Create a physics capsule. This is a convenience method for physics implementations which don't need different geometry creation for different PhysicsNodes.

Parameters:
name - name of the Spatial
node - physics node which becomes parent of the geometry, null allowed if implementation supports geoms without a parent
Returns:
a new physics capsule
See Also:
PhysicsCollisionGeometry, PhysicsCapsule

createMesh

protected PhysicsMesh createMesh(java.lang.String name,
                                 PhysicsNode node)
Create a physics mesh. This is a convenience method for physics implementations which don't need different geometry creation for different PhysicsNodes.

Parameters:
name - name of the Spatial
node - physics node which becomes parent of the geometry, null allowed if implementation supports geoms without a parent
Returns:
a new physics mesh
See Also:
PhysicsCollisionGeometry, PhysicsMesh

createRay

protected PhysicsRay createRay(java.lang.String name,
                               PhysicsNode node)
Create a physics ray. This is a convenience method for physics implementations which don't need different geometry creation for different PhysicsNodes.

Parameters:
name - name of the Spatial
node - physics node which becomes parent of the geometry, null allowed if implementation supports geoms without a parent
Returns:
a new physics mesh
See Also:
PhysicsCollisionGeometry, PhysicsRay

addToUpdateCallbacks

public boolean addToUpdateCallbacks(PhysicsUpdateCallback value)
See Also:
PhysicsUpdateCallback

getFromUpdateCallbacks

protected PhysicsUpdateCallback getFromUpdateCallbacks(int index)
Get an element from the updateCallbacks association.

Parameters:
index - index of element to be retrieved
Returns:
the element, null if index out of range
See Also:
PhysicsUpdateCallback

removeAllFromUpdateCallbacks

public void removeAllFromUpdateCallbacks()
See Also:
PhysicsUpdateCallback

removeFromUpdateCallbacks

public boolean removeFromUpdateCallbacks(PhysicsUpdateCallback value)
See Also:
PhysicsUpdateCallback

sizeOfUpdateCallbacks

protected int sizeOfUpdateCallbacks()
See Also:
PhysicsUpdateCallback

getCollisionEventHandler

public com.jme.input.util.SyntheticButton getCollisionEventHandler()
All phyics collisions are reported to this synthetic button to allow the application to react on collisions. The trigger receives the ContactInfo as data element. Thus an action can cast getTriggerData() to ContactInfo to obtain additional information on the collision.

Note: if this event handler is obtained it must be used with an InputHandler which is updated regularly

Returns:
a synthetic button that is triggered on each collision event
See Also:
PhysicsNode.getCollisionEventHandler(), PhysicsCollisionGeometry.getCollisionEventHandler()

collisionEvent

protected void collisionEvent(ContactInfo info)
Called by subclasses upon each collision event that could be processed by the application.

Parameters:
info - info about the collision

setupBinaryClassLoader

public void setupBinaryClassLoader(com.jme.util.export.binary.BinaryImporter importer)

setAccuracy

public abstract void setAccuracy(float value)
Change the accuracy of the underlying physics simulation. This value is implementation dependant! It should match a step size (or similar) for iterative methods.

Parameters:
value - value > 0 to indicate accuracy, smaller values mean more accuracy

addCollisionGroup

protected int addCollisionGroup(CollisionGroup value)
add group

Parameters:
value - group to add
Returns:
index of group in list

removeCollisionGroup

protected void removeCollisionGroup(CollisionGroup value)

getCollisionGroups

public java.util.List<? extends CollisionGroup> getCollisionGroups()
Returns:
the list of CollisionGroups used by this PhysicsSpace
See Also:
CollisionGroup

createCollisionGroup

public abstract CollisionGroup createCollisionGroup(java.lang.String name)
Create a CollisionGroup.

Parameters:
name - name of this group (descriptive only)
Returns:
new collision group
See Also:
CollisionGroup

getDefaultCollisionGroup

public abstract CollisionGroup getDefaultCollisionGroup()
Returns:
the default collision group for newly created nodes
See Also:
getStaticCollisionGroup()

getStaticCollisionGroup

public abstract CollisionGroup getStaticCollisionGroup()
Note: this method might return the same group like getDefaultCollisionGroup().

Returns:
the default collision group for newly created static nodes
See Also:
getDefaultCollisionGroup()