Class cocos.collision_model.CollisionManagerGrid

Implements the CollisionManager interface based on the scheme known as spatial hashing.

The idea behind is to divide the space in rectangles with a given width and height, and have a table telling which objects overlaps each rectangle.

Later, when the question 'which know objects has such and such spatial relation with <some object>' arrives, only the objects in rectangles overlaping <some object> (or nearby ones) needs to be examined for the condition.

Look at CollisionManager for other class and methods documentation.

Methods

  __init__(self, xmin, xmax, ymin, ymax, cell_width, cell_height)
Cell width and height have impact on performance.
  add(self, obj)
  remove_tricky(self, obj)
  clear(self)
  they_collide(self, obj1, obj2)
  objs_colliding(self, obj)
  iter_colliding(self, obj)
  any_near(self, obj, near_distance)
  objs_near(self, obj, near_distance)
  objs_near_wdistance(self, obj, near_distance)
  ranked_objs_near(self, obj, near_distance)
  iter_all_collisions(self)
  knows(self, obj)
  known_objs(self)
  objs_touching_point(self, x, y)
  objs_into_box(self, minx, maxx, miny, maxy)

Method Details

__init__

(Constructor) __init__(self, xmin, xmax, ymin, ymax, cell_width, cell_height)
Cell width and height have impact on performance. For objects with same with, and with width==height, a good value is 1.25 * (object width). For mixed widths, a good guess can be ~ 1.25 * { width(object): all objects not exceptionlly big}
Parameters:
xmin : float
minimun x coordinate for a point in world
xmax : float
maximun x coordinate for a point in world
ymin : float
minimun y coordinate for a point in world
ymax : float
maximun y coordinate for a point in world
cell_width : float
width for the rectangles the space will be broken
cell_height : float
heigh for the rectangles the space will be broken