diff --git a/DebugUtils/Include/DebugDraw.h b/DebugUtils/Include/DebugDraw.h index 0b8c593..1e70f1a 100644 --- a/DebugUtils/Include/DebugDraw.h +++ b/DebugUtils/Include/DebugDraw.h @@ -66,6 +66,11 @@ struct duDebugDraw /// End drawing primitives. virtual void end() = 0; + + /// Compute a color for given polygon. + /// @param poly [in] the polygon to compute color for. + /// @return The color value. + virtual unsigned int polyToCol(const struct dtPoly* poly); }; inline unsigned int duRGBA(int r, int g, int b, int a) diff --git a/DebugUtils/Source/DebugDraw.cpp b/DebugUtils/Source/DebugDraw.cpp index a009def..a74bb9d 100644 --- a/DebugUtils/Source/DebugDraw.cpp +++ b/DebugUtils/Source/DebugDraw.cpp @@ -20,13 +20,26 @@ #include #include "DebugDraw.h" #include "DetourMath.h" +#include "DetourNavMesh.h" duDebugDraw::~duDebugDraw() { // Empty } - + +unsigned int duDebugDraw::polyToCol(const struct dtPoly* poly) +{ + if (poly->getArea() == 0) + { + // Treat zero area type as default. + return duRGBA(0, 192, 255, 255); + } + else + { + return duIntToCol(poly->getArea(), 255); + } +} inline int bit(int a, int b) { diff --git a/DebugUtils/Source/DetourDebugDraw.cpp b/DebugUtils/Source/DetourDebugDraw.cpp index e2db107..762f084 100644 --- a/DebugUtils/Source/DetourDebugDraw.cpp +++ b/DebugUtils/Source/DetourDebugDraw.cpp @@ -121,6 +121,7 @@ static void drawMeshTile(duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMesh dtPolyRef base = mesh.getPolyRefBase(tile); int tileNum = mesh.decodePolyIdTile(base); + const unsigned int tileColor = duIntToCol(tileNum, 128); dd->depthMask(false); @@ -139,16 +140,9 @@ static void drawMeshTile(duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMesh else { if (flags & DU_DRAWNAVMESH_COLOR_TILES) - { - col = duIntToCol(tileNum, 128); - } + col = tileColor; else - { - if (p->getArea() == 0) // Treat zero area type as default. - col = duRGBA(0,192,255,64); - else - col = duIntToCol(p->getArea(), 64); - } + col = duTransCol(dd->polyToCol(p), 64); } for (int j = 0; j < pd->triCount; ++j) @@ -184,8 +178,8 @@ static void drawMeshTile(duDebugDraw* dd, const dtNavMesh& mesh, const dtNavMesh if (query && query->isInClosedList(base | (dtPolyRef)i)) col = duRGBA(255,196,0,220); else - col = duDarkenCol(duIntToCol(p->getArea(), 220)); - + col = duDarkenCol(duTransCol(dd->polyToCol(p), 220)); + const dtOffMeshConnection* con = &tile->offMeshCons[i - tile->header->offMeshBase]; const float* va = &tile->verts[p->verts[0]*3]; const float* vb = &tile->verts[p->verts[1]*3];