9
3

DebugDraw.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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. #define _USE_MATH_DEFINES
  19. #include <string.h>
  20. #include "DebugDraw.h"
  21. #include "DetourMath.h"
  22. #include "DetourNavMesh.h"
  23. duDebugDraw::~duDebugDraw()
  24. {
  25. // Empty
  26. }
  27. unsigned int duDebugDraw::areaToCol(unsigned int area)
  28. {
  29. if (area == 0)
  30. {
  31. // Treat zero area type as default.
  32. return duRGBA(0, 192, 255, 255);
  33. }
  34. else
  35. {
  36. return duIntToCol(area, 255);
  37. }
  38. }
  39. inline int bit(int a, int b)
  40. {
  41. return (a & (1 << b)) >> b;
  42. }
  43. unsigned int duIntToCol(int i, int a)
  44. {
  45. int r = bit(i, 1) + bit(i, 3) * 2 + 1;
  46. int g = bit(i, 2) + bit(i, 4) * 2 + 1;
  47. int b = bit(i, 0) + bit(i, 5) * 2 + 1;
  48. return duRGBA(r*63,g*63,b*63,a);
  49. }
  50. void duIntToCol(int i, float* col)
  51. {
  52. int r = bit(i, 0) + bit(i, 3) * 2 + 1;
  53. int g = bit(i, 1) + bit(i, 4) * 2 + 1;
  54. int b = bit(i, 2) + bit(i, 5) * 2 + 1;
  55. col[0] = 1 - r*63.0f/255.0f;
  56. col[1] = 1 - g*63.0f/255.0f;
  57. col[2] = 1 - b*63.0f/255.0f;
  58. }
  59. void duCalcBoxColors(unsigned int* colors, unsigned int colTop, unsigned int colSide)
  60. {
  61. if (!colors) return;
  62. colors[0] = duMultCol(colTop, 250);
  63. colors[1] = duMultCol(colSide, 140);
  64. colors[2] = duMultCol(colSide, 165);
  65. colors[3] = duMultCol(colSide, 217);
  66. colors[4] = duMultCol(colSide, 165);
  67. colors[5] = duMultCol(colSide, 217);
  68. }
  69. void duDebugDrawCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
  70. float maxx, float maxy, float maxz, unsigned int col, const float lineWidth)
  71. {
  72. if (!dd) return;
  73. dd->begin(DU_DRAW_LINES, lineWidth);
  74. duAppendCylinderWire(dd, minx,miny,minz, maxx,maxy,maxz, col);
  75. dd->end();
  76. }
  77. void duDebugDrawBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
  78. float maxx, float maxy, float maxz, unsigned int col, const float lineWidth)
  79. {
  80. if (!dd) return;
  81. dd->begin(DU_DRAW_LINES, lineWidth);
  82. duAppendBoxWire(dd, minx,miny,minz, maxx,maxy,maxz, col);
  83. dd->end();
  84. }
  85. void duDebugDrawArc(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
  86. const float x1, const float y1, const float z1, const float h,
  87. const float as0, const float as1, unsigned int col, const float lineWidth)
  88. {
  89. if (!dd) return;
  90. dd->begin(DU_DRAW_LINES, lineWidth);
  91. duAppendArc(dd, x0,y0,z0, x1,y1,z1, h, as0, as1, col);
  92. dd->end();
  93. }
  94. void duDebugDrawArrow(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
  95. const float x1, const float y1, const float z1,
  96. const float as0, const float as1, unsigned int col, const float lineWidth)
  97. {
  98. if (!dd) return;
  99. dd->begin(DU_DRAW_LINES, lineWidth);
  100. duAppendArrow(dd, x0,y0,z0, x1,y1,z1, as0, as1, col);
  101. dd->end();
  102. }
  103. void duDebugDrawCircle(struct duDebugDraw* dd, const float x, const float y, const float z,
  104. const float r, unsigned int col, const float lineWidth)
  105. {
  106. if (!dd) return;
  107. dd->begin(DU_DRAW_LINES, lineWidth);
  108. duAppendCircle(dd, x,y,z, r, col);
  109. dd->end();
  110. }
  111. void duDebugDrawCross(struct duDebugDraw* dd, const float x, const float y, const float z,
  112. const float size, unsigned int col, const float lineWidth)
  113. {
  114. if (!dd) return;
  115. dd->begin(DU_DRAW_LINES, lineWidth);
  116. duAppendCross(dd, x,y,z, size, col);
  117. dd->end();
  118. }
  119. void duDebugDrawBox(struct duDebugDraw* dd, float minx, float miny, float minz,
  120. float maxx, float maxy, float maxz, const unsigned int* fcol)
  121. {
  122. if (!dd) return;
  123. dd->begin(DU_DRAW_QUADS);
  124. duAppendBox(dd, minx,miny,minz, maxx,maxy,maxz, fcol);
  125. dd->end();
  126. }
  127. void duDebugDrawCylinder(struct duDebugDraw* dd, float minx, float miny, float minz,
  128. float maxx, float maxy, float maxz, unsigned int col)
  129. {
  130. if (!dd) return;
  131. dd->begin(DU_DRAW_TRIS);
  132. duAppendCylinder(dd, minx,miny,minz, maxx,maxy,maxz, col);
  133. dd->end();
  134. }
  135. void duDebugDrawGridXZ(struct duDebugDraw* dd, const float ox, const float oy, const float oz,
  136. const int w, const int h, const float size,
  137. const unsigned int col, const float lineWidth)
  138. {
  139. if (!dd) return;
  140. dd->begin(DU_DRAW_LINES, lineWidth);
  141. for (int i = 0; i <= h; ++i)
  142. {
  143. dd->vertex(ox,oy,oz+i*size, col);
  144. dd->vertex(ox+w*size,oy,oz+i*size, col);
  145. }
  146. for (int i = 0; i <= w; ++i)
  147. {
  148. dd->vertex(ox+i*size,oy,oz, col);
  149. dd->vertex(ox+i*size,oy,oz+h*size, col);
  150. }
  151. dd->end();
  152. }
  153. void duAppendCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
  154. float maxx, float maxy, float maxz, unsigned int col)
  155. {
  156. if (!dd) return;
  157. static const int NUM_SEG = 16;
  158. static float dir[NUM_SEG*2];
  159. static bool init = false;
  160. if (!init)
  161. {
  162. init = true;
  163. for (int i = 0; i < NUM_SEG; ++i)
  164. {
  165. const float a = (float)i/(float)NUM_SEG*DU_PI*2;
  166. dir[i*2] = dtMathCosf(a);
  167. dir[i*2+1] = dtMathSinf(a);
  168. }
  169. }
  170. const float cx = (maxx + minx)/2;
  171. const float cz = (maxz + minz)/2;
  172. const float rx = (maxx - minx)/2;
  173. const float rz = (maxz - minz)/2;
  174. for (int i = 0, j = NUM_SEG-1; i < NUM_SEG; j = i++)
  175. {
  176. dd->vertex(cx+dir[j*2+0]*rx, miny, cz+dir[j*2+1]*rz, col);
  177. dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col);
  178. dd->vertex(cx+dir[j*2+0]*rx, maxy, cz+dir[j*2+1]*rz, col);
  179. dd->vertex(cx+dir[i*2+0]*rx, maxy, cz+dir[i*2+1]*rz, col);
  180. }
  181. for (int i = 0; i < NUM_SEG; i += NUM_SEG/4)
  182. {
  183. dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col);
  184. dd->vertex(cx+dir[i*2+0]*rx, maxy, cz+dir[i*2+1]*rz, col);
  185. }
  186. }
  187. void duAppendBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
  188. float maxx, float maxy, float maxz, unsigned int col)
  189. {
  190. if (!dd) return;
  191. // Top
  192. dd->vertex(minx, miny, minz, col);
  193. dd->vertex(maxx, miny, minz, col);
  194. dd->vertex(maxx, miny, minz, col);
  195. dd->vertex(maxx, miny, maxz, col);
  196. dd->vertex(maxx, miny, maxz, col);
  197. dd->vertex(minx, miny, maxz, col);
  198. dd->vertex(minx, miny, maxz, col);
  199. dd->vertex(minx, miny, minz, col);
  200. // bottom
  201. dd->vertex(minx, maxy, minz, col);
  202. dd->vertex(maxx, maxy, minz, col);
  203. dd->vertex(maxx, maxy, minz, col);
  204. dd->vertex(maxx, maxy, maxz, col);
  205. dd->vertex(maxx, maxy, maxz, col);
  206. dd->vertex(minx, maxy, maxz, col);
  207. dd->vertex(minx, maxy, maxz, col);
  208. dd->vertex(minx, maxy, minz, col);
  209. // Sides
  210. dd->vertex(minx, miny, minz, col);
  211. dd->vertex(minx, maxy, minz, col);
  212. dd->vertex(maxx, miny, minz, col);
  213. dd->vertex(maxx, maxy, minz, col);
  214. dd->vertex(maxx, miny, maxz, col);
  215. dd->vertex(maxx, maxy, maxz, col);
  216. dd->vertex(minx, miny, maxz, col);
  217. dd->vertex(minx, maxy, maxz, col);
  218. }
  219. void duAppendBoxPoints(struct duDebugDraw* dd, float minx, float miny, float minz,
  220. float maxx, float maxy, float maxz, unsigned int col)
  221. {
  222. if (!dd) return;
  223. // Top
  224. dd->vertex(minx, miny, minz, col);
  225. dd->vertex(maxx, miny, minz, col);
  226. dd->vertex(maxx, miny, minz, col);
  227. dd->vertex(maxx, miny, maxz, col);
  228. dd->vertex(maxx, miny, maxz, col);
  229. dd->vertex(minx, miny, maxz, col);
  230. dd->vertex(minx, miny, maxz, col);
  231. dd->vertex(minx, miny, minz, col);
  232. // bottom
  233. dd->vertex(minx, maxy, minz, col);
  234. dd->vertex(maxx, maxy, minz, col);
  235. dd->vertex(maxx, maxy, minz, col);
  236. dd->vertex(maxx, maxy, maxz, col);
  237. dd->vertex(maxx, maxy, maxz, col);
  238. dd->vertex(minx, maxy, maxz, col);
  239. dd->vertex(minx, maxy, maxz, col);
  240. dd->vertex(minx, maxy, minz, col);
  241. }
  242. void duAppendBox(struct duDebugDraw* dd, float minx, float miny, float minz,
  243. float maxx, float maxy, float maxz, const unsigned int* fcol)
  244. {
  245. if (!dd) return;
  246. const float verts[8*3] =
  247. {
  248. minx, miny, minz,
  249. maxx, miny, minz,
  250. maxx, miny, maxz,
  251. minx, miny, maxz,
  252. minx, maxy, minz,
  253. maxx, maxy, minz,
  254. maxx, maxy, maxz,
  255. minx, maxy, maxz,
  256. };
  257. static const unsigned char inds[6*4] =
  258. {
  259. 7, 6, 5, 4,
  260. 0, 1, 2, 3,
  261. 1, 5, 6, 2,
  262. 3, 7, 4, 0,
  263. 2, 6, 7, 3,
  264. 0, 4, 5, 1,
  265. };
  266. const unsigned char* in = inds;
  267. for (int i = 0; i < 6; ++i)
  268. {
  269. dd->vertex(&verts[*in*3], fcol[i]); in++;
  270. dd->vertex(&verts[*in*3], fcol[i]); in++;
  271. dd->vertex(&verts[*in*3], fcol[i]); in++;
  272. dd->vertex(&verts[*in*3], fcol[i]); in++;
  273. }
  274. }
  275. void duAppendCylinder(struct duDebugDraw* dd, float minx, float miny, float minz,
  276. float maxx, float maxy, float maxz, unsigned int col)
  277. {
  278. if (!dd) return;
  279. static const int NUM_SEG = 16;
  280. static float dir[NUM_SEG*2];
  281. static bool init = false;
  282. if (!init)
  283. {
  284. init = true;
  285. for (int i = 0; i < NUM_SEG; ++i)
  286. {
  287. const float a = (float)i/(float)NUM_SEG*DU_PI*2;
  288. dir[i*2] = cosf(a);
  289. dir[i*2+1] = sinf(a);
  290. }
  291. }
  292. unsigned int col2 = duMultCol(col, 160);
  293. const float cx = (maxx + minx)/2;
  294. const float cz = (maxz + minz)/2;
  295. const float rx = (maxx - minx)/2;
  296. const float rz = (maxz - minz)/2;
  297. for (int i = 2; i < NUM_SEG; ++i)
  298. {
  299. const int a = 0, b = i-1, c = i;
  300. dd->vertex(cx+dir[a*2+0]*rx, miny, cz+dir[a*2+1]*rz, col2);
  301. dd->vertex(cx+dir[b*2+0]*rx, miny, cz+dir[b*2+1]*rz, col2);
  302. dd->vertex(cx+dir[c*2+0]*rx, miny, cz+dir[c*2+1]*rz, col2);
  303. }
  304. for (int i = 2; i < NUM_SEG; ++i)
  305. {
  306. const int a = 0, b = i, c = i-1;
  307. dd->vertex(cx+dir[a*2+0]*rx, maxy, cz+dir[a*2+1]*rz, col);
  308. dd->vertex(cx+dir[b*2+0]*rx, maxy, cz+dir[b*2+1]*rz, col);
  309. dd->vertex(cx+dir[c*2+0]*rx, maxy, cz+dir[c*2+1]*rz, col);
  310. }
  311. for (int i = 0, j = NUM_SEG-1; i < NUM_SEG; j = i++)
  312. {
  313. dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col2);
  314. dd->vertex(cx+dir[j*2+0]*rx, miny, cz+dir[j*2+1]*rz, col2);
  315. dd->vertex(cx+dir[j*2+0]*rx, maxy, cz+dir[j*2+1]*rz, col);
  316. dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col2);
  317. dd->vertex(cx+dir[j*2+0]*rx, maxy, cz+dir[j*2+1]*rz, col);
  318. dd->vertex(cx+dir[i*2+0]*rx, maxy, cz+dir[i*2+1]*rz, col);
  319. }
  320. }
  321. inline void evalArc(const float x0, const float y0, const float z0,
  322. const float dx, const float dy, const float dz,
  323. const float h, const float u, float* res)
  324. {
  325. res[0] = x0 + dx * u;
  326. res[1] = y0 + dy * u + h * (1-(u*2-1)*(u*2-1));
  327. res[2] = z0 + dz * u;
  328. }
  329. inline void vcross(float* dest, const float* v1, const float* v2)
  330. {
  331. dest[0] = v1[1]*v2[2] - v1[2]*v2[1];
  332. dest[1] = v1[2]*v2[0] - v1[0]*v2[2];
  333. dest[2] = v1[0]*v2[1] - v1[1]*v2[0];
  334. }
  335. inline void vnormalize(float* v)
  336. {
  337. float d = 1.0f / sqrtf(v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
  338. v[0] *= d;
  339. v[1] *= d;
  340. v[2] *= d;
  341. }
  342. inline void vsub(float* dest, const float* v1, const float* v2)
  343. {
  344. dest[0] = v1[0]-v2[0];
  345. dest[1] = v1[1]-v2[1];
  346. dest[2] = v1[2]-v2[2];
  347. }
  348. inline float vdistSqr(const float* v1, const float* v2)
  349. {
  350. const float x = v1[0]-v2[0];
  351. const float y = v1[1]-v2[1];
  352. const float z = v1[2]-v2[2];
  353. return x*x + y*y + z*z;
  354. }
  355. void appendArrowHead(struct duDebugDraw* dd, const float* p, const float* q,
  356. const float s, unsigned int col)
  357. {
  358. const float eps = 0.001f;
  359. if (!dd) return;
  360. if (vdistSqr(p,q) < eps*eps) return;
  361. float ax[3], ay[3] = {0,1,0}, az[3];
  362. vsub(az, q, p);
  363. vnormalize(az);
  364. vcross(ax, ay, az);
  365. vcross(ay, az, ax);
  366. vnormalize(ay);
  367. dd->vertex(p, col);
  368. // dd->vertex(p[0]+az[0]*s+ay[0]*s/2, p[1]+az[1]*s+ay[1]*s/2, p[2]+az[2]*s+ay[2]*s/2, col);
  369. dd->vertex(p[0]+az[0]*s+ax[0]*s/3, p[1]+az[1]*s+ax[1]*s/3, p[2]+az[2]*s+ax[2]*s/3, col);
  370. dd->vertex(p, col);
  371. // dd->vertex(p[0]+az[0]*s-ay[0]*s/2, p[1]+az[1]*s-ay[1]*s/2, p[2]+az[2]*s-ay[2]*s/2, col);
  372. dd->vertex(p[0]+az[0]*s-ax[0]*s/3, p[1]+az[1]*s-ax[1]*s/3, p[2]+az[2]*s-ax[2]*s/3, col);
  373. }
  374. void duAppendArc(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
  375. const float x1, const float y1, const float z1, const float h,
  376. const float as0, const float as1, unsigned int col)
  377. {
  378. if (!dd) return;
  379. static const int NUM_ARC_PTS = 8;
  380. static const float PAD = 0.05f;
  381. static const float ARC_PTS_SCALE = (1.0f-PAD*2) / (float)NUM_ARC_PTS;
  382. const float dx = x1 - x0;
  383. const float dy = y1 - y0;
  384. const float dz = z1 - z0;
  385. const float len = sqrtf(dx*dx + dy*dy + dz*dz);
  386. float prev[3];
  387. evalArc(x0,y0,z0, dx,dy,dz, len*h, PAD, prev);
  388. for (int i = 1; i <= NUM_ARC_PTS; ++i)
  389. {
  390. const float u = PAD + i * ARC_PTS_SCALE;
  391. float pt[3];
  392. evalArc(x0,y0,z0, dx,dy,dz, len*h, u, pt);
  393. dd->vertex(prev[0],prev[1],prev[2], col);
  394. dd->vertex(pt[0],pt[1],pt[2], col);
  395. prev[0] = pt[0]; prev[1] = pt[1]; prev[2] = pt[2];
  396. }
  397. // End arrows
  398. if (as0 > 0.001f)
  399. {
  400. float p[3], q[3];
  401. evalArc(x0,y0,z0, dx,dy,dz, len*h, PAD, p);
  402. evalArc(x0,y0,z0, dx,dy,dz, len*h, PAD+0.05f, q);
  403. appendArrowHead(dd, p, q, as0, col);
  404. }
  405. if (as1 > 0.001f)
  406. {
  407. float p[3], q[3];
  408. evalArc(x0,y0,z0, dx,dy,dz, len*h, 1-PAD, p);
  409. evalArc(x0,y0,z0, dx,dy,dz, len*h, 1-(PAD+0.05f), q);
  410. appendArrowHead(dd, p, q, as1, col);
  411. }
  412. }
  413. void duAppendArrow(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
  414. const float x1, const float y1, const float z1,
  415. const float as0, const float as1, unsigned int col)
  416. {
  417. if (!dd) return;
  418. dd->vertex(x0,y0,z0, col);
  419. dd->vertex(x1,y1,z1, col);
  420. // End arrows
  421. const float p[3] = {x0,y0,z0}, q[3] = {x1,y1,z1};
  422. if (as0 > 0.001f)
  423. appendArrowHead(dd, p, q, as0, col);
  424. if (as1 > 0.001f)
  425. appendArrowHead(dd, q, p, as1, col);
  426. }
  427. void duAppendCircle(struct duDebugDraw* dd, const float x, const float y, const float z,
  428. const float r, unsigned int col)
  429. {
  430. if (!dd) return;
  431. static const int NUM_SEG = 40;
  432. static float dir[40*2];
  433. static bool init = false;
  434. if (!init)
  435. {
  436. init = true;
  437. for (int i = 0; i < NUM_SEG; ++i)
  438. {
  439. const float a = (float)i/(float)NUM_SEG*DU_PI*2;
  440. dir[i*2] = cosf(a);
  441. dir[i*2+1] = sinf(a);
  442. }
  443. }
  444. for (int i = 0, j = NUM_SEG-1; i < NUM_SEG; j = i++)
  445. {
  446. dd->vertex(x+dir[j*2+0]*r, y, z+dir[j*2+1]*r, col);
  447. dd->vertex(x+dir[i*2+0]*r, y, z+dir[i*2+1]*r, col);
  448. }
  449. }
  450. void duAppendCross(struct duDebugDraw* dd, const float x, const float y, const float z,
  451. const float s, unsigned int col)
  452. {
  453. if (!dd) return;
  454. dd->vertex(x-s,y,z, col);
  455. dd->vertex(x+s,y,z, col);
  456. dd->vertex(x,y-s,z, col);
  457. dd->vertex(x,y+s,z, col);
  458. dd->vertex(x,y,z-s, col);
  459. dd->vertex(x,y,z+s, col);
  460. }
  461. duDisplayList::duDisplayList(int cap) :
  462. m_pos(0),
  463. m_color(0),
  464. m_size(0),
  465. m_cap(0),
  466. m_depthMask(true),
  467. m_prim(DU_DRAW_LINES),
  468. m_primSize(1.0f)
  469. {
  470. if (cap < 8)
  471. cap = 8;
  472. resize(cap);
  473. }
  474. duDisplayList::~duDisplayList()
  475. {
  476. delete [] m_pos;
  477. delete [] m_color;
  478. }
  479. void duDisplayList::resize(int cap)
  480. {
  481. float* newPos = new float[cap*3];
  482. if (m_size)
  483. memcpy(newPos, m_pos, sizeof(float)*3*m_size);
  484. delete [] m_pos;
  485. m_pos = newPos;
  486. unsigned int* newColor = new unsigned int[cap];
  487. if (m_size)
  488. memcpy(newColor, m_color, sizeof(unsigned int)*m_size);
  489. delete [] m_color;
  490. m_color = newColor;
  491. m_cap = cap;
  492. }
  493. void duDisplayList::clear()
  494. {
  495. m_size = 0;
  496. }
  497. void duDisplayList::depthMask(bool state)
  498. {
  499. m_depthMask = state;
  500. }
  501. void duDisplayList::begin(duDebugDrawPrimitives prim, float size)
  502. {
  503. clear();
  504. m_prim = prim;
  505. m_primSize = size;
  506. }
  507. void duDisplayList::vertex(const float x, const float y, const float z, unsigned int color)
  508. {
  509. if (m_size+1 >= m_cap)
  510. resize(m_cap*2);
  511. float* p = &m_pos[m_size*3];
  512. p[0] = x;
  513. p[1] = y;
  514. p[2] = z;
  515. m_color[m_size] = color;
  516. m_size++;
  517. }
  518. void duDisplayList::vertex(const float* pos, unsigned int color)
  519. {
  520. vertex(pos[0],pos[1],pos[2],color);
  521. }
  522. void duDisplayList::end()
  523. {
  524. }
  525. void duDisplayList::draw(struct duDebugDraw* dd)
  526. {
  527. if (!dd) return;
  528. if (!m_size) return;
  529. dd->depthMask(m_depthMask);
  530. dd->begin(m_prim, m_primSize);
  531. for (int i = 0; i < m_size; ++i)
  532. dd->vertex(&m_pos[i*3], m_color[i]);
  533. dd->end();
  534. }