net.java.dev.joode.space
Class Space

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

public abstract class Space
extends Geom

Spaces are fundamental to collision detection, as they handle the collidable Geoms. Because Spaces are themselves Geoms, a Space can be added to another Space. This can improve collision detection significantly, especially if the different spaces are on great parts disjoint.
There are several different types of Spaces:
-SimpleSpace
-OctTreeSpace
-HashSpace (this space is not yet implemented)

Author:
Tom Larkworthy
See Also:
Serialized Form

Field Summary
 
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
protected Space()
          used for cloning
  Space(Space parent, int type)
          Creates a new Space and adds it to parent.
 
Method Summary
abstract  void add(Geom g)
          adds a Geom to this Space.
 void addBodyGeoms(Body b)
          Adds all Geoms associated with the Body
 void addGeomListener(GeomListener l)
           
static boolean canCollide(Geom g1, Geom g2, boolean ignoreStatic)
           
abstract  void cleanGeoms()
          turn all dirty geoms into clean geoms by computing their AABBs and any other space data structures that are required.
 void clonePartialSpace(Space partialClone, ClonedReferences util)
           
abstract  void collide(java.lang.Object data, NearCallback callback)
          tests for collisions of the Geoms in this Space with each other.
abstract  void collide2(java.lang.Object data, Geom geom, NearCallback callback)
          tests for collisions of a Geom with the Geoms in this Space
static boolean collideAABBs(Geom g1, Geom g2, java.lang.Object data, NearCallback callback)
          collides two Geoms, but it first performs some simple AABB-tests
 void computeAABB()
          computes the AABB of this Space.
static void dGeomMoved(Geom g)
          from the bottom of the space hierarchy up, process all clean geoms turning them into dirty geoms.
static void dSpaceCollide2(Geom g1, Geom g2, java.lang.Object data, NearCallback callback)
          collides two Spaces or Geoms with eachother and themselves
protected abstract  java.util.Iterator<Geom> getGeoms()
          returns an Iterator through all GeomS in this Space
abstract  void getGeoms(java.util.List<Geom> geoms)
          adds all the geoms in this space to the passed in list
abstract  int getNumGeoms()
          returns the Number of Geoms in this Space
protected abstract  boolean isEmpty()
          tests, if this is Space is empty
protected  void notifyGeomAdded(Geom geom)
           
protected  void notifyGeomRemoved(Geom geom)
           
 boolean query(Geom g)
          tests, if the parent space of a Geom is this Space
abstract  void remove(Geom g)
          removes the Geom from this Space.
 void removeBodyGeoms(Body b)
           
 void removeGeomListener(GeomListener l)
           
static boolean testAABBs(float[] bounds1, float[] bounds2)
          tests, if bounds1 does not intersect bounds2
 
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
 
Methods inherited from interface net.java.dev.joode.SimState
cloneState
 

Constructor Detail

Space

public Space(Space parent,
             int type)
Creates a new Space and adds it to parent. If this Space is supposed to be a root-space, simply specify null for parent.

Parameters:
parent - the space, that is going to be the parent of this space - null is legal
type - the type of the Space.

Space

protected Space()
used for cloning

Method Detail

computeAABB

public void computeAABB()
computes the AABB of this Space.

Specified by:
computeAABB in class Geom

query

public boolean query(Geom g)
tests, if the parent space of a Geom is this Space

Parameters:
g - the Geom to test

isEmpty

protected abstract boolean isEmpty()
tests, if this is Space is empty

Returns:
true, if empty

getGeoms

protected abstract java.util.Iterator<Geom> getGeoms()
returns an Iterator through all GeomS in this Space

Returns:
the Iterator

getNumGeoms

public abstract int getNumGeoms()
returns the Number of Geoms in this Space

Returns:
the Number of Geoms in this Space

getGeoms

public abstract void getGeoms(java.util.List<Geom> geoms)
adds all the geoms in this space to the passed in list

Parameters:
geoms -

canCollide

public static boolean canCollide(Geom g1,
                                 Geom g2,
                                 boolean ignoreStatic)

cleanGeoms

public abstract void cleanGeoms()
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.


collide

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

Parameters:
data - the World of collision
callback - the callback for the collision

collide2

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

Parameters:
data - the World of collision
geom - the Geom to collide with this Space.
callback - the callback for the collision

add

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

Parameters:
g - the Geom to add

addBodyGeoms

public void addBodyGeoms(Body b)
Adds all Geoms associated with the Body

Parameters:
b -

remove

public abstract void remove(Geom g)
removes the Geom from this Space.

Parameters:
g - the Geom to remove

removeBodyGeoms

public void removeBodyGeoms(Body b)

dGeomMoved

public static void dGeomMoved(Geom g)
from the bottom of the space hierarchy up, process all clean geoms turning them into dirty geoms.

Parameters:
g - the moved Geom

testAABBs

public static boolean testAABBs(float[] bounds1,
                                float[] bounds2)
tests, if bounds1 does not intersect bounds2

Parameters:
bounds1 - the first bounds with typical aabb format
bounds2 - the second bounds with typical aabb format
Returns:
if bounds1 and bounds2 are disjoint

collideAABBs

public static boolean collideAABBs(Geom g1,
                                   Geom g2,
                                   java.lang.Object data,
                                   NearCallback callback)
collides two Geoms, but it first performs some simple AABB-tests

Parameters:
g1 - the first Geom to collide
g2 - the second Geom to collide
data - some data
callback - the callback for the collision

dSpaceCollide2

public static void dSpaceCollide2(Geom g1,
                                  Geom g2,
                                  java.lang.Object data,
                                  NearCallback callback)
collides two Spaces or Geoms with eachother and themselves

Parameters:
g1 - the first Geom (Space) to collide
g2 - the second Geom (Space) to collide
data - some data
callback - the callback for the collision

addGeomListener

public void addGeomListener(GeomListener l)

removeGeomListener

public void removeGeomListener(GeomListener l)

notifyGeomAdded

protected void notifyGeomAdded(Geom geom)

notifyGeomRemoved

protected void notifyGeomRemoved(Geom geom)

clonePartialSpace

public void clonePartialSpace(Space partialClone,
                              ClonedReferences util)