net.java.dev.joode.space
Class OctTreeSpace

java.lang.Object
  extended by net.java.dev.joode.geom.Geom
      extended by net.java.dev.joode.space.Space
          extended by net.java.dev.joode.space.OctTreeSpace
All Implemented Interfaces:
java.io.Serializable, SimState

public class OctTreeSpace
extends Space

OctTreeSpace orders the elements in an OctTree (a BSPTree to be precise) This way only Geoms close to eachother get tested for collisions. This means a Speed-Improvement from O(n^2) to O(n log n) in average case.

Author:
Arne Müller
See Also:
Serialized Form

Field Summary
static java.util.HashSet<Geom> tmp
           
 
Fields inherited from class net.java.dev.joode.geom.Geom
aabb, AABB_MAX_X, AABB_MAX_Y, AABB_MAX_Z, AABB_MIN_X, AABB_MIN_Y, AABB_MIN_Z, body, category_bits, collide_bits, dBoxClass, dCapsuleClass, dCircle, dConvex, dCylinderClass, dFirstSpaceClass, dFirstUserClass, dGeomNumClasses, dGeomTransformClass, dHashSpaceClass, dLastSpaceClass, dLastUserClass, dMaxUserClasses, dOctTreeSpaceClass, dPlaneClass, dQuadTreeSpaceClass, dRayClass, dRectangle, dSimpleSpaceClass, dSphereClass, dTriMeshClass, GEOM_AABB_BAD, GEOM_DIRTY, GEOM_ENABLED, GEOM_PLACEABLE, gflags, lpos, parent_space, pos, R, RAY_BACKFACECULL, RAY_CLOSEST_HIT, RAY_FIRSTCONTACT, tmpq, type
 
Constructor Summary
OctTreeSpace(Space parent)
          Creates a new OctTreeSpace with parent as it's parent-space
 
Method Summary
 void add(Geom g)
          adds a Geom to this Space.
 void cleanGeoms()
          turn all dirty geoms into clean geoms by computing their AABBs and any other space data structures that are required.
 OctTreeSpace cloneState(ClonedReferences util)
           deep clones the state object, any references to other SimState objects should be cloned and assigned to the clone via the ClonedReferences util object.
 void collide(java.lang.Object data, NearCallback callback)
          tests for collisions of the Geoms in this Space with each other.
 void collide2(java.lang.Object data, Geom geom, NearCallback callback)
          tests for collisions of a Geom with the Geoms in this Space
 void computeAABB()
          computes the AABB of this Space.
protected  java.util.Iterator<Geom> getGeoms()
          returns an Iterator through all GeomS in this Space
 void getGeoms(java.util.List<Geom> geoms)
          adds all the geoms in this space to the passed in list
 int getNumGeoms()
          returns the Number of Geoms in this Space
protected  boolean isEmpty()
          tests, if this is Space is empty
 void remove(Geom g)
          removes a Geom from this Space.
 
Methods inherited from class net.java.dev.joode.space.Space
addBodyGeoms, addGeomListener, canCollide, clonePartialSpace, collideAABBs, dGeomMoved, dSpaceCollide2, notifyGeomAdded, notifyGeomRemoved, query, removeBodyGeoms, removeGeomListener, testAABBs
 
Methods inherited from class net.java.dev.joode.geom.Geom
AABBTest, clonePartialGeom, destroy, getAABB, getUserData, isEnabled, recomputeAABB, setBody, setPosition, setQuaternion, setQuaternion, setRotation, setUserData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tmp

public static final java.util.HashSet<Geom> tmp
Constructor Detail

OctTreeSpace

public OctTreeSpace(Space parent)
Creates a new OctTreeSpace with parent as it's parent-space

Parameters:
parent - the parent space, use null for root-Spaces
Method Detail

isEmpty

protected boolean isEmpty()
Description copied from class: Space
tests, if this is Space is empty

Specified by:
isEmpty in class Space
Returns:
true, if empty

getGeoms

protected java.util.Iterator<Geom> getGeoms()
Description copied from class: Space
returns an Iterator through all GeomS in this Space

Specified by:
getGeoms in class Space
Returns:
the Iterator

getNumGeoms

public int getNumGeoms()
Description copied from class: Space
returns the Number of Geoms in this Space

Specified by:
getNumGeoms in class Space
Returns:
the Number of Geoms in this Space

getGeoms

public void getGeoms(java.util.List<Geom> geoms)
Description copied from class: Space
adds all the geoms in this space to the passed in list

Specified by:
getGeoms in class Space

cleanGeoms

public void cleanGeoms()
Description copied from class: Space
turn all dirty geoms into clean geoms by computing their AABBs and any other space data structures that are required. this should clear the GEOM_DIRTY and GEOM_AABB_BAD flags of all geoms.

Specified by:
cleanGeoms in class Space

computeAABB

public void computeAABB()
Description copied from class: Space
computes the AABB of this Space.

Overrides:
computeAABB in class Space

collide

public void collide(java.lang.Object data,
                    NearCallback callback)
Description copied from class: Space
tests for collisions of the Geoms in this Space with each other.

Specified by:
collide in class Space
Parameters:
data - the World of collision
callback - the callback for the collision

collide2

public void collide2(java.lang.Object data,
                     Geom geom,
                     NearCallback callback)
Description copied from class: Space
tests for collisions of a Geom with the Geoms in this Space

Specified by:
collide2 in class Space
Parameters:
data - the World of collision
geom - the Geom to collide with this Space.
callback - the callback for the collision

add

public void add(Geom g)
Description copied from class: Space
adds a Geom to this Space. Important: the Geom is not allowed to be already inside a different Space.

Specified by:
add in class Space
Parameters:
g - the Geom to add

remove

public void remove(Geom g)
removes a Geom from this Space. Important: If the Geom has changed position to much, it might not be found anymore, with possible mystorious bugs.

Specified by:
remove in class Space
Parameters:
g - the Geom to remove
See Also:
Space.remove(net.java.dev.joode.geom.Geom)

cloneState

public OctTreeSpace cloneState(ClonedReferences util)
Description copied from interface: SimState

deep clones the state object, any references to other SimState objects should be cloned and assigned to the clone via the ClonedReferences util object. The util object ensures that multiple clones of the same object are not performed during a clone operation.

Parameters:
util - instanciate a new one if top level cloning