SpatialHashing:
Filter:
GameLoop/Classes (extension) | Class

SpatialHashing
ExtensionExtension

A spatial index for efficient collision detection

Description

SpatialHashing is a spatial index used by EntityManager for collision detection. It is based on the paper "Optimization of Large-Scale, Real-Time Simulations by Spatial Hashing" (Erin J. Hastings, Jaruwan Mesit, Ratan K. Guha). I also had a look at the implementation described here.

The objects registered in the index should be circles and have getter methods for position and radius.

Class Methods

.new

Create a new instance of SpatialHashing with the given dimensions and resolution. The dimensions are in metres. The cell size should be able to fully contain the largest entity in order to function correctly.

Instance Methods

.register

register the entity in the index

.clearBuckets

clear the index

.getCellsForLine

A bit of a hack to see the cells that contain a line. This is used for adding and colliding with Wall objects