Moved common debugdraw code to DebugDraw.h/cpp, changed API to allow uint colors.
This commit is contained in:
parent
44b6c54c57
commit
6c76919ab9
@ -70,4 +70,50 @@ inline unsigned int duRGBAf(float fr, float fg, float fb, float fa)
|
|||||||
unsigned int duIntToCol(int i, int a);
|
unsigned int duIntToCol(int i, int a);
|
||||||
void duIntToCol(int i, float* col);
|
void duIntToCol(int i, float* col);
|
||||||
|
|
||||||
|
void duCalcBoxColors(unsigned int* colors, unsigned int colTop, unsigned int colSide);
|
||||||
|
|
||||||
|
void duDebugDrawCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
|
||||||
|
float maxx, float maxy, float maxz, unsigned int col, const float lineWidth);
|
||||||
|
|
||||||
|
void duDebugDrawBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
|
||||||
|
float maxx, float maxy, float maxz, unsigned int col, const float lineWidth);
|
||||||
|
|
||||||
|
void duDebugDrawArc(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
|
||||||
|
const float x1, const float y1, const float z1, const float h, unsigned int col, const float lineWidth);
|
||||||
|
|
||||||
|
void duDebugDrawCircle(struct duDebugDraw* dd, const float x, const float y, const float z,
|
||||||
|
const float r, unsigned int col, const float lineWidth);
|
||||||
|
|
||||||
|
void duDebugDrawCross(struct duDebugDraw* dd, const float x, const float y, const float z,
|
||||||
|
const float size, unsigned int col, const float lineWidth);
|
||||||
|
|
||||||
|
void duDebugDrawBox(struct duDebugDraw* dd, float minx, float miny, float minz,
|
||||||
|
float maxx, float maxy, float maxz, const unsigned int* fcol);
|
||||||
|
|
||||||
|
void duDebugDrawGridXZ(struct duDebugDraw* dd, const float ox, const float oy, const float oz,
|
||||||
|
const int w, const int h, const float size,
|
||||||
|
const unsigned int col, const float lineWidth);
|
||||||
|
|
||||||
|
|
||||||
|
// Versions without begin/end, can be used to draw multiple primitives.
|
||||||
|
void duAppendCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
|
||||||
|
float maxx, float maxy, float maxz, unsigned int col);
|
||||||
|
|
||||||
|
void duAppendBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
|
||||||
|
float maxx, float maxy, float maxz, unsigned int col);
|
||||||
|
|
||||||
|
void duAppendArc(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
|
||||||
|
const float x1, const float y1, const float z1, const float h, unsigned int col);
|
||||||
|
|
||||||
|
void duAppendCircle(struct duDebugDraw* dd, const float x, const float y, const float z,
|
||||||
|
const float r, unsigned int col);
|
||||||
|
|
||||||
|
void duAppendCross(struct duDebugDraw* dd, const float x, const float y, const float z,
|
||||||
|
const float size, unsigned int col);
|
||||||
|
|
||||||
|
void duAppendBox(struct duDebugDraw* dd, float minx, float miny, float minz,
|
||||||
|
float maxx, float maxy, float maxz, const unsigned int* fcol);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // DEBUGDRAW_H
|
#endif // DEBUGDRAW_H
|
||||||
|
@ -23,6 +23,6 @@
|
|||||||
|
|
||||||
void duDebugDrawNavMesh(struct duDebugDraw* dd, const dtNavMesh* mesh, bool drawClosedList = false);
|
void duDebugDrawNavMesh(struct duDebugDraw* dd, const dtNavMesh* mesh, bool drawClosedList = false);
|
||||||
void duDebugDrawNavMeshBVTree(struct duDebugDraw* dd, const dtNavMesh* mesh);
|
void duDebugDrawNavMeshBVTree(struct duDebugDraw* dd, const dtNavMesh* mesh);
|
||||||
void duDebugDrawNavMeshPoly(struct duDebugDraw* dd, const dtNavMesh* mesh, dtPolyRef ref, const float* col);
|
void duDebugDrawNavMeshPoly(struct duDebugDraw* dd, const dtNavMesh* mesh, dtPolyRef ref, const unsigned int col);
|
||||||
|
|
||||||
#endif // DETOURDEBUGDRAW_H
|
#endif // DETOURDEBUGDRAW_H
|
@ -35,12 +35,4 @@ void duDebugDrawContours(struct duDebugDraw* dd, const struct rcContourSet& cset
|
|||||||
void duDebugDrawPolyMesh(struct duDebugDraw* dd, const struct rcPolyMesh& mesh);
|
void duDebugDrawPolyMesh(struct duDebugDraw* dd, const struct rcPolyMesh& mesh);
|
||||||
void duDebugDrawPolyMeshDetail(struct duDebugDraw* dd, const struct rcPolyMeshDetail& dmesh);
|
void duDebugDrawPolyMeshDetail(struct duDebugDraw* dd, const struct rcPolyMeshDetail& dmesh);
|
||||||
|
|
||||||
void duDebugDrawCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
|
|
||||||
float maxx, float maxy, float maxz, const float* col);
|
|
||||||
void duDebugDrawBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
|
|
||||||
float maxx, float maxy, float maxz, const float* col);
|
|
||||||
void duDebugDrawBox(struct duDebugDraw* dd, float minx, float miny, float minz, float maxx, float maxy, float maxz,
|
|
||||||
const float* col1, const float* col2);
|
|
||||||
void duDebugDrawArc(struct duDebugDraw* dd, const float* p0, const float* p1, const float* col, float lineWidth);
|
|
||||||
|
|
||||||
#endif // RECAST_DEBUGDRAW_H
|
#endif // RECAST_DEBUGDRAW_H
|
||||||
|
@ -16,6 +16,8 @@
|
|||||||
// 3. This notice may not be removed or altered from any source distribution.
|
// 3. This notice may not be removed or altered from any source distribution.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#define _USE_MATH_DEFINES
|
||||||
|
#include <math.h>
|
||||||
#include "DebugDraw.h"
|
#include "DebugDraw.h"
|
||||||
|
|
||||||
inline int bit(int a, int b)
|
inline int bit(int a, int b)
|
||||||
@ -40,3 +42,253 @@ void duIntToCol(int i, float* col)
|
|||||||
col[1] = 1 - g*63.0f/255.0f;
|
col[1] = 1 - g*63.0f/255.0f;
|
||||||
col[2] = 1 - b*63.0f/255.0f;
|
col[2] = 1 - b*63.0f/255.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline unsigned int multCol(const unsigned int col, const unsigned int d)
|
||||||
|
{
|
||||||
|
const unsigned int r = col & 0xff;
|
||||||
|
const unsigned int g = (col >> 8) & 0xff;
|
||||||
|
const unsigned int b = (col >> 16) & 0xff;
|
||||||
|
const unsigned int a = (col >> 24) & 0xff;
|
||||||
|
return duRGBA((r*d) >> 8, (g*d) >> 8, (b*d) >> 8, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
void duCalcBoxColors(unsigned int* colors, unsigned int colTop, unsigned int colSide)
|
||||||
|
{
|
||||||
|
colors[0] = multCol(colTop, 250);
|
||||||
|
colors[1] = multCol(colSide, 140);
|
||||||
|
colors[2] = multCol(colSide, 165);
|
||||||
|
colors[3] = multCol(colSide, 217);
|
||||||
|
colors[4] = multCol(colSide, 165);
|
||||||
|
colors[5] = multCol(colSide, 217);
|
||||||
|
}
|
||||||
|
|
||||||
|
void duDebugDrawCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
|
||||||
|
float maxx, float maxy, float maxz, unsigned int col, const float lineWidth)
|
||||||
|
{
|
||||||
|
dd->begin(DU_DRAW_LINES, lineWidth);
|
||||||
|
duAppendCylinderWire(dd, minx,miny,minz, maxx,maxy,maxz, col);
|
||||||
|
dd->end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void duDebugDrawBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
|
||||||
|
float maxx, float maxy, float maxz, unsigned int col, const float lineWidth)
|
||||||
|
{
|
||||||
|
dd->begin(DU_DRAW_LINES, lineWidth);
|
||||||
|
duAppendBoxWire(dd, minx,miny,minz, maxx,maxy,maxz, col);
|
||||||
|
dd->end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void duDebugDrawArc(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
|
||||||
|
const float x1, const float y1, const float z1, const float h, unsigned int col, const float lineWidth)
|
||||||
|
{
|
||||||
|
dd->begin(DU_DRAW_LINES, lineWidth);
|
||||||
|
duAppendArc(dd, x0,y0,z0, x1,y1,z1, h, col);
|
||||||
|
dd->end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void duDebugDrawCircle(struct duDebugDraw* dd, const float x, const float y, const float z,
|
||||||
|
const float r, unsigned int col, const float lineWidth)
|
||||||
|
{
|
||||||
|
dd->begin(DU_DRAW_LINES, lineWidth);
|
||||||
|
duAppendCircle(dd, x,y,z, r, col);
|
||||||
|
dd->end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void duDebugDrawCross(struct duDebugDraw* dd, const float x, const float y, const float z,
|
||||||
|
const float size, unsigned int col, const float lineWidth)
|
||||||
|
{
|
||||||
|
dd->begin(DU_DRAW_LINES, lineWidth);
|
||||||
|
duAppendCross(dd, x,y,z, size, col);
|
||||||
|
dd->end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void duDebugDrawBox(struct duDebugDraw* dd, float minx, float miny, float minz,
|
||||||
|
float maxx, float maxy, float maxz, const unsigned int* fcol)
|
||||||
|
{
|
||||||
|
dd->begin(DU_DRAW_TRIS);
|
||||||
|
duAppendBox(dd, minx,miny,minz, maxx,maxy,maxz, fcol);
|
||||||
|
dd->end();
|
||||||
|
}
|
||||||
|
|
||||||
|
void duDebugDrawGridXZ(struct duDebugDraw* dd, const float ox, const float oy, const float oz,
|
||||||
|
const int w, const int h, const float size,
|
||||||
|
const unsigned int col, const float lineWidth)
|
||||||
|
{
|
||||||
|
dd->begin(DU_DRAW_LINES, lineWidth);
|
||||||
|
for (int i = 0; i <= h; ++i)
|
||||||
|
{
|
||||||
|
dd->vertex(ox,oy,oz+i*size, col);
|
||||||
|
dd->vertex(ox+w*size,oy,oz+i*size, col);
|
||||||
|
}
|
||||||
|
for (int i = 0; i <= w; ++i)
|
||||||
|
{
|
||||||
|
dd->vertex(ox+i*size,oy,oz, col);
|
||||||
|
dd->vertex(ox+i*size,oy,oz+h*size, col);
|
||||||
|
}
|
||||||
|
dd->end();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void duAppendCylinderWire(struct duDebugDraw* dd, float minx, float miny, float minz,
|
||||||
|
float maxx, float maxy, float maxz, unsigned int col)
|
||||||
|
{
|
||||||
|
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*(float)M_PI*2;
|
||||||
|
dir[i*2] = cosf(a);
|
||||||
|
dir[i*2+1] = sinf(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = 0, j = NUM_SEG-1; i < NUM_SEG; j = i++)
|
||||||
|
{
|
||||||
|
dd->vertex(cx+dir[j*2+0]*rx, miny, cz+dir[j*2+1]*rz, col);
|
||||||
|
dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < NUM_SEG; i += NUM_SEG/4)
|
||||||
|
{
|
||||||
|
dd->vertex(cx+dir[i*2+0]*rx, miny, cz+dir[i*2+1]*rz, col);
|
||||||
|
dd->vertex(cx+dir[i*2+0]*rx, maxy, cz+dir[i*2+1]*rz, col);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void duAppendBoxWire(struct duDebugDraw* dd, float minx, float miny, float minz,
|
||||||
|
float maxx, float maxy, float maxz, unsigned int col)
|
||||||
|
{
|
||||||
|
// Top
|
||||||
|
dd->vertex(minx, miny, minz, col);
|
||||||
|
dd->vertex(maxx, miny, minz, col);
|
||||||
|
dd->vertex(maxx, miny, minz, col);
|
||||||
|
dd->vertex(maxx, miny, maxz, col);
|
||||||
|
dd->vertex(maxx, miny, maxz, col);
|
||||||
|
dd->vertex(minx, miny, maxz, col);
|
||||||
|
dd->vertex(minx, miny, maxz, col);
|
||||||
|
dd->vertex(minx, miny, minz, col);
|
||||||
|
|
||||||
|
// bottom
|
||||||
|
dd->vertex(minx, maxy, minz, col);
|
||||||
|
dd->vertex(maxx, maxy, minz, col);
|
||||||
|
dd->vertex(maxx, maxy, minz, col);
|
||||||
|
dd->vertex(maxx, maxy, maxz, col);
|
||||||
|
dd->vertex(maxx, maxy, maxz, col);
|
||||||
|
dd->vertex(minx, maxy, maxz, col);
|
||||||
|
dd->vertex(minx, maxy, maxz, col);
|
||||||
|
dd->vertex(minx, maxy, minz, col);
|
||||||
|
|
||||||
|
// Sides
|
||||||
|
dd->vertex(minx, miny, minz, col);
|
||||||
|
dd->vertex(minx, maxy, minz, col);
|
||||||
|
dd->vertex(maxx, miny, minz, col);
|
||||||
|
dd->vertex(maxx, maxy, minz, col);
|
||||||
|
dd->vertex(maxx, miny, maxz, col);
|
||||||
|
dd->vertex(maxx, maxy, maxz, col);
|
||||||
|
dd->vertex(minx, miny, maxz, col);
|
||||||
|
dd->vertex(minx, maxy, maxz, col);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void duAppendBox(struct duDebugDraw* dd, float minx, float miny, float minz,
|
||||||
|
float maxx, float maxy, float maxz, const unsigned int* fcol)
|
||||||
|
{
|
||||||
|
const float verts[8*3] =
|
||||||
|
{
|
||||||
|
minx, miny, minz,
|
||||||
|
maxx, miny, minz,
|
||||||
|
maxx, miny, maxz,
|
||||||
|
minx, miny, maxz,
|
||||||
|
minx, maxy, minz,
|
||||||
|
maxx, maxy, minz,
|
||||||
|
maxx, maxy, maxz,
|
||||||
|
minx, maxy, maxz,
|
||||||
|
};
|
||||||
|
static const unsigned char inds[6*4] =
|
||||||
|
{
|
||||||
|
7, 6, 5, 4,
|
||||||
|
0, 1, 2, 3,
|
||||||
|
1, 5, 6, 2,
|
||||||
|
3, 7, 4, 0,
|
||||||
|
2, 6, 7, 3,
|
||||||
|
0, 4, 5, 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
const unsigned char* in = inds;
|
||||||
|
for (int i = 0; i < 6; ++i)
|
||||||
|
{
|
||||||
|
dd->vertex(&verts[*in*3], fcol[i]); in++;
|
||||||
|
dd->vertex(&verts[*in*3], fcol[i]); in++;
|
||||||
|
dd->vertex(&verts[*in*3], fcol[i]); in++;
|
||||||
|
dd->vertex(&verts[*in*3], fcol[i]); in++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void duAppendArc(struct duDebugDraw* dd, const float x0, const float y0, const float z0,
|
||||||
|
const float x1, const float y1, const float z1, const float h, unsigned int col)
|
||||||
|
{
|
||||||
|
static const int NUM_ARC_PTS = 8;
|
||||||
|
static const float ARC_PTS_SCALE = 1.0f / (float)NUM_ARC_PTS;
|
||||||
|
const float dx = x1 - x0;
|
||||||
|
const float dy = y1 - y0;
|
||||||
|
const float dz = z1 - z0;
|
||||||
|
const float len = sqrtf(dx*dx + dy*dy + dz*dz);
|
||||||
|
float px = x0, py = y0, pz = z0;
|
||||||
|
for (int i = 1; i <= NUM_ARC_PTS; ++i)
|
||||||
|
{
|
||||||
|
const float u = i * ARC_PTS_SCALE;
|
||||||
|
const float x = x0 + dx * u;
|
||||||
|
const float y = y0 + dy * u + (len*h) * (1-(u*2-1)*(u*2-1));
|
||||||
|
const float z = z0 + dz * u;
|
||||||
|
dd->vertex(px,py,pz, col);
|
||||||
|
dd->vertex(x,y,z, col);
|
||||||
|
px = x; py = y; pz = z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void duAppendCircle(struct duDebugDraw* dd, const float x, const float y, const float z,
|
||||||
|
const float r, unsigned int col)
|
||||||
|
{
|
||||||
|
static const int NUM_SEG = 40;
|
||||||
|
static float dir[40*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*(float)M_PI*2;
|
||||||
|
dir[i*2] = cosf(a);
|
||||||
|
dir[i*2+1] = sinf(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0, j = NUM_SEG-1; i < NUM_SEG; j = i++)
|
||||||
|
{
|
||||||
|
dd->vertex(x+dir[j*2+0]*r, y, z+dir[j*2+1]*r, col);
|
||||||
|
dd->vertex(x+dir[i*2+0]*r, y, z+dir[i*2+1]*r, col);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void duAppendCross(struct duDebugDraw* dd, const float x, const float y, const float z,
|
||||||
|
const float s, unsigned int col)
|
||||||
|
{
|
||||||
|
dd->vertex(x-s,y,z, col);
|
||||||
|
dd->vertex(x+s,y,z, col);
|
||||||
|
dd->vertex(x,y-s,z, col);
|
||||||
|
dd->vertex(x,y+s,z, col);
|
||||||
|
dd->vertex(x,y,z-s, col);
|
||||||
|
dd->vertex(x,y,z+s, col);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,40 +20,6 @@
|
|||||||
#include "DetourDebugDraw.h"
|
#include "DetourDebugDraw.h"
|
||||||
#include "DetourNavMesh.h"
|
#include "DetourNavMesh.h"
|
||||||
|
|
||||||
static void drawBoxWire(duDebugDraw* dd, float minx, float miny, float minz, float maxx, float maxy, float maxz, const float* col)
|
|
||||||
{
|
|
||||||
unsigned int c = duRGBAf(col[0],col[1],col[2],col[3]);
|
|
||||||
|
|
||||||
// Top
|
|
||||||
dd->vertex(minx, miny, minz, c);
|
|
||||||
dd->vertex(maxx, miny, minz, c);
|
|
||||||
dd->vertex(maxx, miny, minz, c);
|
|
||||||
dd->vertex(maxx, miny, maxz, c);
|
|
||||||
dd->vertex(maxx, miny, maxz, c);
|
|
||||||
dd->vertex(minx, miny, maxz, c);
|
|
||||||
dd->vertex(minx, miny, maxz, c);
|
|
||||||
dd->vertex(minx, miny, minz, c);
|
|
||||||
|
|
||||||
// bottom
|
|
||||||
dd->vertex(minx, maxy, minz, c);
|
|
||||||
dd->vertex(maxx, maxy, minz, c);
|
|
||||||
dd->vertex(maxx, maxy, minz, c);
|
|
||||||
dd->vertex(maxx, maxy, maxz, c);
|
|
||||||
dd->vertex(maxx, maxy, maxz, c);
|
|
||||||
dd->vertex(minx, maxy, maxz, c);
|
|
||||||
dd->vertex(minx, maxy, maxz, c);
|
|
||||||
dd->vertex(minx, maxy, minz, c);
|
|
||||||
|
|
||||||
// Sides
|
|
||||||
dd->vertex(minx, miny, minz, c);
|
|
||||||
dd->vertex(minx, maxy, minz, c);
|
|
||||||
dd->vertex(maxx, miny, minz, c);
|
|
||||||
dd->vertex(maxx, maxy, minz, c);
|
|
||||||
dd->vertex(maxx, miny, maxz, c);
|
|
||||||
dd->vertex(maxx, maxy, maxz, c);
|
|
||||||
dd->vertex(minx, miny, maxz, c);
|
|
||||||
dd->vertex(minx, maxy, maxz, c);
|
|
||||||
}
|
|
||||||
|
|
||||||
static float distancePtLine2d(const float* pt, const float* p, const float* q)
|
static float distancePtLine2d(const float* pt, const float* p, const float* q)
|
||||||
{
|
{
|
||||||
@ -80,6 +46,9 @@ static void drawPolyBoundaries(duDebugDraw* dd, const dtMeshHeader* header,
|
|||||||
for (int i = 0; i < header->npolys; ++i)
|
for (int i = 0; i < header->npolys; ++i)
|
||||||
{
|
{
|
||||||
const dtPoly* p = &header->polys[i];
|
const dtPoly* p = &header->polys[i];
|
||||||
|
|
||||||
|
if (p->flags & DT_POLY_OFFMESH_LINK) continue;
|
||||||
|
|
||||||
const dtPolyDetail* pd = &header->dmeshes[i];
|
const dtPolyDetail* pd = &header->dmeshes[i];
|
||||||
|
|
||||||
for (int j = 0, nj = (int)p->nv; j < nj; ++j)
|
for (int j = 0, nj = (int)p->nv; j < nj; ++j)
|
||||||
@ -153,6 +122,9 @@ static void drawMeshTile(duDebugDraw* dd, const dtNavMesh* mesh, const dtMeshTil
|
|||||||
for (int i = 0; i < header->npolys; ++i)
|
for (int i = 0; i < header->npolys; ++i)
|
||||||
{
|
{
|
||||||
const dtPoly* p = &header->polys[i];
|
const dtPoly* p = &header->polys[i];
|
||||||
|
if (p->flags & DT_POLY_OFFMESH_LINK) // Skip off-mesh links.
|
||||||
|
continue;
|
||||||
|
|
||||||
const dtPolyDetail* pd = &header->dmeshes[i];
|
const dtPolyDetail* pd = &header->dmeshes[i];
|
||||||
|
|
||||||
unsigned int col;
|
unsigned int col;
|
||||||
@ -175,6 +147,26 @@ static void drawMeshTile(duDebugDraw* dd, const dtNavMesh* mesh, const dtMeshTil
|
|||||||
}
|
}
|
||||||
dd->end();
|
dd->end();
|
||||||
|
|
||||||
|
dd->begin(DU_DRAW_LINES, 2.0f);
|
||||||
|
for (int i = 0; i < header->npolys; ++i)
|
||||||
|
{
|
||||||
|
const dtPoly* p = &header->polys[i];
|
||||||
|
if ((p->flags & DT_POLY_OFFMESH_LINK) == 0) // Skip regular polys.
|
||||||
|
continue;
|
||||||
|
|
||||||
|
unsigned int col;
|
||||||
|
if (drawClosedList && mesh->isInClosedList(base | (dtPolyRef)i))
|
||||||
|
col = duRGBA(255,196,0,220);
|
||||||
|
else
|
||||||
|
col = duRGBA(0,196,255,220);
|
||||||
|
|
||||||
|
const float* va = &header->verts[p->v[0]*3];
|
||||||
|
const float* vb = &header->verts[p->v[1]*3];
|
||||||
|
|
||||||
|
duDebugDrawArc(dd, va[0],va[1]+0.1f,va[2], vb[0],vb[1]+0.1f,vb[2], 0.25f, col, 2.0f);
|
||||||
|
}
|
||||||
|
dd->end();
|
||||||
|
|
||||||
// Draw inter poly boundaries
|
// Draw inter poly boundaries
|
||||||
drawPolyBoundaries(dd, header, duRGBA(0,48,64,32), 1.5f, true);
|
drawPolyBoundaries(dd, header, duRGBA(0,48,64,32), 1.5f, true);
|
||||||
|
|
||||||
@ -290,7 +282,6 @@ static void drawMeshTileBVTree(duDebugDraw* dd, const dtNavMesh* mesh, const dtM
|
|||||||
const dtMeshHeader* header = tile->header;
|
const dtMeshHeader* header = tile->header;
|
||||||
|
|
||||||
// Draw BV nodes.
|
// Draw BV nodes.
|
||||||
const float col[] = { 1,1,1,0.5f };
|
|
||||||
const float cs = 1.0f / header->bvquant;
|
const float cs = 1.0f / header->bvquant;
|
||||||
dd->begin(DU_DRAW_LINES, 1.0f);
|
dd->begin(DU_DRAW_LINES, 1.0f);
|
||||||
for (int i = 0; i < header->nbvtree; ++i)
|
for (int i = 0; i < header->nbvtree; ++i)
|
||||||
@ -298,12 +289,13 @@ static void drawMeshTileBVTree(duDebugDraw* dd, const dtNavMesh* mesh, const dtM
|
|||||||
const dtBVNode* n = &header->bvtree[i];
|
const dtBVNode* n = &header->bvtree[i];
|
||||||
if (n->i < 0) // Leaf indices are positive.
|
if (n->i < 0) // Leaf indices are positive.
|
||||||
continue;
|
continue;
|
||||||
drawBoxWire(dd, header->bmin[0] + n->bmin[0]*cs,
|
duAppendBoxWire(dd, header->bmin[0] + n->bmin[0]*cs,
|
||||||
header->bmin[1] + n->bmin[1]*cs,
|
header->bmin[1] + n->bmin[1]*cs,
|
||||||
header->bmin[2] + n->bmin[2]*cs,
|
header->bmin[2] + n->bmin[2]*cs,
|
||||||
header->bmin[0] + n->bmax[0]*cs,
|
header->bmin[0] + n->bmax[0]*cs,
|
||||||
header->bmin[1] + n->bmax[1]*cs,
|
header->bmin[1] + n->bmax[1]*cs,
|
||||||
header->bmin[2] + n->bmax[2]*cs, col);
|
header->bmin[2] + n->bmax[2]*cs,
|
||||||
|
duRGBA(255,255,255,128));
|
||||||
}
|
}
|
||||||
dd->end();
|
dd->end();
|
||||||
|
|
||||||
@ -401,7 +393,7 @@ void duDebugDrawNavMeshBVTree(duDebugDraw* dd, const dtNavMesh* mesh)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void duDebugDrawNavMeshPoly(duDebugDraw* dd, const dtNavMesh* mesh, dtPolyRef ref, const float* col)
|
void duDebugDrawNavMeshPoly(duDebugDraw* dd, const dtNavMesh* mesh, dtPolyRef ref, const unsigned int col)
|
||||||
{
|
{
|
||||||
int ip = 0;
|
int ip = 0;
|
||||||
const dtMeshTile* tile = mesh->getTileByRef(ref, &ip);
|
const dtMeshTile* tile = mesh->getTileByRef(ref, &ip);
|
||||||
@ -409,9 +401,19 @@ void duDebugDrawNavMeshPoly(duDebugDraw* dd, const dtNavMesh* mesh, dtPolyRef re
|
|||||||
return;
|
return;
|
||||||
const dtMeshHeader* header = tile->header;
|
const dtMeshHeader* header = tile->header;
|
||||||
const dtPoly* p = &header->polys[ip];
|
const dtPoly* p = &header->polys[ip];
|
||||||
|
|
||||||
|
const unsigned int c = (col & 0x00ffffff) | (64 << 24);
|
||||||
|
|
||||||
|
if (p->flags & DT_POLY_OFFMESH_LINK)
|
||||||
|
{
|
||||||
|
const float* va = &header->verts[p->v[0]*3];
|
||||||
|
const float* vb = &header->verts[p->v[1]*3];
|
||||||
|
duDebugDrawArc(dd, va[0],va[1]+0.1f,va[2], vb[0],vb[1]+0.1f,vb[2], 0.25f, c, 2.0f);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
const dtPolyDetail* pd = &header->dmeshes[ip];
|
const dtPolyDetail* pd = &header->dmeshes[ip];
|
||||||
|
|
||||||
unsigned int c = duRGBAf(col[0],col[1],col[2],0.25f);
|
|
||||||
dd->begin(DU_DRAW_TRIS);
|
dd->begin(DU_DRAW_TRIS);
|
||||||
for (int i = 0; i < pd->ntris; ++i)
|
for (int i = 0; i < pd->ntris; ++i)
|
||||||
{
|
{
|
||||||
@ -426,4 +428,5 @@ void duDebugDrawNavMeshPoly(duDebugDraw* dd, const dtNavMesh* mesh, dtPolyRef re
|
|||||||
}
|
}
|
||||||
dd->end();
|
dd->end();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ void duDebugDrawTriMeshSlope(duDebugDraw* dd, const float* verts, int nverts,
|
|||||||
dd->end();
|
dd->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
static void drawBoxWire(duDebugDraw* dd,
|
static void drawBoxWire(duDebugDraw* dd,
|
||||||
float minx, float miny, float minz,
|
float minx, float miny, float minz,
|
||||||
float maxx, float maxy, float maxz,
|
float maxx, float maxy, float maxz,
|
||||||
@ -111,8 +112,8 @@ static void drawBoxWire(duDebugDraw* dd,
|
|||||||
dd->vertex(minx, miny, maxz, color);
|
dd->vertex(minx, miny, maxz, color);
|
||||||
dd->vertex(minx, maxy, maxz, color);
|
dd->vertex(minx, maxy, maxz, color);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
static void drawBox(duDebugDraw* dd,
|
/*static void drawBox(duDebugDraw* dd,
|
||||||
float minx, float miny, float minz,
|
float minx, float miny, float minz,
|
||||||
float maxx, float maxy, float maxz,
|
float maxx, float maxy, float maxz,
|
||||||
const float* col1, const float* col2)
|
const float* col1, const float* col2)
|
||||||
@ -211,7 +212,7 @@ void duDebugDrawBox(duDebugDraw* dd, float minx, float miny, float minz, float m
|
|||||||
dd->begin(DU_DRAW_QUADS,24);
|
dd->begin(DU_DRAW_QUADS,24);
|
||||||
drawBox(dd, minx, miny, minz, maxx, maxy, maxz, col1, col2);
|
drawBox(dd, minx, miny, minz, maxx, maxy, maxz, col1, col2);
|
||||||
dd->end();
|
dd->end();
|
||||||
}
|
}*/
|
||||||
|
|
||||||
static int getSpanCount(const rcHeightfield& hf)
|
static int getSpanCount(const rcHeightfield& hf)
|
||||||
{
|
{
|
||||||
@ -227,7 +228,6 @@ static int getSpanCount(const rcHeightfield& hf)
|
|||||||
|
|
||||||
void duDebugDrawHeightfieldSolid(duDebugDraw* dd, const rcHeightfield& hf)
|
void duDebugDrawHeightfieldSolid(duDebugDraw* dd, const rcHeightfield& hf)
|
||||||
{
|
{
|
||||||
static const float col0[4] = { 1,1,1,1 };
|
|
||||||
|
|
||||||
const float* orig = hf.bmin;
|
const float* orig = hf.bmin;
|
||||||
const float cs = hf.cs;
|
const float cs = hf.cs;
|
||||||
@ -236,6 +236,9 @@ void duDebugDrawHeightfieldSolid(duDebugDraw* dd, const rcHeightfield& hf)
|
|||||||
const int w = hf.width;
|
const int w = hf.width;
|
||||||
const int h = hf.height;
|
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);
|
dd->begin(DU_DRAW_QUADS);
|
||||||
|
|
||||||
for (int y = 0; y < h; ++y)
|
for (int y = 0; y < h; ++y)
|
||||||
@ -247,7 +250,7 @@ void duDebugDrawHeightfieldSolid(duDebugDraw* dd, const rcHeightfield& hf)
|
|||||||
const rcSpan* s = hf.spans[x + y*w];
|
const rcSpan* s = hf.spans[x + y*w];
|
||||||
while (s)
|
while (s)
|
||||||
{
|
{
|
||||||
drawBox(dd, fx, orig[1]+s->smin*ch, fz, fx+cs, orig[1] + s->smax*ch, fz+cs, col0, col0);
|
duAppendBox(dd, fx, orig[1]+s->smin*ch, fz, fx+cs, orig[1] + s->smax*ch, fz+cs, fcol);
|
||||||
s = s->next;
|
s = s->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -257,11 +260,6 @@ void duDebugDrawHeightfieldSolid(duDebugDraw* dd, const rcHeightfield& hf)
|
|||||||
|
|
||||||
void duDebugDrawHeightfieldWalkable(duDebugDraw* dd, const rcHeightfield& hf)
|
void duDebugDrawHeightfieldWalkable(duDebugDraw* dd, const rcHeightfield& hf)
|
||||||
{
|
{
|
||||||
static const float colb[4] = {0.85f,0.85f,0.85f,1 }; // Base
|
|
||||||
static const float col0[4] = {0.5f, 0.75f, 0.85f,1}; // Culled
|
|
||||||
static const float col1[4] = {0.3f, 0.55f, 0.65f, 1}; // Walkable
|
|
||||||
static const float col2[4] = {0.15f, 0.4f, 0.5f,1}; // Ledge
|
|
||||||
|
|
||||||
const float* orig = hf.bmin;
|
const float* orig = hf.bmin;
|
||||||
const float cs = hf.cs;
|
const float cs = hf.cs;
|
||||||
const float ch = hf.ch;
|
const float ch = hf.ch;
|
||||||
@ -269,6 +267,11 @@ void duDebugDrawHeightfieldWalkable(duDebugDraw* dd, const rcHeightfield& hf)
|
|||||||
const int w = hf.width;
|
const int w = hf.width;
|
||||||
const int h = hf.height;
|
const int h = hf.height;
|
||||||
|
|
||||||
|
unsigned int fcol0[6], fcol1[6], fcol2[6];
|
||||||
|
duCalcBoxColors(fcol0, duRGBA(128,192,217,255), duRGBA(217,217,217,255)); // Culled
|
||||||
|
duCalcBoxColors(fcol1, duRGBA(77,140,165,255), duRGBA(217,217,217,255)); // Walkable
|
||||||
|
duCalcBoxColors(fcol2, duRGBA(38,102,128,255), duRGBA(217,217,217,255)); // Ledge
|
||||||
|
|
||||||
dd->begin(DU_DRAW_QUADS);
|
dd->begin(DU_DRAW_QUADS);
|
||||||
|
|
||||||
for (int y = 0; y < h; ++y)
|
for (int y = 0; y < h; ++y)
|
||||||
@ -280,12 +283,12 @@ void duDebugDrawHeightfieldWalkable(duDebugDraw* dd, const rcHeightfield& hf)
|
|||||||
const rcSpan* s = hf.spans[x + y*w];
|
const rcSpan* s = hf.spans[x + y*w];
|
||||||
while (s)
|
while (s)
|
||||||
{
|
{
|
||||||
const float* c = col0;
|
const unsigned int* c = fcol0;
|
||||||
if (s->flags & RC_LEDGE)
|
if (s->flags & RC_LEDGE)
|
||||||
c = col2;
|
c = fcol2;
|
||||||
else if (s->flags & RC_WALKABLE)
|
else if (s->flags & RC_WALKABLE)
|
||||||
c = col1;
|
c = fcol1;
|
||||||
drawBox(dd, fx, orig[1]+s->smin*ch, fz, fx+cs, orig[1] + s->smax*ch, fz+cs, colb, c);
|
duAppendBox(dd, fx, orig[1]+s->smin*ch, fz, fx+cs, orig[1] + s->smax*ch, fz+cs, c);
|
||||||
s = s->next;
|
s = s->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -432,7 +435,7 @@ static const rcContour* findContourFromSet(const rcContourSet& cset, unsigned sh
|
|||||||
|
|
||||||
static const int NUM_ADU_PTS = 8;
|
static const int NUM_ADU_PTS = 8;
|
||||||
|
|
||||||
static void drawArc(duDebugDraw* dd, const float* p0, const float* p1, unsigned int color)
|
void drawArc(duDebugDraw* dd, const float* p0, const float* p1, unsigned int color)
|
||||||
{
|
{
|
||||||
// Submits NPTS*2 vertices.
|
// Submits NPTS*2 vertices.
|
||||||
float pts[NUM_ADU_PTS*3];
|
float pts[NUM_ADU_PTS*3];
|
||||||
@ -462,6 +465,19 @@ void duDebugDrawArc(duDebugDraw* dd, const float* p0, const float* p1, const flo
|
|||||||
dd->end();
|
dd->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void duDebugDrawCross(struct duDebugDraw* dd, const float* p, const float s, const float dy, const float* col, float lineWidth)
|
||||||
|
{
|
||||||
|
const unsigned int color = duRGBAf(col[0],col[1],col[2],col[3]);
|
||||||
|
dd->begin(DU_DRAW_LINES, lineWidth);
|
||||||
|
dd->vertex(p[0]-s,p[1]+dy,p[2], color);
|
||||||
|
dd->vertex(p[0]+s,p[1]+dy,p[2], color);
|
||||||
|
dd->vertex(p[0],p[1]-s+dy,p[2], color);
|
||||||
|
dd->vertex(p[0],p[1]+s+dy,p[2], color);
|
||||||
|
dd->vertex(p[0],p[1]+dy,p[2]-s, color);
|
||||||
|
dd->vertex(p[0],p[1]+dy,p[2]+s, color);
|
||||||
|
dd->end();
|
||||||
|
}
|
||||||
|
|
||||||
void duDebugDrawRegionConnections(duDebugDraw* dd, const rcContourSet& cset, const float alpha)
|
void duDebugDrawRegionConnections(duDebugDraw* dd, const rcContourSet& cset, const float alpha)
|
||||||
{
|
{
|
||||||
const float* orig = cset.bmin;
|
const float* orig = cset.bmin;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user