Debug draw duPolyToCol custom function (#253)

Add duDebugDraw::duPolyToCol to allow user to pick polygon color.
This commit is contained in:
Domenico Albani 2017-01-30 11:11:32 +01:00 committed by Jakob Botsch Nielsen
parent dfd40071c5
commit ad6e5de2e9
3 changed files with 24 additions and 12 deletions

View File

@ -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)

View File

@ -20,13 +20,26 @@
#include <string.h>
#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)
{

View File

@ -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];