void duAppendCylinder(struct duDebugDraw* dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, unsigned int col) { if (!dd) return; static const int NUM_SEG = 16; static float dir[NUM_SEG*2]; static bool init = false; if (!init) { init = true; for (int i = 0; i < NUM_SEG; ++i) { const float a = (float)i/(float)NUM_SEG*DU_PI*2; dir[i*2] = cosf(a); dir[i*2+1] = sinf(a); } } unsigned int col2 = duMultCol(col, 160); const float cx = (maxx + minx)/2; const float cz = (maxz + minz)/2; const float rx = (maxx - minx)/2; const float rz = (maxz - minz)/2; for (int i = 2; i < NUM_SEG; ++i) { const int a = 0, b = i-1, c = i; dd->vertex(cx+dir[a*2+0]*rx, miny, cz+dir[a*2+1]*rz, col2); dd->vertex(cx+dir[b*2+0]*rx, miny, cz+dir[b*2+1]*rz, col2); dd->vertex(cx+dir[c*2+0]*rx, miny, cz+dir[c*2+1]*rz, col2); } for (int i = 2; i < NUM_SEG; ++i) { const int a = 0, b = i, c = i-1; dd->vertex(cx+dir[a*2+0]*rx, maxy, cz+dir[a*2+1]*rz, col); dd->vertex(cx+dir[b*2+0]*rx, maxy, cz+dir[b*2+1]*rz, col); dd->vertex(cx+dir[c*2+0]*rx, maxy, cz+dir[c*2+1]*rz, col); } for (int i = 0, j = NUM_SEG-1; i < NUM_SEG; j = i++) { dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col2); dd->vertex(cx+dir[j*2+0]*rx, miny, cz+dir[j*2+1]*rz, col2); dd->vertex(cx+dir[j*2+0]*rx, maxy, cz+dir[j*2+1]*rz, col); dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col2); dd->vertex(cx+dir[j*2+0]*rx, maxy, cz+dir[j*2+1]*rz, col); dd->vertex(cx+dir[i*2+0]*rx, maxy, cz+dir[i*2+1]*rz, col); } }
void duCalcBoxColors(unsigned int* colors, unsigned int colTop, unsigned int colSide) { if (!colors) return; colors[0] = duMultCol(colTop, 250); colors[1] = duMultCol(colSide, 140); colors[2] = duMultCol(colSide, 165); colors[3] = duMultCol(colSide, 217); colors[4] = duMultCol(colSide, 165); colors[5] = duMultCol(colSide, 217); }
void duDebugDrawHeightfieldWalkable(duDebugDraw* dd, const rcHeightfield& hf) { if (!dd) return; const float* orig = hf.bmin; const float cs = hf.cs; const float ch = hf.ch; const int w = hf.width; const int h = hf.height; unsigned int fcol[6]; duCalcBoxColors(fcol, duRGBA(255,255,255,255), duRGBA(217,217,217,255)); dd->begin(DU_DRAW_QUADS); for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { float fx = orig[0] + x*cs; float fz = orig[2] + y*cs; const rcSpan* s = hf.spans[x + y*w]; while (s) { if (s->area == RC_WALKABLE_AREA) fcol[0] = duRGBA(64,128,160,255); else if (s->area == RC_NULL_AREA) fcol[0] = duRGBA(64,64,64,255); else fcol[0] = duMultCol(duIntToCol(s->area, 255), 200); duAppendBox(dd, fx, orig[1]+s->smin*ch, fz, fx+cs, orig[1] + s->smax*ch, fz+cs, fcol); s = s->next; } } } dd->end(); }