org.odejava
Class Space

java.lang.Object
  extended by org.odejava.Space
Direct Known Subclasses:
HashSpace, QuadTreeSpace, SimpleSpace

public abstract class Space
extends Object

A space is a non-placeable geom that can contain other geoms. It is similar to the rigid body concept of the world, except that it applies to collision instead of dynamics.

Space objects exist to make collision detection go faster. Without spaces, you might generate contacts in your simulation by calling dCollide() to get contact points for every single pair of geoms. For N geoms this is O(N2) tests, which is too computationally expensive if your environment has many objects.

Developer note: currently all Geoms and even Body objects are stored also to Space object's as LinkedLists. This is for convenience. Spaces however have to do with collision only.

Created 16.12.2003 (dd.mm.yyyy)

Author:
Jani Laakso E-mail: jani.laakso@itmill.com see http://odejava.dev.java.net

Field Summary
protected  boolean deleted
          Flag indicating that this world has been requested to be deleted.
protected  LinkedList<Geom> geomList
           
protected  HashMap<String,Geom> geomMap
           
protected  org.odejava.ode.SWIGTYPE_p_dSpaceID parentId
          The identifier or the parent ODE space object to us
protected  org.odejava.ode.SWIGTYPE_p_dSpaceID spaceId
          Our ODE space identifier
static org.odejava.ode.SWIGTYPE_p_dSpaceID SPACEID_ZERO
          Deprecated. This is no longer needed and will be deleted shortly. Zero IDs are automatically derived from null references to objects
 
Constructor Summary
Space()
          Create a generic space object that does not have a parent space.
Space(Space parent)
          Create a generic space object that belongs to the given parent space.
 
Method Summary
 void add(Geom geom)
          Add a single item of geometry to this space.
 void addBodyGeoms(Body body)
          Adds all of the geoms that belong to the passed Body.
 void addGeom(Geom geom)
          Add a single item of geometry to this space.
 boolean containsGeom(String name)
          Returns true if the space contains a Geom with the given name.
 void delete()
          Request deletion of this space.
 boolean getChildCleanupMode()
          Get the child cleanup mode to be used after the next delete.
 Geom getGeom(String name)
          Get Geom by name.
 HashMap<String,Geom> getGeomMap()
          Get the internal mapping of names to geometry objects.
 List<Geom> getGeoms()
          Gets a list of the Geoms in the scene.
 org.odejava.ode.SWIGTYPE_p_dSpaceID getId()
           
 long getID()
           
 long getNativeAddr()
          Native address can be used to compare against contact information values which are also native addresses.
static Space getSpaceFromNativeAddr(long nativeAddress)
          Performs lookup of a WeakHashMap and returns the Geom with the native address equal to the one passed or null if none exist.
 Object getUserData()
           
 boolean isEnabled()
           
 void remove(Geom geom)
          Removes a Geom from this Space.
 void renameGeom(String oldName, String newName)
           
 void setChildCleanupMode(boolean killKids)
          Set the cleanup mode to be used by this space when it is deleted.
 void setEnabled(boolean enabled)
          Diables or Enables this geom.
 void setUserData(Object userData)
           
protected  void updateNativeAddr()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

spaceId

protected org.odejava.ode.SWIGTYPE_p_dSpaceID spaceId
Our ODE space identifier


parentId

protected org.odejava.ode.SWIGTYPE_p_dSpaceID parentId
The identifier or the parent ODE space object to us


geomList

protected LinkedList<Geom> geomList

geomMap

protected HashMap<String,Geom> geomMap

SPACEID_ZERO

@Deprecated
public static final org.odejava.ode.SWIGTYPE_p_dSpaceID SPACEID_ZERO
Deprecated. This is no longer needed and will be deleted shortly. Zero IDs are automatically derived from null references to objects

deleted

protected boolean deleted
Flag indicating that this world has been requested to be deleted. After this is set to true, none of the methods should allow further calls to ODE as the values are invalid, and may well cause a crash of the library or other strange error.

Constructor Detail

Space

public Space()
Create a generic space object that does not have a parent space.


Space

public Space(Space parent)
Create a generic space object that belongs to the given parent space. If the parent space reference is null, then this space is placed as a top-level space.

Parameters:
parent - A reference to the parent space, or null
Method Detail

getUserData

public final Object getUserData()
Returns:
Returns the userData.

setUserData

public final void setUserData(Object userData)
Parameters:
userData - The userData to set.

addGeom

public void addGeom(Geom geom)
Add a single item of geometry to this space. A check is performed to make sure that the geometry is not already part of this space. If it is, an exception is generated.

Parameters:
geom - The geometry instance to add
Throws:
IllegalOdejavaOperation - The geom is already part of this space

add

public void add(Geom geom)
Add a single item of geometry to this space. A check is performed to make sure that the geometry is not already part of this space. If it is, an exception is generated.

Parameters:
geom - The geometry instance to add
Throws:
IllegalOdejavaOperation - The geom is already part of this space

addBodyGeoms

public void addBodyGeoms(Body body)
Adds all of the geoms that belong to the passed Body. A check is performed to make sure that no geometries are multiply added. If one is found, an exception is generated.

Parameters:
body - A body to get the geometry(s) from
Throws:
IllegalOdejavaOperation - The geom is already part of this space

remove

public void remove(Geom geom)
Removes a Geom from this Space. This Geom can then be added to another Space if desired.

Throws:
IllegalArgumentException - if the Geom is not currently in this space.

getGeoms

public List<Geom> getGeoms()
Gets a list of the Geoms in the scene.

Returns:
Returns the geoms.

getGeom

public Geom getGeom(String name)
Get Geom by name. If the geometry does not exist in this space, null is returned.

Parameters:
name - The name of the geometry to fetch
Returns:
geom A reference to the geometry or null

renameGeom

public void renameGeom(String oldName,
                       String newName)

containsGeom

public boolean containsGeom(String name)
Returns true if the space contains a Geom with the given name.

Parameters:
name - the name of the Geom
Returns:
true if the space contains a Geom with the given name.

getGeomMap

public HashMap<String,Geom> getGeomMap()
Get the internal mapping of names to geometry objects. This is a reference to the internal map, so care should be taken when interacting with the map so as to not mess with the internal state.

Returns:
Returns the mapping of names to geometry.

setChildCleanupMode

public void setChildCleanupMode(boolean killKids)
Set the cleanup mode to be used by this space when it is deleted. A value of true says that child geometry should also be deleted when this space is deleted. A value of false leaves the child geometry alone.

Parameters:
killKids - true to delete the child geometry too

getChildCleanupMode

public boolean getChildCleanupMode()
Get the child cleanup mode to be used after the next delete.

Returns:
true if child geometry is being deleted too

delete

public void delete()
Request deletion of this space. Any further calls to this space instance after this has been called will be met with an error.


getId

public org.odejava.ode.SWIGTYPE_p_dSpaceID getId()

getID

public final long getID()

getSpaceFromNativeAddr

public static Space getSpaceFromNativeAddr(long nativeAddress)
Performs lookup of a WeakHashMap and returns the Geom with the native address equal to the one passed or null if none exist.

Parameters:
nativeAddress - the native address to lookup
Returns:
the Space with the native address equal to the one passed or null if none can be found.

updateNativeAddr

protected void updateNativeAddr()

getNativeAddr

public long getNativeAddr()

Native address can be used to compare against contact information values which are also native addresses.

UNSUPPORTED - use of this method is better avoided. No guarantees are made that this method won't change or even exist in future versions.

Returns:
Returns the native address.

setEnabled

public void setEnabled(boolean enabled)
Diables or Enables this geom.

Parameters:
enabled -
ODE Calls:
dGeomEnable - (if true is passed)
dGeomDiable - (if false is passed)

isEnabled

public boolean isEnabled()
Returns:
Diabled or Enabled state of this geom.
ODE Calls:
dGeomEnable - (if true is passed)
dGeomDiable - (if false is passed)