Panda3D
 All Classes Functions Variables Enumerations
collisionVisualizer.h
1 // Filename: collisionVisualizer.h
2 // Created by: drose (16Apr03)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef COLLISIONVISUALIZER_H
16 #define COLLISIONVISUALIZER_H
17 
18 #include "pandabase.h"
19 #include "pandaNode.h"
20 #include "collisionRecorder.h"
21 #include "collisionSolid.h"
22 #include "nodePath.h"
23 #include "pmap.h"
24 
25 #ifdef DO_COLLISION_RECORDING
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : CollisionVisualizer
29 // Description : This class is used to help debug the work the
30 // collisions system is doing. It shows the polygons
31 // that are detected as collisions, as well as those
32 // that are simply considered for collisions.
33 //
34 // It may be parented anywhere in the scene graph where
35 // it will be rendered to achieve this.
36 ////////////////////////////////////////////////////////////////////
37 class EXPCL_PANDA_COLLIDE CollisionVisualizer : public PandaNode, public CollisionRecorder {
38 PUBLISHED:
39  CollisionVisualizer(const string &name);
40  virtual ~CollisionVisualizer();
41 
42  INLINE void set_point_scale(PN_stdfloat point_scale);
43  INLINE PN_stdfloat get_point_scale() const;
44 
45  INLINE void set_normal_scale(PN_stdfloat normal_scale);
46  INLINE PN_stdfloat get_normal_scale() const;
47 
48  void clear();
49 
50 public:
51  // from parent class PandaNode.
52  virtual PandaNode *make_copy() const;
53  virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
54  virtual bool is_renderable() const;
55  virtual void output(ostream &out) const;
56 
57  // from parent class CollisionRecorder.
58  virtual void begin_traversal();
59  virtual void collision_tested(const CollisionEntry &entry, bool detected);
60 
61  // To disambiguate the multiple inheritance from TypedObject.
62  INLINE TypedObject *as_typed_object();
63  INLINE const TypedObject *as_typed_object() const;
64 
65 private:
66  CPT(RenderState) get_viz_state();
67 
68 private:
69  class SolidInfo {
70  public:
71  INLINE SolidInfo();
72  int _detected_count;
73  int _missed_count;
74  };
76 
77  class CollisionPoint {
78  public:
79  LPoint3 _surface_point;
80  LVector3 _surface_normal;
81  LPoint3 _interior_point;
82  };
83  typedef pvector<CollisionPoint> Points;
84 
85  class VizInfo {
86  public:
87  Solids _solids;
88  Points _points;
89  };
90 
92  Data _data;
93 
94  PN_stdfloat _point_scale;
95  PN_stdfloat _normal_scale;
96 
97 public:
98  static TypeHandle get_class_type() {
99  return _type_handle;
100  }
101 
102  static void init_type() {
103  PandaNode::init_type();
104  CollisionRecorder::init_type();
105  register_type(_type_handle, "CollisionVisualizer",
106  PandaNode::get_class_type(),
107  CollisionRecorder::get_class_type());
108  }
109  virtual TypeHandle get_type() const {
110  return get_class_type();
111  }
112  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
113 
114 private:
115  static TypeHandle _type_handle;
116 };
117 
118 #include "collisionVisualizer.I"
119 
120 #endif // DO_COLLISION_RECORDING
121 
122 #endif
A basic node of the scene graph or data graph.
Definition: pandaNode.h:72
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
This collects together the pieces of data that are accumulated for each node while walking the scene ...
virtual PandaNode * make_copy() const
Returns a newly-allocated PandaNode that is a shallow copy of this one.
Definition: pandaNode.cxx:604
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition: typedObject.h:98
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:39
Defines a single collision event.
virtual bool is_renderable() const
Returns true if there is some value to visiting this particular node during the cull traversal for an...
Definition: pandaNode.cxx:578
This represents a unique collection of RenderAttrib objects that correspond to a particular renderabl...
Definition: renderState.h:53
TypedObject * as_typed_object()
Returns the object, upcast (if necessary) to a TypedObject pointer.
Definition: typedObject.I:99
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This object performs a depth-first traversal of the scene graph, with optional view-frustum culling...
Definition: cullTraverser.h:48
virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data)
This function will be called during the cull traversal to perform any additional operations that shou...
Definition: pandaNode.cxx:477