CollisionTraverser
-
class CollisionTraverser
Bases:
NamableThis class manages the traversal through the scene graph to detect collisions. It holds ownership of a number of collider objects, each of which is a
CollisionNodeand an associatedCollisionHandler.When
traverse()is called, it begins at the indicated root and detects all collisions with any of its collider objects against nodes at or below the indicated root, calling the appropriateCollisionHandlerfor each detected collision.Inheritance diagram
-
explicit CollisionTraverser(std::string const &name = "ctrav")
-
CollisionTraverser(CollisionTraverser const&) = default
-
void add_collider(NodePath const &collider, CollisionHandler *handler)
Adds a new
CollisionNode, representing an object that will be tested for collisions into other objects, along with the handler that will serve each detected collision. EachCollisionNodemay be served by only one handler at a time, but a given handler may serve manyCollisionNodes.The handler that serves a particular node may be changed from time to time by calling add_collider() again on the same node.
-
void clear_colliders(void)
Completely empties the set of collision nodes and their associated handlers.
-
void clear_recorder(void)
Removes the
CollisionRecorderfrom the traverser and restores normal low- overhead operation.
-
static TypeHandle get_class_type(void)
-
NodePath get_collider(int n) const
Returns the nth
CollisionNodethat has been added to the traverser viaadd_collider().
-
CollisionHandler *get_handler(NodePath const &collider) const
Returns the handler that is currently assigned to serve the indicated collision node, or NULL if the node is not on the traverser’s set of active nodes.
-
int get_num_colliders(void) const
Returns the number of
CollisionNodesthat have been added to the traverser viaadd_collider().
-
CollisionRecorder *get_recorder(void) const
Returns the
CollisionRecordercurrently assigned, or NULL if no recorder is assigned.
-
bool get_respect_prev_transform(void) const
Returns the flag that indicates whether the prev_transform stored on a node is respected to calculate collisions. See
set_respect_prev_transform().
-
bool has_collider(NodePath const &collider) const
Returns true if the indicated node is current in the set of nodes that will be tested each frame for collisions into other objects.
-
bool has_recorder(void) const
Returns true if the
CollisionTraverserhas aCollisionRecorderobject currently assigned, false otherwise.
-
void hide_collisions(void)
Undoes the effect of a previous call to
show_collisions().
-
void output(std::ostream &out) const
-
bool remove_collider(NodePath const &collider)
Removes the collider (and its associated handler) from the set of
CollisionNodesthat will be tested each frame for collisions into other objects. Returns true if the definition was found and removed, false if it wasn’t present to begin with.
-
void set_recorder(CollisionRecorder *recorder)
Uses the indicated
CollisionRecorderobject to start recording the intersection tests made by each subsequent call totraverse()on this object. A particularCollisionRecorderobject can only record one traverser at a time; if this object has already been assigned to another traverser, that assignment is broken.This is intended to be used in a debugging mode to try to determine what work is being performed by the collision traversal. Usually, attaching a recorder will impose significant runtime overhead.
This does not transfer ownership of the
CollisionRecorderpointer; maintenance of that remains the caller’s responsibility. If theCollisionRecorderis destructed, it will cleanly remove itself from the traverser.
-
void set_respect_prev_transform(bool flag)
Sets the flag that indicates whether the prev_transform stored on a node (as updated via set_fluid_pos(), etc.) is respected to calculate collisions. If this is true, certain types of collision tests will be enhanced by the information about objects in motion. If this is false, objects are always considered to be static. The default is false.
-
CollisionVisualizer *show_collisions(NodePath const &root)
This is a high-level function to create a
CollisionVisualizerobject to render the collision tests performed by this traverser. The supplied root should be any node in the scene graph; typically, the top node (e.g. render). TheCollisionVisualizerwill be attached to this node.
-
void traverse(NodePath const &root)
Perform the traversal. Begins at the indicated root and detects all collisions with any of its collider objects against nodes at or below the indicated root, calling the appropriate
CollisionHandlerfor each detected collision.
-
void write(std::ostream &out, int indent_level) const
-
explicit CollisionTraverser(std::string const &name = "ctrav")
