Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/collide/collisionTraverser.h

Go to the documentation of this file.
00001 // Filename: collisionTraverser.h
00002 // Created by:  drose (16Mar02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef COLLISIONTRAVERSER_H
00020 #define COLLISIONTRAVERSER_H
00021 
00022 #include "pandabase.h"
00023 
00024 #include "collisionHandler.h"
00025 #include "collisionLevelState.h"
00026 
00027 #include "pointerTo.h"
00028 #include "pStatCollector.h"
00029 
00030 #include "pset.h"
00031 
00032 class CollisionNode;
00033 class CollisionRecorder;
00034 class Geom;
00035 class NodePath;
00036 class CollisionEntry;
00037 
00038 ////////////////////////////////////////////////////////////////////
00039 //       Class : CollisionTraverser
00040 // Description : This class manages the traversal through the scene
00041 //               graph to detect collisions.  It holds ownership of a
00042 //               number of collider objects, each of which is a
00043 //               CollisionNode and an associated CollisionHandler.
00044 //
00045 //               When traverse() is called, it begins at the indicated
00046 //               root and detects all collisions with any of its
00047 //               collider objects against nodes at or below the
00048 //               indicated root, calling the appropriate
00049 //               CollisionHandler for each detected collision.
00050 ////////////////////////////////////////////////////////////////////
00051 class EXPCL_PANDA CollisionTraverser {
00052 PUBLISHED:
00053   CollisionTraverser();
00054   ~CollisionTraverser();
00055 
00056   void add_collider(CollisionNode *node, CollisionHandler *handler);
00057   bool remove_collider(CollisionNode *node);
00058   bool has_collider(CollisionNode *node) const;
00059   int get_num_colliders() const;
00060   CollisionNode *get_collider(int n) const;
00061   CollisionHandler *get_handler(CollisionNode *node) const;
00062   void clear_colliders();
00063 
00064   void traverse(const NodePath &root);
00065 
00066 #ifdef DO_COLLISION_RECORDING
00067   void set_recorder(CollisionRecorder *recorder);
00068   INLINE bool has_recorder() const;
00069   INLINE CollisionRecorder *get_recorder() const;
00070   INLINE void clear_recorder();
00071 #endif  // DO_COLLISION_RECORDING
00072 
00073   void output(ostream &out) const;
00074   void write(ostream &out, int indent_level) const;
00075 
00076 private:
00077   void prepare_colliders(CollisionLevelState &state);
00078 
00079   void r_traverse(CollisionLevelState &level_state);
00080 
00081   void compare_collider_to_node(CollisionEntry &entry,
00082                                 const GeometricBoundingVolume *from_parent_gbv,
00083                                 const GeometricBoundingVolume *from_node_gbv,
00084                                 const GeometricBoundingVolume *into_node_gbv);
00085   void compare_collider_to_geom_node(CollisionEntry &entry,
00086                                      const GeometricBoundingVolume *from_parent_gbv,
00087                                      const GeometricBoundingVolume *from_node_gbv,
00088                                      const GeometricBoundingVolume *into_node_gbv);
00089   void compare_collider_to_solid(CollisionEntry &entry,
00090                                  const GeometricBoundingVolume *from_node_gbv,
00091                                  const GeometricBoundingVolume *solid_gbv);
00092   void compare_collider_to_geom(CollisionEntry &entry, Geom *geom,
00093                                 const GeometricBoundingVolume *from_node_gbv,
00094                                 const GeometricBoundingVolume *solid_gbv);
00095 
00096 private:
00097   PT(CollisionHandler) _default_handler;
00098   TypeHandle _graph_type;
00099 
00100   typedef pmap<PT(CollisionNode),  PT(CollisionHandler) > Colliders;
00101   Colliders _colliders;
00102   typedef pvector<CollisionNode *> OrderedColliders;
00103   OrderedColliders _ordered_colliders;
00104 
00105   typedef pmap<PT(CollisionHandler), int> Handlers;
00106   Handlers _handlers;
00107 
00108 #ifdef DO_COLLISION_RECORDING
00109   CollisionRecorder *_recorder;
00110 #endif  // DO_COLLISION_RECORDING
00111 
00112   // Statistics
00113   static PStatCollector _collisions_pcollector;
00114 };
00115 
00116 INLINE ostream &operator << (ostream &out, const CollisionTraverser &trav) {
00117   trav.output(out);
00118   return out;
00119 }
00120 
00121 #include "collisionTraverser.I"
00122 
00123 #endif
00124 

Generated on Fri May 2 00:35:47 2003 for Panda by doxygen1.3