Panda3D

collisionVisualizer.h

00001 // Filename: collisionVisualizer.h
00002 // Created by:  drose (16Apr03)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef COLLISIONVISUALIZER_H
00016 #define COLLISIONVISUALIZER_H
00017 
00018 #include "pandabase.h"
00019 #include "pandaNode.h"
00020 #include "collisionRecorder.h"
00021 #include "collisionSolid.h"
00022 #include "nodePath.h"
00023 #include "pmap.h"
00024 
00025 #ifdef DO_COLLISION_RECORDING
00026 
00027 ////////////////////////////////////////////////////////////////////
00028 //       Class : CollisionVisualizer
00029 // Description : This class is used to help debug the work the
00030 //               collisions system is doing.  It shows the polygons
00031 //               that are detected as collisions, as well as those
00032 //               that are simply considered for collisions.
00033 //
00034 //               It may be parented anywhere in the scene graph where
00035 //               it will be rendered to achieve this.
00036 ////////////////////////////////////////////////////////////////////
00037 class EXPCL_PANDA_COLLIDE CollisionVisualizer : public PandaNode, public CollisionRecorder {
00038 PUBLISHED:
00039   CollisionVisualizer(const string &name);
00040   virtual ~CollisionVisualizer();
00041 
00042   INLINE void set_point_scale(PN_stdfloat point_scale);
00043   INLINE PN_stdfloat get_point_scale() const;
00044 
00045   INLINE void set_normal_scale(PN_stdfloat normal_scale);
00046   INLINE PN_stdfloat get_normal_scale() const;
00047 
00048   void clear();
00049 
00050 public:
00051   // from parent class PandaNode.
00052   virtual PandaNode *make_copy() const;
00053   virtual bool cull_callback(CullTraverser *trav, CullTraverserData &data);
00054   virtual bool is_renderable() const;
00055   virtual void output(ostream &out) const;
00056 
00057   // from parent class CollisionRecorder.
00058   virtual void begin_traversal();
00059   virtual void collision_tested(const CollisionEntry &entry, bool detected);
00060 
00061   // To disambiguate the multiple inheritance from TypedObject.
00062   INLINE TypedObject *as_typed_object();
00063   INLINE const TypedObject *as_typed_object() const;
00064 
00065 private:
00066   CPT(RenderState) get_viz_state();
00067 
00068 private:
00069   class SolidInfo {
00070   public:
00071     INLINE SolidInfo();
00072     int _detected_count;
00073     int _missed_count;
00074   };
00075   typedef pmap<CPT(CollisionSolid), SolidInfo> Solids;
00076 
00077   class CollisionPoint {
00078   public:
00079     LPoint3 _surface_point;
00080     LVector3 _surface_normal;
00081     LPoint3 _interior_point;
00082   };
00083   typedef pvector<CollisionPoint> Points;
00084 
00085   class VizInfo {
00086   public:
00087     Solids _solids;
00088     Points _points;
00089   };
00090 
00091   typedef pmap<CPT(TransformState), VizInfo> Data;
00092   Data _data;
00093 
00094   PN_stdfloat _point_scale;
00095   PN_stdfloat _normal_scale;
00096 
00097 public:
00098   static TypeHandle get_class_type() {
00099     return _type_handle;
00100   }
00101 
00102   static void init_type() {
00103     PandaNode::init_type();
00104     CollisionRecorder::init_type();
00105     register_type(_type_handle, "CollisionVisualizer",
00106                   PandaNode::get_class_type(),
00107                   CollisionRecorder::get_class_type());
00108   }
00109   virtual TypeHandle get_type() const {
00110     return get_class_type();
00111   }
00112   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00113 
00114 private:
00115   static TypeHandle _type_handle;
00116 };
00117 
00118 #include "collisionVisualizer.I"
00119 
00120 #endif  // DO_COLLISION_RECORDING  
00121 
00122 #endif
 All Classes Functions Variables Enumerations