net.nexttext
Class SpatialList

java.lang.Object
  extended by net.nexttext.SpatialList

public class SpatialList
extends java.lang.Object

The SpatialList class is used to keep track of the TextObjects in a spatially organised fashion in order to facilitate proximity and collision queries.

At the moment, the list will only contain glyph objects and no groups. Group behaviour based on proximity will have to be deduced from the collisions between the different glyphs.

The SpatialList is updated once each frame by the Simulator, meaning that as objects move during the behaviours step of the simulation the SpatialList becomes unsorted. For this reason, queries for possibly colliding objects will not always be completely accurate. However, this has not proved to be problematic in practice.

The spatial list is maintained using a sweep and prune collision approximation algorithm which use dynamic AABBs (Axis-Aligned Bounding Boxes) to determine proximity or overlap between two objects.

This algorithm is optimised based on the assumption that objects maintain their spatial coherence from frame to frame (ie: object don't travel very far within the span of one frame). As such, insertion of objects in the spatial list is costly (because the list has to be resorted), however once objects have been inserted, maintaining a sorted order is done in nearly O(n) most of the time.

Add description of how to use the class

TO DO: Add/Remove function for Groups


Constructor Summary
SpatialList()
           
 
Method Summary
 void add(TextObject to)
          Adds a TextObject to the spatial list.
 void add(TextObjectGlyph to)
          Adds a single TextObjectGlyph to the spatial list
 void add(TextObjectGroup tog)
          Adds all the glyphs part of a TextObjectGroup to the spatial list.
 int getNumCollisionTests()
          Returns the average number of collision tests performed by the sorting function
 java.util.HashSet<TextObjectGlyph> getPotentialCollisions(TextObject to)
          Redirects to the proper implementation of getPotentialCollisions based on type (TextObjectGlyph or TextObjectGroup)
 java.util.HashSet<TextObjectGlyph> getPotentialCollisions(TextObjectGlyph to)
          Given a TextObjectGlyph, get a list of objects which's bounding box are overlapping.
 java.util.HashSet<TextObjectGlyph> getPotentialCollisions(TextObjectGroup tog)
          Given a TextObjectGroup, find all the glyphs which's bounding boxes are overlapping with any of the given group's glyphs.
 void remove(TextObject to)
          Removes a TextObject to the spatial list.
 void remove(TextObjectGlyph to)
          Removes an object from the spatial list
 void remove(TextObjectGroup tog)
          Removes all the glyphs part of a TextObjectGroup from the spatial list
 void update()
          Sorts the X and Y axis interval lists.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SpatialList

public SpatialList()
Method Detail

update

public void update()
Sorts the X and Y axis interval lists.


add

public void add(TextObjectGlyph to)
Adds a single TextObjectGlyph to the spatial list


remove

public void remove(TextObjectGlyph to)
Removes an object from the spatial list


add

public void add(TextObjectGroup tog)
Adds all the glyphs part of a TextObjectGroup to the spatial list.


add

public void add(TextObject to)
Adds a TextObject to the spatial list. Use this method to avoid casting the object as group or a glyph


remove

public void remove(TextObject to)
Removes a TextObject to the spatial list. Use this method to avoid casting the object as group or a glyph


remove

public void remove(TextObjectGroup tog)
Removes all the glyphs part of a TextObjectGroup from the spatial list


getPotentialCollisions

public java.util.HashSet<TextObjectGlyph> getPotentialCollisions(TextObject to)
Redirects to the proper implementation of getPotentialCollisions based on type (TextObjectGlyph or TextObjectGroup)


getPotentialCollisions

public java.util.HashSet<TextObjectGlyph> getPotentialCollisions(TextObjectGlyph to)
Given a TextObjectGlyph, get a list of objects which's bounding box are overlapping. It returns an empty hashset if there is none.

Parameters:
to - A TextObjectGlyph to test for collisions

getPotentialCollisions

public java.util.HashSet<TextObjectGlyph> getPotentialCollisions(TextObjectGroup tog)
Given a TextObjectGroup, find all the glyphs which's bounding boxes are overlapping with any of the given group's glyphs. Returns an empty set if no objects are colliding with the group.


getNumCollisionTests

public int getNumCollisionTests()
Returns the average number of collision tests performed by the sorting function