org.odejava.xode
Class XODEContainer

java.lang.Object
  extended by org.odejava.xode.XODEObject
      extended by org.odejava.xode.XODEContainer
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
XODEGroup, XODERoot, XODEWorld

public abstract class XODEContainer
extends XODEObject
implements Serializable

Base XODE container (as defined in the spec)

Author:
William Denniss
See Also:
Serialized Form

Field Summary
protected  boolean absoluteTransform
           
protected  org.openmali.vecmath2.Matrix4f cachedBodyRelTransform
           
protected  org.openmali.vecmath2.Matrix4f cachedRootTransform
           
protected  org.openmali.vecmath2.Matrix4f cachedTransform
           
protected  org.openmali.vecmath2.Matrix4f relTransform
           
protected  List<XODEObject> xodeObjects
           
 
Fields inherited from class org.odejava.xode.XODEObject
node, odeObject
 
Constructor Summary
protected XODEContainer()
           
  XODEContainer(Node node)
           
  XODEContainer(String name, org.openmali.vecmath2.Matrix4f transform)
           
 
Method Summary
 void addChild(XODEObject toAdd)
          Adds a child XODEObject to this container
protected  void addChildElements(Element parent, Document doc)
           
 void addChildren(World world, Space space, String namePrefix, List<Object> odeList)
           
protected  void addTransformElement(Element element, Document doc)
          Adds a new Element representing the transform of this container to the passed Element.
 void buildOde(World world, Space space, String namePrefix, List<Object> odeList)
          Constructs the ODE scene based on this XODE structure
 org.openmali.vecmath2.Matrix4f getBodyRelTransform()
          Recursivly builds the transform of this container relative to its parent body.
 List<XODEObject> getChildren()
          Returns a List containing all child XODEObjectS
 org.openmali.vecmath2.Tuple3f getPosition()
          Gets a Vector representing the virtual world position of this object
 org.openmali.vecmath2.Matrix4f getRootTransform()
          Returns the transform of the ancestor XODERoot or the identity matrix if none.
 org.openmali.vecmath2.Quaternion4f getRotation()
          Gets a Quaternion representing the virtual world rotation of this object
 org.openmali.vecmath2.Matrix4f getTransform()
          Gets the virtual world transform of this object.
 org.openmali.vecmath2.Matrix4f getTransform(org.openmali.vecmath2.Matrix4f transform)
          Gets the virtual world transform of this object.
protected  XODETransform getXODETransform()
           
protected  void invalidateTransformCache()
          Forces recomputation of all transforms in the XODE tree next time getTransform, getPosition or getRotation is called.
 boolean isAbsoluteTransformMode()
          Returns true if the transform mode for this object is absolute
protected  void parseTransform(Node xodeData)
          Parses the transform from the XODE structured XML data
 void removeChild(XODEObject toRemove)
          Removes a child XODEObject from this container
 void scrapDOMObjectCache()
          Dereferences the cached XML Node object (if any) for this XODEContainer and all child XODEContainers and XODEObjects.
 void scrapODEObjectCache()
          Dereferences the cached ODE object (if any) for this XODEContainer and all child XODEContainers and XODEObjects.
 void setAbsolute(boolean absolute)
          Sets the transform mode.
protected  void setParent(XODEContainer parent)
          Sets the parent of this object. and invalidates the transform cache for this branch of the XODE tree.
 void setPosition(org.openmali.vecmath2.Tuple3f position)
          Sets the position of this object.
 void setRotation(org.openmali.vecmath2.Quaternion4f rotation)
          Sets the rotation of this object.
 void setTransform(org.openmali.vecmath2.Matrix4f transform)
          Sets the transform of this object.
 
Methods inherited from class org.odejava.xode.XODEObject
buildElement, clone, getDOMNode, getFirstBodyAncestor, getFirstJointGroupAncestor, getFirstSpaceAncestor, getName, getODEObject, getParent, setName
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xodeObjects

protected List<XODEObject> xodeObjects

relTransform

protected org.openmali.vecmath2.Matrix4f relTransform

absoluteTransform

protected boolean absoluteTransform

cachedTransform

protected transient org.openmali.vecmath2.Matrix4f cachedTransform

cachedBodyRelTransform

protected transient org.openmali.vecmath2.Matrix4f cachedBodyRelTransform

cachedRootTransform

protected transient org.openmali.vecmath2.Matrix4f cachedRootTransform
Constructor Detail

XODEContainer

protected XODEContainer()

XODEContainer

public XODEContainer(String name,
                     org.openmali.vecmath2.Matrix4f transform)

XODEContainer

public XODEContainer(Node node)
Method Detail

parseTransform

protected void parseTransform(Node xodeData)
Parses the transform from the XODE structured XML data

Parameters:
xodeData - the node to parse

getRootTransform

public org.openmali.vecmath2.Matrix4f getRootTransform()
Returns the transform of the ancestor XODERoot or the identity matrix if none. Result is cached for efficiancy.

Returns:
the transform of the ancestor XODERoot or the identity matrix if none.

getBodyRelTransform

public org.openmali.vecmath2.Matrix4f getBodyRelTransform()
Recursivly builds the transform of this container relative to its parent body. Used for GeomTransform where ODE maintains the relationship so one only needs to specify the offset from the body (i.e. relative transform).

Returns:
the transform of this container relative to its parent body
Throws:
XODEException - if no body ancestor was found

buildOde

public void buildOde(World world,
                     Space space,
                     String namePrefix,
                     List<Object> odeList)
Description copied from class: XODEObject
Constructs the ODE scene based on this XODE structure

Specified by:
buildOde in class XODEObject
Parameters:
world - the World to add created bodies
space - the Space to add created geometry
namePrefix - string to prefix all names
odeList - list of all created ODE files (will be added to)

addChildren

public void addChildren(World world,
                        Space space,
                        String namePrefix,
                        List<Object> odeList)

addChild

public void addChild(XODEObject toAdd)
Adds a child XODEObject to this container

Parameters:
toAdd - the XODEObject to add

removeChild

public void removeChild(XODEObject toRemove)
Removes a child XODEObject from this container

Parameters:
toRemove - the XODEObject to remove

getChildren

public List<XODEObject> getChildren()
Returns a List containing all child XODEObjectS

Returns:
a List containing all child XODEObjectS

getTransform

public final org.openmali.vecmath2.Matrix4f getTransform()
Gets the virtual world transform of this object.

Returns:
the virtual world transform of this object.

getTransform

public final org.openmali.vecmath2.Matrix4f getTransform(org.openmali.vecmath2.Matrix4f transform)
Gets the virtual world transform of this object.

Parameters:
transform - the Matrix to store the transform in (will be overwritten and returned)
Returns:
the virtual world transform of this object.

getPosition

public org.openmali.vecmath2.Tuple3f getPosition()
Gets a Vector representing the virtual world position of this object

Returns:
the virtual world position of this object

getRotation

public org.openmali.vecmath2.Quaternion4f getRotation()
Gets a Quaternion representing the virtual world rotation of this object

Returns:
the virtual world rotation of this object

setPosition

public void setPosition(org.openmali.vecmath2.Tuple3f position)
Sets the position of this object. If the transform mode is relative, it is relative to the parent XODEContainer (if any), else the transform is absolute and is relative only to the master transform of the XODERoot.

Parameters:
position - the new position of this object.
See Also:
setAbsolute(boolean)

setRotation

public void setRotation(org.openmali.vecmath2.Quaternion4f rotation)
Sets the rotation of this object. If the transform mode is relative, it is relative to the parent XODEContainer (if any), else the transform is absolute and is relative only to the master transform of the XODERoot.

Parameters:
rotation - the new rotation of this object.
See Also:
setAbsolute(boolean)

setTransform

public void setTransform(org.openmali.vecmath2.Matrix4f transform)
Sets the transform of this object. If the transform mode is relative, it is relative to the parent XODEContainer (if any), else the transform is absolute and is relative only to the master transform of the XODERoot.

Parameters:
transform - the new transform of this object.
See Also:
setAbsolute(boolean)

setAbsolute

public void setAbsolute(boolean absolute)
Sets the transform mode. If absolute, this objects transform is relative only to the XODERoot ancestor (if any). Else, it is relative to the parent XODEContainer (if any)

Parameters:
absolute - true for absolute mode, false for relative mode
See Also:
isAbsoluteTransformMode()

isAbsoluteTransformMode

public boolean isAbsoluteTransformMode()
Returns true if the transform mode for this object is absolute

Returns:
true if the transform mode for this object is absolute
See Also:
setTransform(org.openmali.vecmath2.Matrix4f)

invalidateTransformCache

protected void invalidateTransformCache()
Forces recomputation of all transforms in the XODE tree next time getTransform, getPosition or getRotation is called. Called when a new parent transform is set in XODERoot.

See Also:
XODERoot.setRootTransform(org.openmali.vecmath2.Matrix4f)

scrapODEObjectCache

public void scrapODEObjectCache()
Dereferences the cached ODE object (if any) for this XODEContainer and all child XODEContainers and XODEObjects.

See Also:
XODEObject.odeObject

scrapDOMObjectCache

public void scrapDOMObjectCache()
Dereferences the cached XML Node object (if any) for this XODEContainer and all child XODEContainers and XODEObjects.

See Also:
XODEObject.node

addTransformElement

protected void addTransformElement(Element element,
                                   Document doc)
Adds a new Element representing the transform of this container to the passed Element.

Parameters:
element - the element to which the transform element will be added
doc - the Document this Element will be associated with

addChildElements

protected void addChildElements(Element parent,
                                Document doc)

setParent

protected void setParent(XODEContainer parent)
Sets the parent of this object. and invalidates the transform cache for this branch of the XODE tree. Should only be called by the addChild() method of XODEContainer.

Overrides:
setParent in class XODEObject
Parameters:
parent - the parent of this object or null if there isn't one
Throws:
XODEException - if this XODEObject has a parent and a non-null parent was passed
See Also:
addChild(XODEObject)

getXODETransform

protected XODETransform getXODETransform()