collisionVisualizer.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Filename: collisionVisualizer.h
  2. // Created by: drose (16Apr03)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
  8. //
  9. // All use of this software is subject to the terms of the Panda 3d
  10. // Software license. You should have received a copy of this license
  11. // along with this source code; you will also find a current copy of
  12. // the license at http://etc.cmu.edu/panda3d/docs/license/ .
  13. //
  14. // To contact the maintainers of this program write to
  15. // [email protected] .
  16. //
  17. ////////////////////////////////////////////////////////////////////
  18. #ifndef COLLISIONVISUALIZER_H
  19. #define COLLISIONVISUALIZER_H
  20. #include "pandabase.h"
  21. #include "pandaNode.h"
  22. #include "collisionRecorder.h"
  23. #include "collisionSolid.h"
  24. #include "nodePath.h"
  25. #include "pmap.h"
  26. #ifdef DO_COLLISION_RECORDING
  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. INLINE void set_point_scale(float point_scale);
  42. INLINE float get_point_scale() const;
  43. INLINE void set_normal_scale(float normal_scale);
  44. INLINE float get_normal_scale() const;
  45. void clear();
  46. public:
  47. // from parent class PandaNode.
  48. virtual PandaNode *make_copy() const;
  49. virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
  50. virtual void output(ostream &out) const;
  51. // from parent class CollisionRecorder.
  52. virtual void begin_traversal();
  53. virtual void collision_tested(const CollisionEntry &entry, bool detected);
  54. // To disambiguate the multiple inheritance from TypedObject.
  55. INLINE TypedObject *as_typed_object();
  56. INLINE const TypedObject *as_typed_object() const;
  57. private:
  58. CPT(RenderState) get_viz_state();
  59. private:
  60. class SolidInfo {
  61. public:
  62. INLINE SolidInfo();
  63. int _detected_count;
  64. int _missed_count;
  65. };
  66. typedef pmap<CPT(CollisionSolid), SolidInfo> Solids;
  67. class CollisionPoint {
  68. public:
  69. LPoint3f _surface_point;
  70. LVector3f _surface_normal;
  71. LPoint3f _interior_point;
  72. };
  73. typedef pvector<CollisionPoint> Points;
  74. class VizInfo {
  75. public:
  76. Solids _solids;
  77. Points _points;
  78. };
  79. typedef pmap<CPT(TransformState), VizInfo> Data;
  80. Data _data;
  81. float _point_scale;
  82. float _normal_scale;
  83. public:
  84. static TypeHandle get_class_type() {
  85. return _type_handle;
  86. }
  87. static void init_type() {
  88. PandaNode::init_type();
  89. CollisionRecorder::init_type();
  90. register_type(_type_handle, "CollisionVisualizer",
  91. PandaNode::get_class_type(),
  92. CollisionRecorder::get_class_type());
  93. }
  94. virtual TypeHandle get_type() const {
  95. return get_class_type();
  96. }
  97. virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
  98. private:
  99. static TypeHandle _type_handle;
  100. };
  101. #include "collisionVisualizer.I"
  102. #endif // DO_COLLISION_RECORDING
  103. #endif