Class R.collision.broadphase.SpatialGrid
Extends
R.spatial.AbstractSpatialContainer.
A structure which divides a finite space up into a coarse grid to
perform "broad phase" collision determinations within the space.
After the PCL (potential collision list) is built, a "narrow phase"
collision model would need to be employed to determine accurate collision
response. Using AABB overlapping for simple true/false determinations is
one method. Another method would be to use something like GJK to determine
by how much two objects' convex hulls are overlapped.
Defined in: spatialgrid.js.
Constructor Attributes | Constructor Name and Description |
---|---|
R.collision.broadphase.SpatialGrid(width, height, divisions)
Create an instance of a spatial grid model
|
Field Attributes | Field Name and Description |
---|---|
Collision checks are performed in the node where the object
being tested resides, and in the four surrounding polar nodes.
|
|
Collision checks are performed in the node where the object
being tested resides, and in the four surrounding polar nodes.
|
|
Collision checks are limited to the exact node where the
object being tested resides.
|
|
Collision checks are performed in the node where the object
being tested resides, and in the eight surrounding nodes.
|
Method Attributes | Method Name and Description |
---|---|
debugPCLCaches(obj)
Dump the cached PCLs to the console so they can be inspected.
|
|
findNodePoint(point)
Find the node that contains the specified point.
|
|
Get the accuracy level of collision checks.
|
|
Get the class name of this object
|
|
Get the number of divisions along the horizontal and vertical axis.
|
|
getNode(x, y)
Get a node within the grid.
|
|
Returns all objects within every node of the spatial grid.
|
|
getPCL(point)
Get the list of objects with respect to the point given.
|
|
release()
Releases the spatial grid back into the object pool.
|
|
reset()
Reset the collision model, removing any references to objects
from all collision nodes.
|
|
setAccuracy(accuracy)
Set the accuracy of the collision checks to either #GOOD_ACCURACY,
#BETTER_ACCURACY, or #HIGH_ACCURACY.
|
Class Detail
R.collision.broadphase.SpatialGrid(width, height, divisions)
Create an instance of a spatial grid model
- Parameters:
- width
- {Number} The width of the area
- height
- {Number} The height of the area
- divisions
- {Number} The number of divisions along both axis
Field Detail
BEST_ACCURACY
Collision checks are performed in the node where the object
being tested resides, and in the four surrounding polar nodes.
BETTER_ACCURACY
Collision checks are performed in the node where the object
being tested resides, and in the four surrounding polar nodes.
GOOD_ACCURACY
Collision checks are limited to the exact node where the
object being tested resides.
HIGH_ACCURACY
Collision checks are performed in the node where the object
being tested resides, and in the eight surrounding nodes.
Method Detail
debugPCLCaches(obj)
Dump the cached PCLs to the console so they can be inspected. Passing an
object to the method will return the PCL which contains that object.
- Parameters:
- obj Optional
- {Object} The object to find in the PCL, or
null
to return all caches.
{R.spatial.SpatialGridNode}
findNodePoint(point)
Find the node that contains the specified point.
- Parameters:
- point
- {R.math.Point2D} The point to locate the node for
- Returns:
- {R.spatial.SpatialGridNode}
{Number}
getAccuracy()
Get the accuracy level of collision checks.
- Returns:
- {Number} The accuracy level
{String}
getClassName()
Get the class name of this object
- Returns:
- {String} "R.collision.broadphase.SpatialGrid"
{Number}
getDivisions()
Get the number of divisions along the horizontal and vertical axis. The
divisions are uniform for both axis, so the cells of the grid won't necessarily
be square.
- Returns:
- {Number}
{R.collision.broadphase.SpatialGridNode}
getNode(x, y)
Get a node within the grid. The X and Y coordinates are node coordinates, and
not world coordinates. For example, if a grid has 5 divisions, the cells are
numbered 0 through 4 on each axis.
- Parameters:
- x
- {Number} The virtual X coordinate in our grid
- y
- {Number} The virtual Y coordinate in our grid
- Returns:
- {R.collision.broadphase.SpatialGridNode}
{R.struct.Container}
getObjects()
Returns all objects within every node of the spatial grid.
- Returns:
- {R.struct.Container} A container with all objects in the spatial grid
{R.struct.Container}
getPCL(point)
Get the list of objects with respect to the point given. Objects will
be returned from the nodes that make up the grid node containing
the point, and the following adjacent nodes:
- Good Accuracy - Just the node containing the point (G)
- Better Accuracy - The four polar nodes around the center (G, B)
- High Accuracy - The eight nodes around the center (G, B, H)
+---+---+---+ | H | B | H | +---+---+---+ | B | G | B | +---+---+---+ | H | B | H | +---+---+---+
- Parameters:
- point
- {R.math.Point2D} The point to begin the search at.
- Returns:
- {R.struct.Container} A container of objects found that could be collision targets
release()
Releases the spatial grid back into the object pool. See PooledObject#release
for more information.
reset()
Reset the collision model, removing any references to objects
from all collision nodes.
setAccuracy(accuracy)
Set the accuracy of the collision checks to either #GOOD_ACCURACY,
#BETTER_ACCURACY, or #HIGH_ACCURACY. See #getPCL for
an explanation of the levels of accuracy.
- Parameters:
- accuracy
- {Number} The level of accuracy during PCL generation