collisionVisualizer.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #ifndef COLLISIONVISUALIZER_H
  14. #define COLLISIONVISUALIZER_H
  15. #include "pandabase.h"
  16. #include "pandaNode.h"
  17. #include "collisionRecorder.h"
  18. #include "collisionSolid.h"
  19. #include "nodePath.h"
  20. #include "pmap.h"
  21. #include "lightMutex.h"
  22. #ifdef DO_COLLISION_RECORDING
  23. /**
  24. * This class is used to help debug the work the collisions system is doing.
  25. * It shows the polygons that are detected as collisions, as well as those
  26. * that are simply considered for collisions.
  27. *
  28. * It may be parented anywhere in the scene graph where it will be rendered to
  29. * achieve this.
  30. */
  31. class EXPCL_PANDA_COLLIDE CollisionVisualizer : public PandaNode, public CollisionRecorder {
  32. PUBLISHED:
  33. explicit CollisionVisualizer(const string &name);
  34. CollisionVisualizer(const CollisionVisualizer &copy);
  35. virtual ~CollisionVisualizer();
  36. INLINE void set_point_scale(PN_stdfloat point_scale);
  37. INLINE PN_stdfloat get_point_scale() const;
  38. INLINE void set_normal_scale(PN_stdfloat normal_scale);
  39. INLINE PN_stdfloat get_normal_scale() const;
  40. void clear();
  41. PUBLISHED:
  42. MAKE_PROPERTY(point_scale, get_point_scale, set_point_scale);
  43. MAKE_PROPERTY(normal_scale, get_normal_scale, set_normal_scale);
  44. public:
  45. // from parent class PandaNode.
  46. virtual PandaNode *make_copy() const;
  47. virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
  48. virtual bool is_renderable() const;
  49. virtual void output(ostream &out) const;
  50. // from parent class CollisionRecorder.
  51. virtual void begin_traversal();
  52. virtual void collision_tested(const CollisionEntry &entry, bool detected);
  53. // To disambiguate the multiple inheritance from TypedObject.
  54. INLINE TypedObject *as_typed_object();
  55. INLINE const TypedObject *as_typed_object() const;
  56. private:
  57. CPT(RenderState) get_viz_state();
  58. private:
  59. class SolidInfo {
  60. public:
  61. INLINE SolidInfo();
  62. int _detected_count;
  63. int _missed_count;
  64. };
  65. typedef pmap<CPT(CollisionSolid), SolidInfo> Solids;
  66. class CollisionPoint {
  67. public:
  68. LPoint3 _surface_point;
  69. LVector3 _surface_normal;
  70. LPoint3 _interior_point;
  71. };
  72. typedef pvector<CollisionPoint> Points;
  73. class VizInfo {
  74. public:
  75. Solids _solids;
  76. Points _points;
  77. };
  78. LightMutex _lock;
  79. typedef pmap<CPT(TransformState), VizInfo> Data;
  80. Data _data;
  81. PN_stdfloat _point_scale;
  82. PN_stdfloat _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