123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062 |
- #define _USE_MATH_DEFINES
- #include <math.h>
- #include "DebugDraw.h"
- #include "RecastDebugDraw.h"
- #include "recast/Recast/Recast.h"
- void duDebugDrawTriMesh(duDebugDraw* dd, const float* verts, int ,
- const int* tris, const float* normals, int ntris,
- const unsigned char* flags, const float texScale)
- {
- if (!dd) return;
- if (!verts) return;
- if (!tris) return;
- if (!normals) return;
- float uva[2];
- float uvb[2];
- float uvc[2];
- const unsigned int unwalkable = duRGBA(192,128,0,255);
- dd->texture(true);
- dd->begin(DU_DRAW_TRIS);
- for (int i = 0; i < ntris*3; i += 3)
- {
- const float* norm = &normals[i];
- unsigned int color;
- unsigned char a = (unsigned char)(220*(2+norm[0]+norm[1])/4);
- if (flags && !flags[i/3])
- color = duLerpCol(duRGBA(a,a,a,255), unwalkable, 64);
- else
- color = duRGBA(a,a,a,255);
- const float* va = &verts[tris[i+0]*3];
- const float* vb = &verts[tris[i+1]*3];
- const float* vc = &verts[tris[i+2]*3];
-
- int ax = 0, ay = 0;
- if (rcAbs(norm[1]) > rcAbs(norm[ax]))
- ax = 1;
- if (rcAbs(norm[2]) > rcAbs(norm[ax]))
- ax = 2;
- ax = (1<<ax)&3;
- ay = (1<<ax)&3;
- uva[0] = va[ax]*texScale;
- uva[1] = va[ay]*texScale;
- uvb[0] = vb[ax]*texScale;
- uvb[1] = vb[ay]*texScale;
- uvc[0] = vc[ax]*texScale;
- uvc[1] = vc[ay]*texScale;
-
- dd->vertex(va, color, uva);
- dd->vertex(vb, color, uvb);
- dd->vertex(vc, color, uvc);
- }
- dd->end();
- dd->texture(false);
- }
- void duDebugDrawTriMeshSlope(duDebugDraw* dd, const float* verts, int ,
- const int* tris, const float* normals, int ntris,
- const float walkableSlopeAngle, const float texScale)
- {
- if (!dd) return;
- if (!verts) return;
- if (!tris) return;
- if (!normals) return;
-
- const float walkableThr = cosf(walkableSlopeAngle/180.0f*DU_PI);
-
- float uva[2];
- float uvb[2];
- float uvc[2];
-
- dd->texture(true);
- const unsigned int unwalkable = duRGBA(192,128,0,255);
-
- dd->begin(DU_DRAW_TRIS);
- for (int i = 0; i < ntris*3; i += 3)
- {
- const float* norm = &normals[i];
- unsigned int color;
- unsigned char a = (unsigned char)(220*(2+norm[0]+norm[1])/4);
- if (norm[1] < walkableThr)
- color = duLerpCol(duRGBA(a,a,a,255), unwalkable, 64);
- else
- color = duRGBA(a,a,a,255);
-
- const float* va = &verts[tris[i+0]*3];
- const float* vb = &verts[tris[i+1]*3];
- const float* vc = &verts[tris[i+2]*3];
-
- int ax = 0, ay = 0;
- if (rcAbs(norm[1]) > rcAbs(norm[ax]))
- ax = 1;
- if (rcAbs(norm[2]) > rcAbs(norm[ax]))
- ax = 2;
- ax = (1<<ax)&3;
- ay = (1<<ax)&3;
-
- uva[0] = va[ax]*texScale;
- uva[1] = va[ay]*texScale;
- uvb[0] = vb[ax]*texScale;
- uvb[1] = vb[ay]*texScale;
- uvc[0] = vc[ax]*texScale;
- uvc[1] = vc[ay]*texScale;
-
- dd->vertex(va, color, uva);
- dd->vertex(vb, color, uvb);
- dd->vertex(vc, color, uvc);
- }
- dd->end();
- dd->texture(false);
- }
- void duDebugDrawHeightfieldSolid(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(255,255,255,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)
- {
- duAppendBox(dd, fx, orig[1]+s->smin*ch, fz, fx+cs, orig[1] + s->smax*ch, fz+cs, fcol);
- s = s->next;
- }
- }
- }
- dd->end();
- }
- 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();
- }
- void duDebugDrawCompactHeightfieldSolid(duDebugDraw* dd, const rcCompactHeightfield& chf)
- {
- if (!dd) return;
- const float cs = chf.cs;
- const float ch = chf.ch;
- dd->begin(DU_DRAW_QUADS);
-
- for (int y = 0; y < chf.height; ++y)
- {
- for (int x = 0; x < chf.width; ++x)
- {
- const float fx = chf.bmin[0] + x*cs;
- const float fz = chf.bmin[2] + y*cs;
- const rcCompactCell& c = chf.cells[x+y*chf.width];
- for (unsigned i = c.index, ni = c.index+c.count; i < ni; ++i)
- {
- const rcCompactSpan& s = chf.spans[i];
- unsigned int color;
- if (chf.areas[i] == RC_WALKABLE_AREA)
- color = duRGBA(0,192,255,64);
- else if (chf.areas[i] == RC_NULL_AREA)
- color = duRGBA(0,0,0,64);
- else
- color = duIntToCol(chf.areas[i], 255);
-
- const float fy = chf.bmin[1] + (s.y+1)*ch;
- dd->vertex(fx, fy, fz, color);
- dd->vertex(fx, fy, fz+cs, color);
- dd->vertex(fx+cs, fy, fz+cs, color);
- dd->vertex(fx+cs, fy, fz, color);
- }
- }
- }
- dd->end();
- }
- void duDebugDrawCompactHeightfieldRegions(duDebugDraw* dd, const rcCompactHeightfield& chf)
- {
- if (!dd) return;
- const float cs = chf.cs;
- const float ch = chf.ch;
- dd->begin(DU_DRAW_QUADS);
- for (int y = 0; y < chf.height; ++y)
- {
- for (int x = 0; x < chf.width; ++x)
- {
- const float fx = chf.bmin[0] + x*cs;
- const float fz = chf.bmin[2] + y*cs;
- const rcCompactCell& c = chf.cells[x+y*chf.width];
-
- for (unsigned i = c.index, ni = c.index+c.count; i < ni; ++i)
- {
- const rcCompactSpan& s = chf.spans[i];
- const float fy = chf.bmin[1] + (s.y)*ch;
- unsigned int color;
- if (s.reg)
- color = duIntToCol(s.reg, 192);
- else
- color = duRGBA(0,0,0,64);
- dd->vertex(fx, fy, fz, color);
- dd->vertex(fx, fy, fz+cs, color);
- dd->vertex(fx+cs, fy, fz+cs, color);
- dd->vertex(fx+cs, fy, fz, color);
- }
- }
- }
-
- dd->end();
- }
- void duDebugDrawCompactHeightfieldDistance(duDebugDraw* dd, const rcCompactHeightfield& chf)
- {
- if (!dd) return;
- if (!chf.dist) return;
-
- const float cs = chf.cs;
- const float ch = chf.ch;
-
- float maxd = chf.maxDistance;
- if (maxd < 1.0f) maxd = 1;
- const float dscale = 255.0f / maxd;
-
- dd->begin(DU_DRAW_QUADS);
-
- for (int y = 0; y < chf.height; ++y)
- {
- for (int x = 0; x < chf.width; ++x)
- {
- const float fx = chf.bmin[0] + x*cs;
- const float fz = chf.bmin[2] + y*cs;
- const rcCompactCell& c = chf.cells[x+y*chf.width];
-
- for (unsigned i = c.index, ni = c.index+c.count; i < ni; ++i)
- {
- const rcCompactSpan& s = chf.spans[i];
- const float fy = chf.bmin[1] + (s.y+1)*ch;
- const unsigned char cd = (unsigned char)(chf.dist[i] * dscale);
- const unsigned int color = duRGBA(cd,cd,cd,255);
- dd->vertex(fx, fy, fz, color);
- dd->vertex(fx, fy, fz+cs, color);
- dd->vertex(fx+cs, fy, fz+cs, color);
- dd->vertex(fx+cs, fy, fz, color);
- }
- }
- }
- dd->end();
- }
- static void drawLayerPortals(duDebugDraw* dd, const rcHeightfieldLayer* layer)
- {
- const float cs = layer->cs;
- const float ch = layer->ch;
- const int w = layer->width;
- const int h = layer->height;
-
- unsigned int pcol = duRGBA(255,255,255,255);
-
- const int segs[4*4] = {0,0,0,1, 0,1,1,1, 1,1,1,0, 1,0,0,0};
-
-
- dd->begin(DU_DRAW_LINES, 2.0f);
- for (int y = 0; y < h; ++y)
- {
- for (int x = 0; x < w; ++x)
- {
- const int idx = x+y*w;
- const int lh = (int)layer->heights[idx];
- if (lh == 255) continue;
-
- for (int dir = 0; dir < 4; ++dir)
- {
- if (layer->cons[idx] & (1<<(dir+4)))
- {
- const int* seg = &segs[dir*4];
- const float ax = layer->bmin[0] + (x+seg[0])*cs;
- const float ay = layer->bmin[1] + (lh+2)*ch;
- const float az = layer->bmin[2] + (y+seg[1])*cs;
- const float bx = layer->bmin[0] + (x+seg[2])*cs;
- const float by = layer->bmin[1] + (lh+2)*ch;
- const float bz = layer->bmin[2] + (y+seg[3])*cs;
- dd->vertex(ax, ay, az, pcol);
- dd->vertex(bx, by, bz, pcol);
- }
- }
- }
- }
- dd->end();
- }
- void duDebugDrawHeightfieldLayer(duDebugDraw* dd, const struct rcHeightfieldLayer& layer, const int idx)
- {
- const float cs = layer.cs;
- const float ch = layer.ch;
- const int w = layer.width;
- const int h = layer.height;
-
- unsigned int color = duIntToCol(idx+1, 255);
-
-
- float bmin[3], bmax[3];
- bmin[0] = layer.bmin[0] + layer.minx*cs;
- bmin[1] = layer.bmin[1];
- bmin[2] = layer.bmin[2] + layer.miny*cs;
- bmax[0] = layer.bmin[0] + (layer.maxx+1)*cs;
- bmax[1] = layer.bmax[1];
- bmax[2] = layer.bmin[2] + (layer.maxy+1)*cs;
- duDebugDrawBoxWire(dd, bmin[0],bmin[1],bmin[2], bmax[0],bmax[1],bmax[2], duTransCol(color,128), 2.0f);
-
-
- dd->begin(DU_DRAW_QUADS);
- for (int y = 0; y < h; ++y)
- {
- for (int x = 0; x < w; ++x)
- {
- const int lidx = x+y*w;
- const int lh = (int)layer.heights[lidx];
- if (h == 0xff) continue;
- const unsigned char area = layer.areas[lidx];
-
- unsigned int col;
- if (area == RC_WALKABLE_AREA)
- col = duLerpCol(color, duRGBA(0,192,255,64), 32);
- else if (area == RC_NULL_AREA)
- col = duLerpCol(color, duRGBA(0,0,0,64), 32);
- else
- col = duLerpCol(color, duIntToCol(area, 255), 32);
-
- const float fx = layer.bmin[0] + x*cs;
- const float fy = layer.bmin[1] + (lh+1)*ch;
- const float fz = layer.bmin[2] + y*cs;
-
- dd->vertex(fx, fy, fz, col);
- dd->vertex(fx, fy, fz+cs, col);
- dd->vertex(fx+cs, fy, fz+cs, col);
- dd->vertex(fx+cs, fy, fz, col);
- }
- }
- dd->end();
-
-
- drawLayerPortals(dd, &layer);
- }
- void duDebugDrawHeightfieldLayers(duDebugDraw* dd, const struct rcHeightfieldLayerSet& lset)
- {
- if (!dd) return;
- for (int i = 0; i < lset.nlayers; ++i)
- duDebugDrawHeightfieldLayer(dd, lset.layers[i], i);
- }
- static void getContourCenter(const rcContour* cont, const float* orig, float cs, float ch, float* center)
- {
- center[0] = 0;
- center[1] = 0;
- center[2] = 0;
- if (!cont->nverts)
- return;
- for (int i = 0; i < cont->nverts; ++i)
- {
- const int* v = &cont->verts[i*4];
- center[0] += (float)v[0];
- center[1] += (float)v[1];
- center[2] += (float)v[2];
- }
- const float s = 1.0f / cont->nverts;
- center[0] *= s * cs;
- center[1] *= s * ch;
- center[2] *= s * cs;
- center[0] += orig[0];
- center[1] += orig[1] + 4*ch;
- center[2] += orig[2];
- }
- static const rcContour* findContourFromSet(const rcContourSet& cset, unsigned short reg)
- {
- for (int i = 0; i < cset.nconts; ++i)
- {
- if (cset.conts[i].reg == reg)
- return &cset.conts[i];
- }
- return 0;
- }
- void duDebugDrawRegionConnections(duDebugDraw* dd, const rcContourSet& cset, const float alpha)
- {
- if (!dd) return;
-
- const float* orig = cset.bmin;
- const float cs = cset.cs;
- const float ch = cset.ch;
-
-
- float pos[3], pos2[3];
- unsigned int color = duRGBA(0,0,0,196);
- dd->begin(DU_DRAW_LINES, 2.0f);
- for (int i = 0; i < cset.nconts; ++i)
- {
- const rcContour* cont = &cset.conts[i];
- getContourCenter(cont, orig, cs, ch, pos);
- for (int j = 0; j < cont->nverts; ++j)
- {
- const int* v = &cont->verts[j*4];
- if (v[3] == 0 || (unsigned short)v[3] < cont->reg) continue;
- const rcContour* cont2 = findContourFromSet(cset, (unsigned short)v[3]);
- if (cont2)
- {
- getContourCenter(cont2, orig, cs, ch, pos2);
- duAppendArc(dd, pos[0],pos[1],pos[2], pos2[0],pos2[1],pos2[2], 0.25f, 0.6f, 0.6f, color);
- }
- }
- }
-
- dd->end();
- unsigned char a = (unsigned char)(alpha * 255.0f);
- dd->begin(DU_DRAW_POINTS, 7.0f);
- for (int i = 0; i < cset.nconts; ++i)
- {
- const rcContour* cont = &cset.conts[i];
- unsigned int col = duDarkenCol(duIntToCol(cont->reg,a));
- getContourCenter(cont, orig, cs, ch, pos);
- dd->vertex(pos, col);
- }
- dd->end();
- }
- void duDebugDrawRawContours(duDebugDraw* dd, const rcContourSet& cset, const float alpha)
- {
- if (!dd) return;
- const float* orig = cset.bmin;
- const float cs = cset.cs;
- const float ch = cset.ch;
-
- const unsigned char a = (unsigned char)(alpha*255.0f);
-
- dd->begin(DU_DRAW_LINES, 2.0f);
-
- for (int i = 0; i < cset.nconts; ++i)
- {
- const rcContour& c = cset.conts[i];
- unsigned int color = duIntToCol(c.reg, a);
- for (int j = 0; j < c.nrverts; ++j)
- {
- const int* v = &c.rverts[j*4];
- float fx = orig[0] + v[0]*cs;
- float fy = orig[1] + (v[1]+1+(i&1))*ch;
- float fz = orig[2] + v[2]*cs;
- dd->vertex(fx,fy,fz,color);
- if (j > 0)
- dd->vertex(fx,fy,fz,color);
- }
-
- const int* v = &c.rverts[0];
- float fx = orig[0] + v[0]*cs;
- float fy = orig[1] + (v[1]+1+(i&1))*ch;
- float fz = orig[2] + v[2]*cs;
- dd->vertex(fx,fy,fz,color);
- }
- dd->end();
- dd->begin(DU_DRAW_POINTS, 2.0f);
- for (int i = 0; i < cset.nconts; ++i)
- {
- const rcContour& c = cset.conts[i];
- unsigned int color = duDarkenCol(duIntToCol(c.reg, a));
-
- for (int j = 0; j < c.nrverts; ++j)
- {
- const int* v = &c.rverts[j*4];
- float off = 0;
- unsigned int colv = color;
- if (v[3] & RC_BORDER_VERTEX)
- {
- colv = duRGBA(255,255,255,a);
- off = ch*2;
- }
-
- float fx = orig[0] + v[0]*cs;
- float fy = orig[1] + (v[1]+1+(i&1))*ch + off;
- float fz = orig[2] + v[2]*cs;
- dd->vertex(fx,fy,fz, colv);
- }
- }
- dd->end();
- }
- void duDebugDrawContours(duDebugDraw* dd, const rcContourSet& cset, const float alpha)
- {
- if (!dd) return;
- const float* orig = cset.bmin;
- const float cs = cset.cs;
- const float ch = cset.ch;
-
- const unsigned char a = (unsigned char)(alpha*255.0f);
-
- dd->begin(DU_DRAW_LINES, 2.5f);
-
- for (int i = 0; i < cset.nconts; ++i)
- {
- const rcContour& c = cset.conts[i];
- if (!c.nverts)
- continue;
- const unsigned int color = duIntToCol(c.reg, a);
- const unsigned int bcolor = duLerpCol(color,duRGBA(255,255,255,a),128);
- for (int j = 0, k = c.nverts-1; j < c.nverts; k=j++)
- {
- const int* va = &c.verts[k*4];
- const int* vb = &c.verts[j*4];
- unsigned int col = (va[3] & RC_AREA_BORDER) ? bcolor : color;
- float fx,fy,fz;
- fx = orig[0] + va[0]*cs;
- fy = orig[1] + (va[1]+1+(i&1))*ch;
- fz = orig[2] + va[2]*cs;
- dd->vertex(fx,fy,fz, col);
- fx = orig[0] + vb[0]*cs;
- fy = orig[1] + (vb[1]+1+(i&1))*ch;
- fz = orig[2] + vb[2]*cs;
- dd->vertex(fx,fy,fz, col);
- }
- }
- dd->end();
- dd->begin(DU_DRAW_POINTS, 3.0f);
-
- for (int i = 0; i < cset.nconts; ++i)
- {
- const rcContour& c = cset.conts[i];
- unsigned int color = duDarkenCol(duIntToCol(c.reg, a));
- for (int j = 0; j < c.nverts; ++j)
- {
- const int* v = &c.verts[j*4];
- float off = 0;
- unsigned int colv = color;
- if (v[3] & RC_BORDER_VERTEX)
- {
- colv = duRGBA(255,255,255,a);
- off = ch*2;
- }
- float fx = orig[0] + v[0]*cs;
- float fy = orig[1] + (v[1]+1+(i&1))*ch + off;
- float fz = orig[2] + v[2]*cs;
- dd->vertex(fx,fy,fz, colv);
- }
- }
- dd->end();
- }
- void duDebugDrawPolyMesh(duDebugDraw* dd, const struct rcPolyMesh& mesh)
- {
- if (!dd) return;
- const int nvp = mesh.nvp;
- const float cs = mesh.cs;
- const float ch = mesh.ch;
- const float* orig = mesh.bmin;
-
- dd->begin(DU_DRAW_TRIS);
-
- for (int i = 0; i < mesh.npolys; ++i)
- {
- const unsigned short* p = &mesh.polys[i*nvp*2];
-
- unsigned int color;
- if (mesh.areas[i] == RC_WALKABLE_AREA)
- color = duRGBA(0,192,255,64);
- else if (mesh.areas[i] == RC_NULL_AREA)
- color = duRGBA(0,0,0,64);
- else
- color = duIntToCol(mesh.areas[i], 255);
-
- unsigned short vi[3];
- for (int j = 2; j < nvp; ++j)
- {
- if (p[j] == RC_MESH_NULL_IDX) break;
- vi[0] = p[0];
- vi[1] = p[j-1];
- vi[2] = p[j];
- for (int k = 0; k < 3; ++k)
- {
- const unsigned short* v = &mesh.verts[vi[k]*3];
- const float x = orig[0] + v[0]*cs;
- const float y = orig[1] + (v[1]+1)*ch;
- const float z = orig[2] + v[2]*cs;
- dd->vertex(x,y,z, color);
- }
- }
- }
- dd->end();
-
- const unsigned int coln = duRGBA(0,48,64,32);
- dd->begin(DU_DRAW_LINES, 1.5f);
- for (int i = 0; i < mesh.npolys; ++i)
- {
- const unsigned short* p = &mesh.polys[i*nvp*2];
- for (int j = 0; j < nvp; ++j)
- {
- if (p[j] == RC_MESH_NULL_IDX) break;
- if (p[nvp+j] & 0x8000) continue;
- const int nj = (j+1 >= nvp || p[j+1] == RC_MESH_NULL_IDX) ? 0 : j+1;
- const int vi[2] = {p[j], p[nj]};
-
- for (int k = 0; k < 2; ++k)
- {
- const unsigned short* v = &mesh.verts[vi[k]*3];
- const float x = orig[0] + v[0]*cs;
- const float y = orig[1] + (v[1]+1)*ch + 0.1f;
- const float z = orig[2] + v[2]*cs;
- dd->vertex(x, y, z, coln);
- }
- }
- }
- dd->end();
-
-
- const unsigned int colb = duRGBA(0,48,64,220);
- dd->begin(DU_DRAW_LINES, 2.5f);
- for (int i = 0; i < mesh.npolys; ++i)
- {
- const unsigned short* p = &mesh.polys[i*nvp*2];
- for (int j = 0; j < nvp; ++j)
- {
- if (p[j] == RC_MESH_NULL_IDX) break;
- if ((p[nvp+j] & 0x8000) == 0) continue;
- const int nj = (j+1 >= nvp || p[j+1] == RC_MESH_NULL_IDX) ? 0 : j+1;
- const int vi[2] = {p[j], p[nj]};
-
- unsigned int col = colb;
- if ((p[nvp+j] & 0xf) != 0xf)
- col = duRGBA(255,255,255,128);
- for (int k = 0; k < 2; ++k)
- {
- const unsigned short* v = &mesh.verts[vi[k]*3];
- const float x = orig[0] + v[0]*cs;
- const float y = orig[1] + (v[1]+1)*ch + 0.1f;
- const float z = orig[2] + v[2]*cs;
- dd->vertex(x, y, z, col);
- }
- }
- }
- dd->end();
-
- dd->begin(DU_DRAW_POINTS, 3.0f);
- const unsigned int colv = duRGBA(0,0,0,220);
- for (int i = 0; i < mesh.nverts; ++i)
- {
- const unsigned short* v = &mesh.verts[i*3];
- const float x = orig[0] + v[0]*cs;
- const float y = orig[1] + (v[1]+1)*ch + 0.1f;
- const float z = orig[2] + v[2]*cs;
- dd->vertex(x,y,z, colv);
- }
- dd->end();
- }
- void duDebugDrawPolyMeshDetail(duDebugDraw* dd, const struct rcPolyMeshDetail& dmesh)
- {
- if (!dd) return;
- dd->begin(DU_DRAW_TRIS);
-
- for (int i = 0; i < dmesh.nmeshes; ++i)
- {
- const unsigned int* m = &dmesh.meshes[i*4];
- const unsigned int bverts = m[0];
- const unsigned int btris = m[2];
- const int ntris = (int)m[3];
- const float* verts = &dmesh.verts[bverts*3];
- const unsigned char* tris = &dmesh.tris[btris*4];
- unsigned int color = duIntToCol(i, 192);
- for (int j = 0; j < ntris; ++j)
- {
- dd->vertex(&verts[tris[j*4+0]*3], color);
- dd->vertex(&verts[tris[j*4+1]*3], color);
- dd->vertex(&verts[tris[j*4+2]*3], color);
- }
- }
- dd->end();
-
- dd->begin(DU_DRAW_LINES, 1.0f);
- const unsigned int coli = duRGBA(0,0,0,64);
- for (int i = 0; i < dmesh.nmeshes; ++i)
- {
- const unsigned int* m = &dmesh.meshes[i*4];
- const unsigned int bverts = m[0];
- const unsigned int btris = m[2];
- const int ntris = (int)m[3];
- const float* verts = &dmesh.verts[bverts*3];
- const unsigned char* tris = &dmesh.tris[btris*4];
-
- for (int j = 0; j < ntris; ++j)
- {
- const unsigned char* t = &tris[j*4];
- for (int k = 0, kp = 2; k < 3; kp=k++)
- {
- unsigned char ef = (t[3] >> (kp*2)) & 0x3;
- if (ef == 0)
- {
-
- if (t[kp] < t[k])
- {
- dd->vertex(&verts[t[kp]*3], coli);
- dd->vertex(&verts[t[k]*3], coli);
- }
- }
- }
- }
- }
- dd->end();
-
-
- dd->begin(DU_DRAW_LINES, 2.0f);
- const unsigned int cole = duRGBA(0,0,0,64);
- for (int i = 0; i < dmesh.nmeshes; ++i)
- {
- const unsigned int* m = &dmesh.meshes[i*4];
- const unsigned int bverts = m[0];
- const unsigned int btris = m[2];
- const int ntris = (int)m[3];
- const float* verts = &dmesh.verts[bverts*3];
- const unsigned char* tris = &dmesh.tris[btris*4];
-
- for (int j = 0; j < ntris; ++j)
- {
- const unsigned char* t = &tris[j*4];
- for (int k = 0, kp = 2; k < 3; kp=k++)
- {
- unsigned char ef = (t[3] >> (kp*2)) & 0x3;
- if (ef != 0)
- {
-
- dd->vertex(&verts[t[kp]*3], cole);
- dd->vertex(&verts[t[k]*3], cole);
- }
- }
- }
- }
- dd->end();
-
- dd->begin(DU_DRAW_POINTS, 3.0f);
- const unsigned int colv = duRGBA(0,0,0,64);
- for (int i = 0; i < dmesh.nmeshes; ++i)
- {
- const unsigned int* m = &dmesh.meshes[i*4];
- const unsigned int bverts = m[0];
- const int nverts = (int)m[1];
- const float* verts = &dmesh.verts[bverts*3];
- for (int j = 0; j < nverts; ++j)
- dd->vertex(&verts[j*3], colv);
- }
- dd->end();
- }
|