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