Panda3D

Loading...
Searching...
No Matches
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.
void | clear_colliders ()
| Completely empties the set of collision nodes and their associated handlers.
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.
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.
bool | has_recorder () const
void | hide_collisions ()
| Undoes the effect of a previous call to show_collisions().
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.
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.
void | traverse (const NodePath &root)
| Perform the traversal.
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.
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.
void | output (std::ostream &out) const
| Outputs the Namable.
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().
| get_num_colliders
| Returns the number of CollisionNodes that have been added to the traverser via add_collider().
| get_recorder
| get_respect_prev_transform
| Returns the flag that indicates whether the prev_transform stored on a node is respected to calculate collisions.
| 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.
| 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.
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.

## Constructor & Destructor Documentation

## ◆ CollisionTraverser()

CollisionTraverser::CollisionTraverser | ( | const std::string & | name = "ctrav" | ) |
| explicit

Definition at line 71 of file collisionTraverser.cxx.

## ◆ ~CollisionTraverser()

CollisionTraverser::~CollisionTraverser | ( |  | ) |

Definition at line 85 of file collisionTraverser.cxx.

## 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.

References PandaNode::is_collision_node(), NodePath::is_empty(), and NodePath::node().

## ◆ 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_class_type()

static TypeHandle CollisionTraverser::get_class_type | ( |  | ) |
| inline static

Definition at line 162 of file collisionTraverser.h.

## ◆ 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().

## ◆ init_type()

static void CollisionTraverser::init_type | ( |  | ) |
| inline static

Definition at line 165 of file collisionTraverser.h.

## ◆ output()

void CollisionTraverser::output | ( | std::ostream & | out | ) | const

Definition at line 436 of file collisionTraverser.cxx.

## ◆ 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 CollisionBox::flush_level(), CollisionCapsule::flush_level(), CollisionPlane::flush_level(), CollisionPolygon::flush_level(), CollisionSphere::flush_level(), CollisionLevelState< BitMaskNative >::get_max_colliders(), and CollisionLevelState< DoubleBitMaskNative >::get_max_colliders().

## ◆ write()

void CollisionTraverser::write | ( | std::ostream & | out,
|  | int | indent_level ) const

Definition at line 445 of file collisionTraverser.cxx.

## Friends And Related Symbol Documentation

## ◆ SortByColliderSort

friend class SortByColliderSort
| friend

Definition at line 172 of file collisionTraverser.h.

## Member Data Documentation

## ◆ clear_recorder

CollisionTraverser::clear_recorder

Definition at line 76 of file collisionTraverser.h.

## ◆ 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_recorder

CollisionTraverser::get_recorder

Definition at line 76 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.

## ◆ has_recorder

CollisionTraverser::has_recorder

Definition at line 76 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