Recast Navigation
Navigation-mesh Toolset for Games
DebugDraw.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
3 //
4 // This software is provided 'as-is', without any express or implied
5 // warranty. In no event will the authors be held liable for any damages
6 // arising from the use of this software.
7 // Permission is granted to anyone to use this software for any purpose,
8 // including commercial applications, and to alter it and redistribute it
9 // freely, subject to the following restrictions:
10 // 1. The origin of this software must not be misrepresented; you must not
11 // claim that you wrote the original software. If you use this software
12 // in a product, an acknowledgment in the product documentation would be
13 // appreciated but is not required.
14 // 2. Altered source versions must be plainly marked as such, and must not be
15 // misrepresented as being the original software.
16 // 3. This notice may not be removed or altered from any source distribution.
17 //
18 
19 #ifndef DEBUGDRAW_H
20 #define DEBUGDRAW_H
21 
22 // Some math headers don't have PI defined.
23 static const float DU_PI = 3.14159265f;
24 
26 {
31 };
32 
35 {
36  virtual ~duDebugDraw() = 0;
37 
38  virtual void depthMask(bool state) = 0;
39 
40  virtual void texture(bool state) = 0;
41 
45  virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f) = 0;
46 
50  virtual void vertex(const float* pos, unsigned int color) = 0;
51 
55  virtual void vertex(const float x, const float y, const float z, unsigned int color) = 0;
56 
61  virtual void vertex(const float* pos, unsigned int color, const float* uv) = 0;
62 
67  virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v) = 0;
68 
70  virtual void end() = 0;
71 
73  virtual unsigned int areaToCol(unsigned int area);
74 };
75 
76 inline unsigned int duRGBA(int r, int g, int b, int a)
77 {
78  return ((unsigned int)r) | ((unsigned int)g << 8) | ((unsigned int)b << 16) | ((unsigned int)a << 24);
79 }
80 
81 inline unsigned int duRGBAf(float fr, float fg, float fb, float fa)
82 {
83  unsigned char r = (unsigned char)(fr*255.0f);
84  unsigned char g = (unsigned char)(fg*255.0f);
85  unsigned char b = (unsigned char)(fb*255.0f);
86  unsigned char a = (unsigned char)(fa*255.0f);
87  return duRGBA(r,g,b,a);
88 }
89 
90 unsigned int duIntToCol(int i, int a);
91 void duIntToCol(int i, float* col);
92 
93 inline unsigned int duMultCol(const unsigned int col, const unsigned int d)
94 {
95  const unsigned int r = col & 0xff;
96  const unsigned int g = (col >> 8) & 0xff;
97  const unsigned int b = (col >> 16) & 0xff;
98  const unsigned int a = (col >> 24) & 0xff;
99  return duRGBA((r*d) >> 8, (g*d) >> 8, (b*d) >> 8, a);
100 }
101 
102 inline unsigned int duDarkenCol(unsigned int col)
103 {
104  return ((col >> 1) & 0x007f7f7f) | (col & 0xff000000);
105 }
106 
107 inline unsigned int duLerpCol(unsigned int ca, unsigned int cb, unsigned int u)
108 {
109  const unsigned int ra = ca & 0xff;
110  const unsigned int ga = (ca >> 8) & 0xff;
111  const unsigned int ba = (ca >> 16) & 0xff;
112  const unsigned int aa = (ca >> 24) & 0xff;
113  const unsigned int rb = cb & 0xff;
114  const unsigned int gb = (cb >> 8) & 0xff;
115  const unsigned int bb = (cb >> 16) & 0xff;
116  const unsigned int ab = (cb >> 24) & 0xff;
117 
118  unsigned int r = (ra*(255-u) + rb*u)/255;
119  unsigned int g = (ga*(255-u) + gb*u)/255;
120  unsigned int b = (ba*(255-u) + bb*u)/255;
121  unsigned int a = (aa*(255-u) + ab*u)/255;
122  return duRGBA(r,g,b,a);
123 }
124 
125 inline unsigned int duTransCol(unsigned int c, unsigned int a)
126 {
127  return (a<<24) | (c & 0x00ffffff);
128 }
129 
130 
131 void duCalcBoxColors(unsigned int* colors, unsigned int colTop, unsigned int colSide);
132 
133 void duDebugDrawCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
134  float maxx, float maxy, float maxz, unsigned int col, const float lineWidth);
135 
136 void duDebugDrawBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
137  float maxx, float maxy, float maxz, unsigned int col, const float lineWidth);
138 
139 void duDebugDrawArc(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
140  const float x1, const float y1, const float z1, const float h,
141  const float as0, const float as1, unsigned int col, const float lineWidth);
142 
143 void duDebugDrawArrow(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
144  const float x1, const float y1, const float z1,
145  const float as0, const float as1, unsigned int col, const float lineWidth);
146 
147 void duDebugDrawCircle(struct duDebugDraw* dd, const float x, const float y, const float z,
148  const float r, unsigned int col, const float lineWidth);
149 
150 void duDebugDrawCross(struct duDebugDraw* dd, const float x, const float y, const float z,
151  const float size, unsigned int col, const float lineWidth);
152 
153 void duDebugDrawBox(struct duDebugDraw* dd, float minx, float miny, float minz,
154  float maxx, float maxy, float maxz, const unsigned int* fcol);
155 
156 void duDebugDrawCylinder(struct duDebugDraw* dd, float minx, float miny, float minz,
157  float maxx, float maxy, float maxz, unsigned int col);
158 
159 void duDebugDrawGridXZ(struct duDebugDraw* dd, const float ox, const float oy, const float oz,
160  const int w, const int h, const float size,
161  const unsigned int col, const float lineWidth);
162 
163 
164 // Versions without begin/end, can be used to draw multiple primitives.
165 void duAppendCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
166  float maxx, float maxy, float maxz, unsigned int col);
167 
168 void duAppendBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
169  float maxx, float maxy, float maxz, unsigned int col);
170 
171 void duAppendBoxPoints(struct duDebugDraw* dd, float minx, float miny, float minz,
172  float maxx, float maxy, float maxz, unsigned int col);
173 
174 void duAppendArc(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
175  const float x1, const float y1, const float z1, const float h,
176  const float as0, const float as1, unsigned int col);
177 
178 void duAppendArrow(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
179  const float x1, const float y1, const float z1,
180  const float as0, const float as1, unsigned int col);
181 
182 void duAppendCircle(struct duDebugDraw* dd, const float x, const float y, const float z,
183  const float r, unsigned int col);
184 
185 void duAppendCross(struct duDebugDraw* dd, const float x, const float y, const float z,
186  const float size, unsigned int col);
187 
188 void duAppendBox(struct duDebugDraw* dd, float minx, float miny, float minz,
189  float maxx, float maxy, float maxz, const unsigned int* fcol);
190 
191 void duAppendCylinder(struct duDebugDraw* dd, float minx, float miny, float minz,
192  float maxx, float maxy, float maxz, unsigned int col);
193 
194 
196 {
197  float* m_pos;
198  unsigned int* m_color;
199  int m_size;
200  int m_cap;
201 
202  duDebugDrawPrimitives m_prim;
203  float m_primSize;
204  bool m_depthMask;
205 
206  void resize(int cap);
207 
208 public:
209  duDisplayList(int cap = 512);
210  virtual ~duDisplayList();
211  virtual void depthMask(bool state);
212  virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f);
213  virtual void vertex(const float x, const float y, const float z, unsigned int color);
214  virtual void vertex(const float* pos, unsigned int color);
215  virtual void end();
216  void clear();
217  void draw(struct duDebugDraw* dd);
218 private:
219  // Explicitly disabled copy constructor and copy assignment operator.
221  duDisplayList& operator=(const duDisplayList&);
222 };
223 
224 
225 #endif // DEBUGDRAW_H
void duDebugDrawCylinder(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col)
Definition: DebugDraw.cpp:150
void duAppendCircle(struct duDebugDraw *dd, const float x, const float y, const float z, const float r, unsigned int col)
Definition: DebugDraw.cpp:490
static const float DU_PI
Definition: DebugDraw.h:23
void duAppendBox(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, const unsigned int *fcol)
Definition: DebugDraw.cpp:279
void duDebugDrawBox(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, const unsigned int *fcol)
Definition: DebugDraw.cpp:140
void duAppendArc(struct duDebugDraw *dd, const float x0, const float y0, const float z0, const float x1, const float y1, const float z1, const float h, const float as0, const float as1, unsigned int col)
Definition: DebugDraw.cpp:431
void duDebugDrawArc(struct duDebugDraw *dd, const float x0, const float y0, const float z0, const float x1, const float y1, const float z1, const float h, const float as0, const float as1, unsigned int col, const float lineWidth)
Definition: DebugDraw.cpp:98
unsigned int duIntToCol(int i, int a)
Definition: DebugDraw.cpp:48
void duDebugDrawCylinderWire(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col, const float lineWidth)
Definition: DebugDraw.cpp:78
void duDebugDrawCircle(struct duDebugDraw *dd, const float x, const float y, const float z, const float r, unsigned int col, const float lineWidth)
Definition: DebugDraw.cpp:120
void duAppendCross(struct duDebugDraw *dd, const float x, const float y, const float z, const float size, unsigned int col)
Definition: DebugDraw.cpp:515
void duDebugDrawBoxWire(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col, const float lineWidth)
Definition: DebugDraw.cpp:88
unsigned int duRGBAf(float fr, float fg, float fb, float fa)
Definition: DebugDraw.h:81
unsigned int duDarkenCol(unsigned int col)
Definition: DebugDraw.h:102
unsigned int duTransCol(unsigned int c, unsigned int a)
Definition: DebugDraw.h:125
void duAppendCylinderWire(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col)
Definition: DebugDraw.cpp:181
void duDebugDrawGridXZ(struct duDebugDraw *dd, const float ox, const float oy, const float oz, const int w, const int h, const float size, const unsigned int col, const float lineWidth)
Definition: DebugDraw.cpp:160
void duDebugDrawArrow(struct duDebugDraw *dd, const float x0, const float y0, const float z0, const float x1, const float y1, const float z1, const float as0, const float as1, unsigned int col, const float lineWidth)
Definition: DebugDraw.cpp:109
void duAppendCylinder(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col)
Definition: DebugDraw.cpp:314
void duAppendBoxWire(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col)
Definition: DebugDraw.cpp:219
void duCalcBoxColors(unsigned int *colors, unsigned int colTop, unsigned int colSide)
Definition: DebugDraw.cpp:66
unsigned int duRGBA(int r, int g, int b, int a)
Definition: DebugDraw.h:76
duDebugDrawPrimitives
Definition: DebugDraw.h:26
@ DU_DRAW_QUADS
Definition: DebugDraw.h:30
@ DU_DRAW_LINES
Definition: DebugDraw.h:28
@ DU_DRAW_TRIS
Definition: DebugDraw.h:29
@ DU_DRAW_POINTS
Definition: DebugDraw.h:27
void duAppendBoxPoints(struct duDebugDraw *dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col)
Definition: DebugDraw.cpp:254
unsigned int duLerpCol(unsigned int ca, unsigned int cb, unsigned int u)
Definition: DebugDraw.h:107
void duAppendArrow(struct duDebugDraw *dd, const float x0, const float y0, const float z0, const float x1, const float y1, const float z1, const float as0, const float as1, unsigned int col)
Definition: DebugDraw.cpp:473
void duDebugDrawCross(struct duDebugDraw *dd, const float x, const float y, const float z, const float size, unsigned int col, const float lineWidth)
Definition: DebugDraw.cpp:130
unsigned int duMultCol(const unsigned int col, const unsigned int d)
Definition: DebugDraw.h:93
Definition: DebugDraw.h:196
virtual void depthMask(bool state)
Definition: DebugDraw.cpp:569
void draw(struct duDebugDraw *dd)
Definition: DebugDraw.cpp:602
void clear()
Definition: DebugDraw.cpp:564
virtual ~duDisplayList()
Definition: DebugDraw.cpp:541
duDisplayList(int cap=512)
Definition: DebugDraw.cpp:527
virtual void begin(duDebugDrawPrimitives prim, float size=1.0f)
Begin drawing primitives.
Definition: DebugDraw.cpp:574
virtual void end()
End drawing primitives.
Definition: DebugDraw.cpp:598
virtual void vertex(const float x, const float y, const float z, unsigned int color)
Submit a vertex.
Definition: DebugDraw.cpp:581
Abstract debug draw interface.
Definition: DebugDraw.h:35
virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v)=0
Submit a vertex.
virtual void vertex(const float x, const float y, const float z, unsigned int color)=0
Submit a vertex.
virtual void begin(duDebugDrawPrimitives prim, float size=1.0f)=0
Begin drawing primitives.
virtual void vertex(const float *pos, unsigned int color, const float *uv)=0
Submit a vertex.
virtual void vertex(const float *pos, unsigned int color)=0
Submit a vertex.
virtual unsigned int areaToCol(unsigned int area)
Compute a color for given area.
Definition: DebugDraw.cpp:30
virtual void depthMask(bool state)=0
virtual void end()=0
End drawing primitives.
virtual ~duDebugDraw()=0
Definition: DebugDraw.cpp:25
virtual void texture(bool state)=0