Class tjhBuckets

java.lang.Object
  |
  +--tjhBuckets

public class tjhBuckets
extends java.lang.Object

a simple regular space-partitioning class to speed up collision detection


Field Summary
protected  float bucket_scale
          the width of each bucket
protected  tjhBucket[][] buckets
          the 2D array of tjhBucket's
protected  int n_xBuckets
          the number of buckets in each direction
protected  int n_yBuckets
          the number of buckets in each direction
 
Constructor Summary
tjhBuckets(float scale, int n_x, int n_y)
          default constructor initializes bucket array
 
Method Summary
protected  int BCoord(float coord)
          returns the floor of the coord divided by the width of each bucket - the index on one axis of the bucket containing it
 boolean CollidesWithAny(tjh2dVector loc, float dist)
          would a tjhCell at the specified location be overlapping any existing one?
protected  tjhBucket FindBucket(tjh2dVector pos)
          locate the bucket that contains the specified coordinate (x or y)
 java.util.Vector GetAllWithin(tjh2dVector loc, float dist)
          get a list of the collisions that would be caused (empty if none)
 void PutCell(tjhCell cell)
          add the bucket reference for this cell (newly created or just moved)
 void RemoveCell(tjhCell cell)
          remove the bucket reference for this cell (died or about to move)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buckets

protected tjhBucket[][] buckets
the 2D array of tjhBucket's

bucket_scale

protected float bucket_scale
the width of each bucket

n_xBuckets

protected int n_xBuckets
the number of buckets in each direction

n_yBuckets

protected int n_yBuckets
the number of buckets in each direction
Constructor Detail

tjhBuckets

public tjhBuckets(float scale,
                  int n_x,
                  int n_y)
default constructor initializes bucket array
Method Detail

RemoveCell

public void RemoveCell(tjhCell cell)
remove the bucket reference for this cell (died or about to move)

PutCell

public void PutCell(tjhCell cell)
add the bucket reference for this cell (newly created or just moved)

GetAllWithin

public java.util.Vector GetAllWithin(tjh2dVector loc,
                                     float dist)
get a list of the collisions that would be caused (empty if none)

CollidesWithAny

public boolean CollidesWithAny(tjh2dVector loc,
                               float dist)
would a tjhCell at the specified location be overlapping any existing one?

FindBucket

protected tjhBucket FindBucket(tjh2dVector pos)
locate the bucket that contains the specified coordinate (x or y)

BCoord

protected int BCoord(float coord)
returns the floor of the coord divided by the width of each bucket - the index on one axis of the bucket containing it