Class Index | File Index

Classes


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.

A spatial grid is defined by the size of the space and the number of divisions within that space. A smaller PCL will result from a larger number of divisions, but the amount of data required to store the cells also increases. Also, larger numbers of divisions means that as objects move, the determination of which cell the object is within increases as well.
Defined in: spatialgrid.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
R.collision.broadphase.SpatialGrid(width, height, divisions)
Create an instance of a spatial grid model
Field Summary
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 Summary
Method Attributes Method Name and Description
 
Dump the cached PCLs to the console so they can be inspected.
 
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.
 
Releases the spatial grid back into the object pool.
 
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: For example, if you had a 3x3 grid with the object in the center node, the nodes marked below would be included in the result set:
 +---+---+---+
 | 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

Documentation generated by JsDoc Toolkit 2.4.0 on Mon Mar 18 2013 16:09:15 GMT-0400 (EDT)