Panda3D

Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
CollisionTraverser Class Reference

This class manages the traversal through the scene graph to detect collisions. More...

`#include "collisionTraverser.h"`

Inheritance diagram for CollisionTraverser:

## Public Member Functions
| CollisionTraverser (const std::string &name="ctrav")
void | add_collider (const NodePath &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. More...
void | clear_colliders ()
| Completely empties the set of collision nodes and their associated handlers. More...
void | clear_recorder ()
NodePath | get_collider (int n) const
CollisionHandler * | get_handler (const NodePath &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. More...
int | get_num_colliders () const
CollisionRecorder * | get_recorder () const
bool | get_respect_prev_transform () const
bool | has_collider (const NodePath &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. More...
bool | has_recorder () const
void | hide_collisions ()
| Undoes the effect of a previous call to show_collisions(). More...
void | output (std::ostream &out) const
bool | remove_collider (const NodePath &collider)
| Removes the collider (and its associated handler) from the set of CollisionNodes that will be tested each frame for collisions into other objects. More...
void | set_recorder (CollisionRecorder *recorder)
void | set_respect_prev_transform (bool flag)
CollisionVisualizer * | show_collisions (const NodePath &root)
| This is a high-level function to create a CollisionVisualizer object to render the collision tests performed by this traverser. More...
void | traverse (const NodePath &root)
| Perform the traversal. More...
void | write (std::ostream &out, int indent_level) const
Public Member Functions inherited from Namable
| Namable (const std::string &initial_name="")
void | clear_name ()
| Resets the Namable's name to empty. More...
const std::string & | get_name () const
bool | has_name () const
| Returns true if the Namable has a nonempty name set, false if the name is empty. More...
void | output (std::ostream &out) const
| Outputs the Namable. More...
void | set_name (const std::string &name)
Public Member Functions inherited from MemoryBase
void | operator delete (void *, void *)
void | operator delete (void *ptr)
void | operator delete[] (void *, void *)
void | operator delete[] (void *ptr)
void * | operator new (size_t size)
void * | operator new (size_t size, void *ptr)
void * | operator new[] (size_t size)
void * | operator new[] (size_t size, void *ptr)

## Static Public Member Functions
static TypeHandle | get_class_type ()
static void | init_type ()
Static Public Member Functions inherited from Namable
static TypeHandle | get_class_type ()
static void | init_type ()

## Public Attributes
| clear_recorder
| get_collider
| Returns the nth CollisionNode that has been added to the traverser via add_collider(). More...
| get_num_colliders
| Returns the number of CollisionNodes that have been added to the traverser via add_collider(). More...
| get_recorder
| get_respect_prev_transform
| Returns the flag that indicates whether the prev_transform stored on a node is respected to calculate collisions. More...
| has_recorder
| set_recorder
| Uses the indicated CollisionRecorder object to start recording the intersection tests made by each subsequent call to traverse() on this object. More...
| set_respect_prev_transform
| 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. More...
Public Attributes inherited from Namable
| get_name
| set_name

## Friends
class | SortByColliderSort

## Detailed Description

This 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 CollisionNode and an associated CollisionHandler.

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 appropriate CollisionHandler for each detected collision.

Definition at line 46 of file collisionTraverser.h.

## Member Function Documentation

## ◆ add_collider()

void CollisionTraverser::add_collider | ( | const NodePath & | 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.

Each CollisionNode may be served by only one handler at a time, but a given handler may serve many CollisionNodes.

The handler that serves a particular node may be changed from time to time by calling add_collider() again on the same node.

Definition at line 101 of file collisionTraverser.cxx.

## ◆ clear_colliders()

void CollisionTraverser::clear_colliders | ( |  | ) |

Completely empties the set of collision nodes and their associated handlers.

Definition at line 243 of file collisionTraverser.cxx.

## ◆ get_handler()

CollisionHandler * CollisionTraverser::get_handler | ( | const NodePath & | 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.

Definition at line 230 of file collisionTraverser.cxx.

## ◆ has_collider()

bool CollisionTraverser::has_collider | ( | const NodePath & | 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.

Definition at line 198 of file collisionTraverser.cxx.

## ◆ hide_collisions()

void CollisionTraverser::hide_collisions | ( |  | ) |

Undoes the effect of a previous call to show_collisions().

Definition at line 421 of file collisionTraverser.cxx.

Referenced by show_collisions().

## ◆ remove_collider()

bool CollisionTraverser::remove_collider | ( | const NodePath & | collider | ) |

Removes the collider (and its associated handler) from the set of CollisionNodes that 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.

Definition at line 157 of file collisionTraverser.cxx.

## ◆ show_collisions()

CollisionVisualizer * CollisionTraverser::show_collisions | ( | const NodePath & | root | ) |

This is a high-level function to create a CollisionVisualizer object 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). The CollisionVisualizer will be attached to this node.

Definition at line 405 of file collisionTraverser.cxx.

References NodePath::attach_new_node(), hide_collisions(), and set_recorder.

## ◆ traverse()

void CollisionTraverser::traverse | ( | const NodePath & | 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 CollisionHandler for each detected collision.

Definition at line 256 of file collisionTraverser.cxx.

References CollisionLevelState< MaskType >::get_max_colliders().

## Member Data Documentation

## ◆ get_collider

NodePath CollisionTraverser::get_collider

Returns the nth CollisionNode that has been added to the traverser via add_collider().

Definition at line 63 of file collisionTraverser.h.

## ◆ get_num_colliders

int CollisionTraverser::get_num_colliders

Returns the number of CollisionNodes that have been added to the traverser via add_collider().

Definition at line 63 of file collisionTraverser.h.

## ◆ get_respect_prev_transform

bool CollisionTraverser::get_respect_prev_transform
| inline

Returns the flag that indicates whether the prev_transform stored on a node is respected to calculate collisions.

See set_respect_prev_transform().

Definition at line 54 of file collisionTraverser.h.

## ◆ set_recorder

void CollisionTraverser::set_recorder

Uses the indicated CollisionRecorder object to start recording the intersection tests made by each subsequent call to traverse() on this object.

A particular CollisionRecorder object 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 CollisionRecorder pointer; maintenance of that remains the caller's responsibility. If the CollisionRecorder is destructed, it will cleanly remove itself from the traverser.

Definition at line 76 of file collisionTraverser.h.

Referenced by show_collisions().

## ◆ set_respect_prev_transform

void CollisionTraverser::set_respect_prev_transform
| inline

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.

Definition at line 54 of file collisionTraverser.h.

The documentation for this class was generated from the following files:

- panda/src/collide/collisionTraverser.h
- panda/src/collide/collisionTraverser.cxx
- panda/src/collide/collisionTraverser.I