| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#ifndef DEBUGDRAW_H |
| 20 |
#define DEBUGDRAW_H |
| 21 |
|
| 22 |
|
| 23 |
static const float DU_PI = 3.14159265f; |
| 24 |
|
| 25 |
enum duDebugDrawPrimitives |
| 26 |
{ |
| 27 |
DU_DRAW_POINTS, |
| 28 |
DU_DRAW_LINES, |
| 29 |
DU_DRAW_TRIS, |
| 30 |
DU_DRAW_QUADS |
| 31 |
}; |
| 32 |
|
| 33 |
|
| 34 |
struct duDebugDraw |
| 35 |
{ |
| 36 |
virtual ~duDebugDraw() = 0; |
| 37 |
|
| 38 |
virtual void depthMask(bool state) = 0; |
| 39 |
|
| 40 |
virtual void texture(bool state) = 0; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f) = 0; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
virtual void vertex(const float* pos, unsigned int color) = 0; |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
virtual void vertex(const float x, const float y, const float z, unsigned int color) = 0; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
virtual void vertex(const float* pos, unsigned int color, const float* uv) = 0; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
virtual void vertex(const float x, const float y, const float z, unsigned int color, const float u, const float v) = 0; |
| 68 |
|
| 69 |
|
| 70 |
virtual void end() = 0; |
| 71 |
|
| 72 |
|
| 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 |
|
| 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 |
|
| 195 |
class duDisplayList : public duDebugDraw |
| 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 |
|
| 220 |
duDisplayList(const duDisplayList&); |
| 221 |
duDisplayList& operator=(const duDisplayList&); |
| 222 |
}; |
| 223 |
|
| 224 |
|
| 225 |
#endif |