Panda3D
bulletDebugNode.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 bulletDebugNode.h
10  * @author enn0x
11  * @date 2010-01-23
12  */
13 
14 #ifndef __BULLET_DEBUG_NODE_H__
15 #define __BULLET_DEBUG_NODE_H__
16 
17 #include "pandabase.h"
18 
19 #include "pandaNode.h"
20 
21 #include "bullet_includes.h"
22 
23 class CullTraverser;
24 class CullTraverserData;
25 
26 /**
27  *
28  */
29 class EXPCL_PANDABULLET BulletDebugNode : public PandaNode {
30 PUBLISHED:
31  explicit BulletDebugNode(const char *name="debug");
32  INLINE ~BulletDebugNode();
33 
34  virtual void draw_mask_changed();
35 
36  INLINE void show_wireframe(bool show);
37  INLINE void show_constraints(bool show);
38  INLINE void show_bounding_boxes(bool show);
39  INLINE void show_normals(bool show);
40  INLINE bool get_show_wireframe() const;
41  INLINE bool get_show_constraints() const;
42  INLINE bool get_show_bounding_boxes() const;
43  INLINE bool get_show_normals() const;
44 
45  MAKE_PROPERTY(wireframe, get_show_wireframe, show_wireframe);
46  MAKE_PROPERTY(constraints, get_show_constraints, show_constraints);
47  MAKE_PROPERTY(bounding_boxes, get_show_bounding_boxes, show_bounding_boxes);
48  MAKE_PROPERTY(normals, get_show_normals, show_normals);
49 
50 public:
51  virtual bool safe_to_flatten() const;
52  virtual bool safe_to_transform() const;
53  virtual bool safe_to_modify_transform() const;
54  virtual bool safe_to_combine() const;
55  virtual bool safe_to_combine_children() const;
56  virtual bool safe_to_flatten_below() const;
57 
58  virtual bool is_renderable() const;
59  virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data);
60 
61 private:
62  void do_sync_b2p(btDynamicsWorld *world);
63 
64  struct Line {
65  LVecBase3 _p0;
66  LVecBase3 _p1;
67  UnalignedLVecBase4 _color;
68  };
69 
70  struct Triangle {
71  LVecBase3 _p0;
72  LVecBase3 _p1;
73  LVecBase3 _p2;
74  UnalignedLVecBase4 _color;
75  };
76 
77  class DebugDraw : public btIDebugDraw {
78 
79  public:
80  DebugDraw() {};
81 
82  virtual void setDebugMode(int mode);
83  virtual int getDebugMode() const;
84  virtual void reportErrorWarning(const char *warning);
85 
86  virtual void drawLine(const btVector3 &from, const btVector3 &to,
87  const btVector3 &color);
88  virtual void drawContactPoint(const btVector3 &point,
89  const btVector3 &normal, btScalar distance, int lifetime,
90  const btVector3 &color);
91  virtual void draw3dText(const btVector3 &location, const char *text);
92  virtual void drawTriangle(const btVector3 &v0, const btVector3 &v1,
93  const btVector3 &v2, const btVector3 &color, btScalar);
94  virtual void drawTriangle(const btVector3 &v0, const btVector3 &v1,
95  const btVector3 &v2, const btVector3 &n0, const btVector3 &n1,
96  const btVector3 &n2, const btVector3 &color, btScalar alpha);
97  virtual void drawSphere(btScalar radius, const btTransform &transform,
98  const btVector3 &color);
99 
100  public:
101  pvector<Line> _lines;
102  pvector<Triangle> _triangles;
103 
104  bool _normals;
105  int _mode;
106  };
107 
108  DebugDraw _drawer;
109 
110  bool _debug_stale;
111  btDynamicsWorld *_debug_world;
112  PT(Geom) _debug_lines;
113  PT(Geom) _debug_triangles;
114 
115  bool _wireframe;
116  bool _constraints;
117  bool _bounds;
118 
119  friend class BulletWorld;
120 
121  static PStatCollector _pstat_debug;
122 
123 public:
124  static void register_with_read_factory();
125  virtual void write_datagram(BamWriter *manager, Datagram &dg);
126 
127 protected:
128  static TypedWritable *make_from_bam(const FactoryParams &params);
129  void fillin(DatagramIterator &scan, BamReader *manager);
130 
131 public:
132  static TypeHandle get_class_type() {
133  return _type_handle;
134  }
135  static void init_type() {
136  PandaNode::init_type();
137  register_type(_type_handle, "BulletDebugNode",
138  PandaNode::get_class_type());
139  }
140  virtual TypeHandle get_type() const {
141  return get_class_type();
142  }
143  virtual TypeHandle force_init_type() {
144  init_type();
145  return get_class_type();
146  }
147 
148 private:
149  static TypeHandle _type_handle;
150 };
151 
152 #include "bulletDebugNode.I"
153 
154 #endif // __BULLET_DEBUG_NODE_H__
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A basic node of the scene graph or data graph.
Definition: pandaNode.h:64
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
Definition: pandaNode.cxx:3589
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:110
virtual bool safe_to_modify_transform() const
Returns true if it is safe to automatically adjust the transform on this kind of node.
Definition: pandaNode.cxx:223
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
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.
virtual bool safe_to_combine_children() const
Returns true if it is generally safe to combine the children of this PandaNode with each other.
Definition: pandaNode.cxx:244
This collects together the pieces of data that are accumulated for each node while walking the scene ...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:63
static void register_with_read_factory()
Tells the BamReader how to create objects of type PandaNode.
Definition: pandaNode.cxx:3580
virtual bool safe_to_combine() const
Returns true if it is generally safe to combine this particular kind of PandaNode with other kinds of...
Definition: pandaNode.cxx:234
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A lightweight class that represents a single element that may be timed and/or counted via stats.
A container for geometry primitives.
Definition: geom.h:54
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
virtual void add_for_draw(CullTraverser *trav, CullTraverserData &data)
Adds the node's contents to the CullResult we are building up during the cull traversal,...
Definition: pandaNode.cxx:478
virtual bool safe_to_flatten_below() const
Returns true if a flatten operation may safely continue past this node, or false if nodes below this ...
Definition: pandaNode.cxx:253
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A class to retrieve the individual data elements previously stored in a Datagram.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
virtual bool safe_to_transform() const
Returns true if it is generally safe to transform this particular kind of PandaNode by calling the xf...
Definition: pandaNode.cxx:210
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
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
virtual bool safe_to_flatten() const
Returns true if it is generally safe to flatten out this particular kind of PandaNode by duplicating ...
Definition: pandaNode.cxx:201