Tinman  1.0
physicsdebugdrawer.h
Go to the documentation of this file.
1 // adaptation of the code found here: https://github.com/gman0/Quarter-Life
2 
3 #ifndef PHYSICS_DEBUG_DRAW
4 #define PHYSICS_DEBUG_DRAW
5 
6 #include <cmath>
7 #include <bullet/btBulletDynamicsCommon.h>
8 #include <OGRE/Ogre.h>
9 
10 typedef std::vector<Ogre::Vector3> Vector3Array;
11 
12 class DynamicRenderable : public Ogre::SimpleRenderable
13 {
14 public:
18  virtual ~DynamicRenderable();
19 
28  void initialize(Ogre::RenderOperation::OperationType operationType,
29  bool useIndices);
30 
32  virtual Ogre::Real getBoundingRadius(void) const;
34  virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const;
35 
36 protected:
41 
47  virtual void createVertexDeclaration() = 0;
48 
63  void prepareHardwareBuffers(size_t vertexCount, size_t indexCount);
64 
71  virtual void fillHardwareBuffers() = 0;
72 };
73 
74 
75 
76 
78 {
79  typedef Ogre::RenderOperation::OperationType OperationType;
80 
81 public:
83  DynamicLines(OperationType opType = Ogre::RenderOperation::OT_LINE_STRIP);
84  virtual ~DynamicLines();
85 
87  void addPoint(const Ogre::Vector3 &p);
89  void addPoint(Ogre::Real x, Ogre::Real y, Ogre::Real z);
90 
92  void setPoint(unsigned short index, const Ogre::Vector3 &value);
93 
95  const Ogre::Vector3& getPoint(unsigned short index) const;
96 
98  unsigned short getNumPoints(void) const;
99 
101  void clear();
102 
104  void update();
105 
116  void setOperationType(OperationType opType);
117  OperationType getOperationType() const;
118 
119 protected:
121  virtual void createVertexDeclaration();
123  virtual void fillHardwareBuffers();
124 
125 private:
126  std::vector<Ogre::Vector3> mPoints;
127  bool mDirty;
128 };
129 
130 
131 
132 class PhysicsDebugDrawer : public btIDebugDraw
133 {
134 protected:
135  Ogre::SceneNode *mNode;
136  btDynamicsWorld *mWorld;
138  bool mDebugOn;
139 
140 public:
141  typedef std::shared_ptr<PhysicsDebugDrawer> shared;
142 
143  PhysicsDebugDrawer(Ogre::SceneNode *node, btDynamicsWorld *world);
144 
146 
147  void step();
148 
149  void drawLine(const btVector3& from,const btVector3& to,const btVector3& color);
150 
151  void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB, btScalar distance, int lifeTime,const btVector3& color);
152 
153  void reportErrorWarning(const char* warningString);
154 
155  void draw3dText(const btVector3& location,const char* textString);
156 
157  //0 for off, anything else for on.
158  void setDebugMode(int isOn);
159 
160  //0 for off, anything else for on.
161  int getDebugMode() const;
162 
163 };
164 
165 
166 #endif // PHYSICS_DEBUG_DRAW
unsigned short getNumPoints(void) const
Return the total number of points in the point list.
Definition: physicsdebugdrawer.cpp:208
int getDebugMode() const
Definition: physicsdebugdrawer.cpp:361
std::shared_ptr< PhysicsDebugDrawer > shared
Definition: physicsdebugdrawer.h:141
void update()
Call this to update the hardware buffer after making changes.
Definition: physicsdebugdrawer.cpp:227
DynamicLines * mLineDrawer
Definition: physicsdebugdrawer.h:137
void setPoint(unsigned short index, const Ogre::Vector3 &value)
Change the location of an existing point in the point list.
Definition: physicsdebugdrawer.cpp:213
btDynamicsWorld * mWorld
Definition: physicsdebugdrawer.h:136
void step()
Definition: physicsdebugdrawer.cpp:315
void drawLine(const btVector3 &from, const btVector3 &to, const btVector3 &color)
Definition: physicsdebugdrawer.cpp:332
virtual ~DynamicLines()
Definition: physicsdebugdrawer.cpp:176
DynamicRenderable()
Constructor.
Definition: physicsdebugdrawer.cpp:33
size_t mIndexBufferCapacity
Maximum capacity of the currently allocated index buffer.
Definition: physicsdebugdrawer.h:40
virtual void createVertexDeclaration()
Implementation DynamicRenderable, creates a simple vertex-only decl.
Definition: physicsdebugdrawer.cpp:232
void clear()
Remove all points from the point list.
Definition: physicsdebugdrawer.cpp:221
PhysicsDebugDrawer(Ogre::SceneNode *node, btDynamicsWorld *world)
Definition: physicsdebugdrawer.cpp:288
OperationType getOperationType() const
Definition: physicsdebugdrawer.cpp:185
virtual void createVertexDeclaration()=0
void addPoint(const Ogre::Vector3 &p)
Add a point to the point list.
Definition: physicsdebugdrawer.cpp:190
void reportErrorWarning(const char *warningString)
Definition: physicsdebugdrawer.cpp:344
std::vector< Ogre::Vector3 > mPoints
Definition: physicsdebugdrawer.h:126
void setOperationType(OperationType opType)
Definition: physicsdebugdrawer.cpp:180
~PhysicsDebugDrawer()
Definition: physicsdebugdrawer.cpp:308
Definition: physicsdebugdrawer.h:12
Definition: physicsdebugdrawer.h:132
Ogre::RenderOperation::OperationType OperationType
Definition: physicsdebugdrawer.h:79
virtual void fillHardwareBuffers()
Implementation DynamicRenderable, pushes point list out to hardware memory.
Definition: physicsdebugdrawer.cpp:238
bool mDirty
Definition: physicsdebugdrawer.h:127
void draw3dText(const btVector3 &location, const char *textString)
Definition: physicsdebugdrawer.cpp:349
bool mDebugOn
Definition: physicsdebugdrawer.h:138
DynamicLines(OperationType opType=Ogre::RenderOperation::OT_LINE_STRIP)
Constructor - see setOperationType() for description of argument.
Definition: physicsdebugdrawer.cpp:169
const Ogre::Vector3 & getPoint(unsigned short index) const
Return the location of an existing point in the point list.
Definition: physicsdebugdrawer.cpp:202
void initialize(Ogre::RenderOperation::OperationType operationType, bool useIndices)
Definition: physicsdebugdrawer.cpp:43
virtual ~DynamicRenderable()
Virtual destructor.
Definition: physicsdebugdrawer.cpp:37
virtual Ogre::Real getSquaredViewDepth(const Ogre::Camera *cam) const
Implementation of SimpleRenderable.
Definition: physicsdebugdrawer.cpp:150
size_t mVertexBufferCapacity
Maximum capacity of the currently allocated vertex buffer.
Definition: physicsdebugdrawer.h:38
Ogre::SceneNode * mNode
Definition: physicsdebugdrawer.h:135
std::vector< Ogre::Vector3 > Vector3Array
Definition: physicsdebugdrawer.h:10
virtual Ogre::Real getBoundingRadius(void) const
Implementation of SimpleRenderable.
Definition: physicsdebugdrawer.cpp:145
void prepareHardwareBuffers(size_t vertexCount, size_t indexCount)
Definition: physicsdebugdrawer.cpp:61
void drawContactPoint(const btVector3 &PointOnB, const btVector3 &normalOnB, btScalar distance, int lifeTime, const btVector3 &color)
Definition: physicsdebugdrawer.cpp:338
Definition: physicsdebugdrawer.h:77
void setDebugMode(int isOn)
Definition: physicsdebugdrawer.cpp:353
virtual void fillHardwareBuffers()=0