com.jmex.physics
Class PhysicsNode

java.lang.Object
  extended by com.jme.scene.Spatial
      extended by com.jme.scene.Node
          extended by com.jmex.physics.PhysicsNode
All Implemented Interfaces:
com.jme.util.export.Savable, PhysicsSpatial, java.io.Serializable
Direct Known Subclasses:
DynamicPhysicsNode, StaticPhysicsNode

public abstract class PhysicsNode
extends com.jme.scene.Node
implements PhysicsSpatial

A PhysicsNode defines a physical entity. Its children may be graphical and physical scenegraph Spatial. The graphical Spatials are used for visual representation and may be used for automatic computation of physical representation (see generatePhysicsGeometry(), PhysicsCollisionGeometry). The physical Spatials define the collision bounds for the physics simulation. Advanced implementation may even use them for mass distribution of dynamic nodes.

PhysicsNodes are created solely by the PhysicsSpace (methods PhysicsSpace.createDynamicNode() and PhysicsSpace.createStaticNode()).

Author:
Irrisor
See Also:
generatePhysicsGeometry(), DynamicPhysicsNode, StaticPhysicsNode, PhysicsCollisionGeometry, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.jme.scene.Spatial
com.jme.scene.Spatial.CullHint, com.jme.scene.Spatial.LightCombineMode, com.jme.scene.Spatial.NormalsMode, com.jme.scene.Spatial.TextureCombineMode
 
Field Summary
static java.lang.String MATERIAL_PROPERTY
           
 
Fields inherited from class com.jme.scene.Node
children
 
Fields inherited from class com.jme.scene.Spatial
cullHint, frustrumIntersects, geometricalControllers, isCollidable, lightCombineMode, localRotation, localScale, localTranslation, LOCKED_BOUNDS, LOCKED_BRANCH, LOCKED_MESH_DATA, LOCKED_NONE, LOCKED_SHADOWS, LOCKED_TRANSFORMS, lockedMode, name, normalsMode, parent, queueDistance, renderQueueMode, renderStateList, textureCombineMode, worldBound, worldRotation, worldScale, worldTranslation, zOrder
 
Method Summary
 PhysicsBox createBox(java.lang.String name)
          Create a physics box.
 PhysicsCapsule createCapsule(java.lang.String name)
          Create a physics capsule.
 PhysicsCylinder createCylinder(java.lang.String name)
          Create a physics cylinder.
 PhysicsMesh createMesh(java.lang.String name)
          Create a physics mesh.
 PhysicsRay createRay(java.lang.String name)
          Create a physics ray.
 PhysicsSphere createSphere(java.lang.String name)
          Create a physics sphere.
 void delete()
           
protected  void drawDebugInfo(com.jme.renderer.Renderer renderer)
          Draw information about the physical properties of the Node.
 void generatePhysicsGeometry()
          This method generates physics geometry bounds for detecting collision from the graphical representation in this PhysicsNode.
 void generatePhysicsGeometry(boolean useTriangleAccurateGeometries)
          This method generates physics geometry bounds for detecting collision from the graphical representation in this PhysicsNode.
static void generatePhysicsGeometry(com.jme.scene.Node source, PhysicsNode target, boolean useTriangleAccurateGeometries)
          This method generates physics geometry bounds for detecting collision from the graphical representation in this PhysicsNode.
static void generatePhysicsGeometry(com.jme.scene.Node source, PhysicsNode target, boolean useTriangleAccurateGeometries, java.util.Map<com.jme.scene.Spatial,PhysicsCollisionGeometry> collisionGeometryMap)
          This method generates physics geometry bounds for detecting collision from the graphical representation in this PhysicsNode.
 java.lang.Class getClassTag()
           
 com.jme.input.util.SyntheticButton getCollisionEventHandler()
          Creates a synthetic button that is triggered when this node collides with another node.
 CollisionGroup getCollisionGroup()
           
 Material getMaterial()
          Query default material of this node.
 PhysicsNode getPhysicsNode()
           
abstract  PhysicsSpace getSpace()
           
 boolean isActive()
           
abstract  boolean isResting()
           
abstract  boolean isStatic()
           
 void read(com.jme.util.export.JMEImporter im)
           
 boolean setActive(boolean value)
          Activate the node when added to a space.
 void setCollisionGroup(CollisionGroup value)
           
 void setMaterial(Material value)
          Change material of this node.
protected  void setParent(com.jme.scene.Node parent)
          overridden to check we don't get another PhysicsNode as parent.
 void write(com.jme.util.export.JMEExporter ex)
           
 
Methods inherited from class com.jme.scene.Node
applyRenderState, attachChild, attachChildAt, childChange, detachAllChildren, detachChild, detachChildAt, detachChildNamed, draw, findCollisions, findPick, getChild, getChild, getChildIndex, getChildren, getQuantity, getTriangleCount, getVertexCount, hasChild, hasCollision, lockBounds, lockMeshes, lockShadows, lockTransforms, setModelBound, sortLights, swapChildren, unlockBounds, unlockMeshes, unlockShadows, unlockTransforms, updateModelBound, updateWorldBound, updateWorldData, updateWorldVectors
 
Methods inherited from class com.jme.scene.Spatial
addController, calculateCollisions, calculatePick, clearControllers, clearRenderState, clearRenderState, getController, getControllerCount, getControllers, getCullHint, getLastFrustumIntersection, getLightCombineMode, getLocalCullHint, getLocalLightCombineMode, getLocalNormalsMode, getLocalRenderQueueMode, getLocalRotation, getLocalScale, getLocalTextureCombineMode, getLocalToWorldMatrix, getLocalTranslation, getLocks, getName, getNormalsMode, getParent, getRenderQueueMode, getRenderState, getRenderState, getTextureCombineMode, getUserData, getWorldBound, getWorldRotation, getWorldScale, getWorldTranslation, getZOrder, hasAncestor, isCollidable, localToWorld, lock, lock, lockBranch, lockMeshes, lookAt, onDraw, propagateBoundToRoot, propagateStatesFromRoot, removeController, removeController, removeFromParent, removeUserData, rotateUpTo, setCullHint, setIsCollidable, setLastFrustumIntersection, setLightCombineMode, setLocalRotation, setLocalRotation, setLocalScale, setLocalScale, setLocalTranslation, setLocalTranslation, setLocks, setLocks, setName, setNormalsMode, setRenderQueueMode, setRenderState, setTextureCombineMode, setUserData, setZOrder, setZOrder, toString, unlock, unlock, unlockBranch, unlockMeshes, updateGeometricState, updateRenderState, updateRenderState, updateWorldRotation, updateWorldScale, updateWorldTranslation, updateWorldVectors, worldToLocal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MATERIAL_PROPERTY

public static final java.lang.String MATERIAL_PROPERTY
See Also:
Constant Field Values
Method Detail

getSpace

public abstract PhysicsSpace getSpace()
Returns:
space this node belongs to, must not be null

isStatic

public abstract boolean isStatic()
Returns:
true if this is a static (passive, immovable) node.

generatePhysicsGeometry

public void generatePhysicsGeometry()
This method generates physics geometry bounds for detecting collision from the graphical representation in this PhysicsNode.

Throws:
java.lang.IllegalStateException - if no graphical representation is present (no Geometries within this Node)
See Also:
PhysicsCollisionGeometry

generatePhysicsGeometry

public void generatePhysicsGeometry(boolean useTriangleAccurateGeometries)
This method generates physics geometry bounds for detecting collision from the graphical representation in this PhysicsNode.

Parameters:
useTriangleAccurateGeometries - true to use triangle accuracy for collision detection with arbitrary geometries - use with care! (makes it expensive to compute collisions)
Throws:
java.lang.IllegalStateException - if no graphical representation is present (no Geometries within this Node)
See Also:
PhysicsCollisionGeometry

generatePhysicsGeometry

public static void generatePhysicsGeometry(com.jme.scene.Node source,
                                           PhysicsNode target,
                                           boolean useTriangleAccurateGeometries)
This method generates physics geometry bounds for detecting collision from the graphical representation in this PhysicsNode.

Parameters:
source - The Node whose children are traversed to create corresponding collision geometries
target - The PhysicsNode to which the collision geometries are added. Can be the same object as source.
useTriangleAccurateGeometries - true to use triangle accuracy for collision detection with arbitrary geometries - use with care! (makes it expensive to compute collisions)
Throws:
java.lang.IllegalStateException - if no graphical representation is present (no Geometries within this Node)
See Also:
PhysicsCollisionGeometry

generatePhysicsGeometry

public static void generatePhysicsGeometry(com.jme.scene.Node source,
                                           PhysicsNode target,
                                           boolean useTriangleAccurateGeometries,
                                           java.util.Map<com.jme.scene.Spatial,PhysicsCollisionGeometry> collisionGeometryMap)
This method generates physics geometry bounds for detecting collision from the graphical representation in this PhysicsNode.

Parameters:
source - The Node whose children are traversed to create corresponding collision geometries
target - The PhysicsNode to which the collision geometries are added. Can be the same object as source.
useTriangleAccurateGeometries - true to use triangle accuracy for collision detection with arbitrary geometries - use with care! (makes it expensive to compute collisions)
collisionGeometryMap - If a map is passed, each spatial for which a collision geometry is generated will be put into it with the collision geometry as value. Also, Spatials already inside the map won't have any collision geometry generated. Pass null to avoid this.
Throws:
java.lang.IllegalStateException - if no graphical representation is present (no Geometries within this Node)
See Also:
PhysicsCollisionGeometry

setParent

protected void setParent(com.jme.scene.Node parent)
overridden to check we don't get another PhysicsNode as parent.

Overrides:
setParent in class com.jme.scene.Spatial
Parameters:
parent - new Parent
See Also:
Spatial.setParent(com.jme.scene.Node)

drawDebugInfo

protected void drawDebugInfo(com.jme.renderer.Renderer renderer)
Draw information about the physical properties of the Node.

Parameters:
renderer - where to draw to

createSphere

public PhysicsSphere createSphere(java.lang.String name)
Create a physics sphere.

Parameters:
name - name of the Spatial
Returns:
a new physics sphere
See Also:
PhysicsCollisionGeometry, PhysicsSphere

createBox

public PhysicsBox createBox(java.lang.String name)
Create a physics box.

Parameters:
name - name of the Spatial
Returns:
a new physics box
See Also:
PhysicsCollisionGeometry, PhysicsBox

createCylinder

public PhysicsCylinder createCylinder(java.lang.String name)
Create a physics cylinder.

Parameters:
name - name of the Spatial
Returns:
a new physics cylinder
See Also:
PhysicsCollisionGeometry, PhysicsCylinder

createCapsule

public PhysicsCapsule createCapsule(java.lang.String name)
Create a physics capsule.

Parameters:
name - name of the Spatial
Returns:
a new physics capsule
See Also:
PhysicsCollisionGeometry, PhysicsCapsule

createMesh

public PhysicsMesh createMesh(java.lang.String name)
Create a physics mesh.

Parameters:
name - name of the Spatial
Returns:
a new physics mesh
See Also:
PhysicsCollisionGeometry, PhysicsMesh

createRay

public PhysicsRay createRay(java.lang.String name)
Create a physics ray.

Parameters:
name - name of the Spatial
Returns:
a new physics ray
See Also:
PhysicsCollisionGeometry, PhysicsRay

isActive

public final boolean isActive()
Returns:
true if node is currently active

setActive

public boolean setActive(boolean value)
Activate the node when added to a space. Deactivate when removed.

Parameters:
value - true when activated
Returns:
true if node was (de)activated, false if state was already set to value

getMaterial

public Material getMaterial()
Query default material of this node. If no material was set for a geometry the material of this physics node is returned.

Returns:
material used for inheriting geometries, not null
See Also:
PhysicsCollisionGeometry.getMaterial()

setMaterial

public void setMaterial(Material value)
Change material of this node. All geometries that did not have a matrial set as well as those with the same material like the node inherit this nodes material.

Parameters:
value - new material
See Also:
PhysicsCollisionGeometry.setMaterial(com.jmex.physics.material.Material)

getCollisionEventHandler

public com.jme.input.util.SyntheticButton getCollisionEventHandler()
Creates a synthetic button that is triggered when this node collides with another node.

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 a collision event that involves this node
See Also:
PhysicsSpace.getCollisionEventHandler()

delete

public void delete()

isResting

public abstract boolean isResting()
Returns:
true if the physics engine believes that this nodes is resting like described in the DynamicPhysicsNode.rest() method. For static nodes this return true, always.
See Also:
DynamicPhysicsNode.rest()

getPhysicsNode

public final PhysicsNode getPhysicsNode()
Specified by:
getPhysicsNode in interface PhysicsSpatial
Returns:
the PhysicsNode the collision geometry belongs to, or the node itself if this is a node

getClassTag

public java.lang.Class getClassTag()
Specified by:
getClassTag in interface com.jme.util.export.Savable
Overrides:
getClassTag in class com.jme.scene.Spatial

read

public void read(com.jme.util.export.JMEImporter im)
          throws java.io.IOException
Specified by:
read in interface com.jme.util.export.Savable
Overrides:
read in class com.jme.scene.Node
Throws:
java.io.IOException

write

public void write(com.jme.util.export.JMEExporter ex)
           throws java.io.IOException
Specified by:
write in interface com.jme.util.export.Savable
Overrides:
write in class com.jme.scene.Node
Throws:
java.io.IOException

getCollisionGroup

public CollisionGroup getCollisionGroup()
Returns:
current value of the field collisionGroup

setCollisionGroup

public void setCollisionGroup(CollisionGroup value)
Parameters:
value - new value for field collisionGroup
See Also:
CollisionGroup