Class R.collision.broadphase.AbstractCollisionModel
Extends
R.engine.BaseObject.
An abstract class to represent broad-phase collision models. Broad-phase models
contain game-world objects and can report on potential objects within a defined
space of that container.
Defined in: abstractcollisionmodel.js.
Constructor Attributes | Constructor Name and Description |
---|---|
R.collision.broadphase.AbstractCollisionModel(name, width, height)
Abstract class for all broad-phase collision models
|
Field Attributes | Field Name and Description |
---|---|
The maximum length of a cast ray (1000)
|
Method Attributes | Method Name and Description |
---|---|
addObject(obj, point)
Add an object to the node which corresponds to the position of the object provided
provided.
|
|
castRay(fromPoint, direction, testFn)
Cast a ray through the collision model, looking for collisions along the
ray.
|
|
Clear all of the spatial data on the given game object.
|
|
findNodePoint(point)
[ABSTRACT] Find the node that contains the specified point.
|
|
Get the class name of this object
|
|
Get the height of the model's world space.
|
|
Returns all objects within the collision model.
|
|
getObjectsOfType(clazz)
Returns all objects within the spatial container of a particular
class type.
|
|
getObjectSpatialData(obj, key)
Get the spatial data for the game object.
|
|
getPCL(point)
Returns a potential collision list (PCL) of objects that are contained
within the defined sub-space of the container.
|
|
getRoot()
Get the root object of the model.
|
|
getWidth()
Get the width of the model's world space.
|
|
normalizePoint(point)
Normalize a point to keep it within the boundaries of the collision model.
|
|
query(testFn)
Query the collision model using a testing function.
|
|
queryNear(point, radius)
Query the collision model for objects near a point.
|
|
release()
Release the spatial container back into the pool for reuse
|
|
removeObject(obj)
Remove an object from the collision model.
|
|
reset()
[ABSTRACT] Reset the collision model, removing any references to objects
from all collision nodes.
|
|
setObjectSpatialData(obj, key, value)
Set a key, within the game object's spatial data, to a specific value.
|
|
setRoot(root)
Set the root object of the model.
|
- Methods borrowed from class R.engine.BaseObject:
- addEvent, addEvents, destroy, getElement, jQ, removeEvent, setElement, triggerEvent, update
- Methods borrowed from class R.engine.PooledObject:
- clearObjectDataModel, getId, getName, getObjectDataModel, getProperties, isDestroyed, setName, setObjectDataModel, toString, toXML
Class Detail
R.collision.broadphase.AbstractCollisionModel(name, width, height)
Abstract class for all broad-phase collision models
- Parameters:
- name
- {String} The name of the model
- width
- {Number} The total width of the model's space
- height
- {Number} The total height of the model's space
Field Detail
MAX_RAY_LENGTH
The maximum length of a cast ray (1000)
Method Detail
addObject(obj, point)
Add an object to the node which corresponds to the position of the object provided
provided. Adding an object at a specific point will remove it from whatever
node it was last in.
- Parameters:
- obj
- {R.engine.BaseObject} The object to add to the collision model
- point
- {R.math.Point2D} The world position where the object is
{R.struct.CollisionData}
castRay(fromPoint, direction, testFn)
Cast a ray through the collision model, looking for collisions along the
ray. If a collision is found, a R.struct.CollisionData object
will be returned or
null
if otherwise. If the object being
tested has a convex hull, that will be used to test for collision with
the ray. Otherwise, its world box will be used.
If a collision occurs, the value stored in R.struct.CollisionData#shape1
is the object which was collided with. The value in R.struct.CollisionData#impulseVector
is the point at which the intersection was determined.
- Parameters:
- fromPoint
- {R.math.Point2D} The origination of the ray
- direction
- {R.math.Vector2D} A vector whose magnitude specifies the direction and length of the ray being cast. The ray will be truncated at #MAX_RAY_LENGTH.
- testFn Optional
- {Function} A test function which will be executed when a collision occurs. The
argument to the function will be a R.struct.CollisionData. Returning
true
will indicate that the raycast testing should stop,false
to continue testing.
- Returns:
- {R.struct.CollisionData} The collision info, or
null
if no collision would occur.
clearObjectSpatialData(obj)
Clear all of the spatial data on the given game object.
- Parameters:
- obj
- {R.engine.BaseObject} The object which has the data model
{R.spatial.AbstractSpatialNode}
findNodePoint(point)
[ABSTRACT] Find the node that contains the specified point.
- Parameters:
- point
- {R.math.Point2D} The point to locate the node for
- Returns:
- {R.spatial.AbstractSpatialNode}
{String}
getClassName()
Get the class name of this object
- Returns:
- {String} "R.collision.broadphase.AbstractCollisionModel"
{Number}
getHeight()
Get the height of the model's world space.
- Returns:
- {Number} The height
{R.struct.Container}
getObjects()
Returns all objects within the collision model.
- Returns:
- {R.struct.Container} A container of all objects in the model
{Array}
getObjectsOfType(clazz)
Returns all objects within the spatial container of a particular
class type.
- Parameters:
- clazz
- {Object} A class type to restrict the collection to
- Returns:
- {Array} An array of objects in the container, filtered by class
getObjectSpatialData(obj, key)
Get the spatial data for the game object. If key is provided, only the
data for key will be returned. If the data has not yet been assigned,
an empty object will be created to contain the data.
- Parameters:
- obj
- {R.engine.BaseObject} The object which has the data
- key Optional
- {String} Optional key which contains the data, or null for the entire data model.
{R.struct.Container}
getPCL(point)
Returns a potential collision list (PCL) of objects that are contained
within the defined sub-space of the container.
- Parameters:
- point
- {R.math.Point2D} The point to begin the search at.
- Returns:
- {R.struct.Container} An empty PCL
{Object}
getRoot()
Get the root object of the model.
- Returns:
- {Object} The root
{Number}
getWidth()
Get the width of the model's world space.
- Returns:
- {Number} The width
{R.math.Point2D}
normalizePoint(point)
Normalize a point to keep it within the boundaries of the collision model.
- Parameters:
- point
- {R.math.Point2D} The point
- Returns:
- {R.math.Point2D} The normalized point
{Array}
query(testFn)
Query the collision model using a testing function. All objects in the
model will be passed through the function, and if the function returns
true
, indicating it passed the test, it will be included
in the list.
- Parameters:
- testFn
- {Function} The testing function
- Returns:
- {Array} An array of objects in the container which pass the test
{Array}
queryNear(point, radius)
Query the collision model for objects near a point. Specify the point
and the radius from that point to test. The test will be performed
against the position of the object being tested, not its boundaries.
- Parameters:
- point
- {R.math.Point2D}
- radius
- {Number}
- Returns:
- {Array} An array of objects in the container which satisfy the query
release()
Release the spatial container back into the pool for reuse
removeObject(obj)
Remove an object from the collision model.
- Parameters:
- obj
- {R.engine.BaseObject} The object to remove
reset()
[ABSTRACT] Reset the collision model, removing any references to objects
from all collision nodes.
setObjectSpatialData(obj, key, value)
Set a key, within the game object's spatial data, to a specific value. This allows a
collision system, or model, to store related information directly on a game object.
The data can be retrieved, as needed, from within the collision system or model.
- Parameters:
- obj
- {R.engine.BaseObject} The object to receive the data
- key
- {String} The key to set the data for
- value
- {Object} The value to assign to the key
setRoot(root)
Set the root object of the model.
- Parameters:
- root
- {Object} The root object of this model