Tweaked debug draw to better fit the Paris conferene setup.
Rewrote fixup contours, now should handle all cases. Added few more debug draw modes for the demo. Changed the vertex welding to cope with slight imprecision in y-direction.
This commit is contained in:
parent
c5d43c8029
commit
ab372964ad
@ -73,6 +73,7 @@ public:
|
||||
// Params:
|
||||
// center - (in) The center of the search box.
|
||||
// extents - (in) The extents of the search box.
|
||||
// Returns: Reference identifier for the polygon, or 0 if no polygons found.
|
||||
dtPolyRef findNearestPoly(const float* center, const float* extents);
|
||||
|
||||
// Returns polygons which touch the query box.
|
||||
@ -107,6 +108,7 @@ public:
|
||||
// pathSize - (in) Number of polygons in path array.
|
||||
// straightPath - (out) Points describing the straight path.
|
||||
// maxStraightPathSize - (in) The max number of points the straight path array can hold.
|
||||
// Returns: Number of points in the path.
|
||||
int findStraightPath(const float* startPos, const float* endPos,
|
||||
const dtPolyRef* path, const int pathSize,
|
||||
float* straightPath, const int maxStraightPathSize);
|
||||
@ -154,6 +156,7 @@ public:
|
||||
// ref - (in) ref to the polygon.
|
||||
// pos - (in) the point to check.
|
||||
// closest - (out) closest point.
|
||||
// Returns: true if closest point found.
|
||||
bool closestPointToPoly(dtPolyRef ref, const float* pos, float* closest) const;
|
||||
|
||||
// Returns cost between two polygons.
|
||||
|
@ -126,8 +126,8 @@ void dtDebugDrawStatNavMesh(const dtStatNavMesh* mesh)
|
||||
glEnd();
|
||||
|
||||
// Draw tri boundaries
|
||||
glColor4ub(0,0,0,64);
|
||||
glLineWidth(1.0f);
|
||||
glColor4ub(0,48,64,32);
|
||||
glLineWidth(1.5f);
|
||||
glBegin(GL_LINES);
|
||||
for (int i = 0; i < mesh->getPolyCount(); ++i)
|
||||
{
|
||||
@ -148,8 +148,8 @@ void dtDebugDrawStatNavMesh(const dtStatNavMesh* mesh)
|
||||
glEnd();
|
||||
|
||||
// Draw boundaries
|
||||
glLineWidth(3.0f);
|
||||
glColor4ub(0,0,0,128);
|
||||
glLineWidth(2.5f);
|
||||
glColor4ub(0,48,64,220);
|
||||
glBegin(GL_LINES);
|
||||
for (int i = 0; i < mesh->getPolyCount(); ++i)
|
||||
{
|
||||
|
@ -121,6 +121,16 @@ inline float triArea2D(const float* a, const float* b, const float* c)
|
||||
return ((b[0]*a[2] - a[0]*b[2]) + (c[0]*b[2] - b[0]*c[2]) + (a[0]*c[2] - c[0]*a[2])) * 0.5f;
|
||||
}
|
||||
|
||||
inline bool checkOverlapBox(const unsigned short amin[3], const unsigned short amax[3],
|
||||
const unsigned short bmin[3], const unsigned short bmax[3])
|
||||
{
|
||||
bool overlap = true;
|
||||
overlap = (amin[0] > bmax[0] || amax[0] < bmin[0]) ? false : overlap;
|
||||
overlap = (amin[1] > bmax[1] || amax[1] < bmin[1]) ? false : overlap;
|
||||
overlap = (amin[2] > bmax[2] || amax[2] < bmin[2]) ? false : overlap;
|
||||
return overlap;
|
||||
}
|
||||
|
||||
static void closestPtPointTriangle(float* closest, const float* p,
|
||||
const float* a, const float* b, const float* c)
|
||||
{
|
||||
@ -604,7 +614,7 @@ unsigned short dtStatNavMesh::getCost(dtPolyRef from, dtPolyRef to) const
|
||||
float fromPc[3], toPc[3];
|
||||
calcPolyCenter(fromPc, fromPoly, m_verts);
|
||||
calcPolyCenter(toPc, toPoly, m_verts);
|
||||
int cost = (int)sqrtf(sqr(fromPc[0]-toPc[0]) + sqr(fromPc[2]-toPc[2]));
|
||||
int cost = (int)(sqrtf(sqr(fromPc[0]-toPc[0]) + sqr(fromPc[2]-toPc[2])) * 4.0f);
|
||||
if (cost < 1) cost = 1;
|
||||
if (cost > 0xffff) cost = 0xffff;
|
||||
return cost;
|
||||
@ -1188,16 +1198,6 @@ int dtStatNavMesh::findPolysAround(dtPolyRef centerRef, const float* centerPos,
|
||||
return n;
|
||||
}
|
||||
|
||||
inline bool checkOverlapBox(const unsigned short amin[3], const unsigned short amax[3],
|
||||
const unsigned short bmin[3], const unsigned short bmax[3])
|
||||
{
|
||||
bool overlap = true;
|
||||
overlap = (amin[0] > bmax[0] || amax[0] < bmin[0]) ? false : overlap;
|
||||
overlap = (amin[1] > bmax[1] || amax[1] < bmin[1]) ? false : overlap;
|
||||
overlap = (amin[2] > bmax[2] || amax[2] < bmin[2]) ? false : overlap;
|
||||
return overlap;
|
||||
}
|
||||
|
||||
// Returns polygons which are withing certain radius from the query location.
|
||||
int dtStatNavMesh::queryPolygons(const float* center, const float* extents,
|
||||
unsigned short* ids, const int maxIds)
|
||||
|
@ -213,6 +213,8 @@ bool dtCreateNavMeshData(const unsigned short* verts, const int nverts,
|
||||
{
|
||||
if (nvp != DT_VERTS_PER_POLYGON)
|
||||
return false;
|
||||
if (nverts >= 0xffff)
|
||||
return false;
|
||||
|
||||
if (!nverts)
|
||||
return false;
|
||||
|
@ -379,13 +379,13 @@ bool rcBuildContours(rcCompactHeightfield& chf,
|
||||
// Params:
|
||||
// cseta - (in) contour set A.
|
||||
// csetb - (in) contour set B.
|
||||
// edge - (in) which edge to conform: 1) B is left of A 2) B is top of A
|
||||
// borderSize - (in) the border which was used when the contours were generated.
|
||||
// tileSize - (in) the tile size which was used when the contours were generated.
|
||||
// walkableHeight - (in) minimum height where the agent can still walk
|
||||
// edgex, edgey - (in) defines the planes where the edges can be merged
|
||||
// orig - (in) origin of the contour set A.
|
||||
// cs - (in) grid cell size
|
||||
// ch - (in) grid cell height
|
||||
bool rcFixupAdjacentContours(rcContourSet* cseta, rcContourSet* csetb, int edge, int edgePos);
|
||||
bool rcFixupAdjacentContours(rcContourSet* cseta, rcContourSet* csetb,
|
||||
const int walkableClimb, const int edgex, const int edgez);
|
||||
|
||||
// Translates the cordinates of the contour set.
|
||||
// Params:
|
||||
|
@ -47,7 +47,7 @@ void rcDebugDrawCompactHeightfieldSolid(const struct rcCompactHeightfield& chf);
|
||||
void rcDebugDrawCompactHeightfieldRegions(const struct rcCompactHeightfield& chf);
|
||||
void rcDebugDrawCompactHeightfieldDistance(const struct rcCompactHeightfield& chf);
|
||||
|
||||
void rcDebugDrawRawContours(const struct rcContourSet& cset, const float* orig, float cs, float ch);
|
||||
void rcDebugDrawRawContours(const struct rcContourSet& cset, const float* orig, float cs, float ch, const float alpha = 1.0f);
|
||||
void rcDebugDrawContours(const struct rcContourSet& cset, const float* orig, float cs, float ch);
|
||||
void rcDebugDrawPolyMesh(const struct rcPolyMesh& mesh);
|
||||
|
||||
@ -56,5 +56,4 @@ void rcDebugDrawBoxWire(float minx, float miny, float minz, float maxx, float ma
|
||||
void rcDebugDrawBox(float minx, float miny, float minz, float maxx, float maxy, float maxz,
|
||||
const float* col1, const float* col2);
|
||||
|
||||
|
||||
#endif // RECAST_DEBUGDRAW_H
|
@ -146,7 +146,7 @@ static float distancePtSeg(int x, int y, int z,
|
||||
int px, int py, int pz,
|
||||
int qx, int qy, int qz)
|
||||
{
|
||||
float pqx = (float)(qx - px);
|
||||
/* float pqx = (float)(qx - px);
|
||||
float pqy = (float)(qy - py);
|
||||
float pqz = (float)(qz - pz);
|
||||
float dx = (float)(x - px);
|
||||
@ -165,7 +165,25 @@ static float distancePtSeg(int x, int y, int z,
|
||||
dy = py + t*pqy - y;
|
||||
dz = pz + t*pqz - z;
|
||||
|
||||
return dx*dx + dy*dy + dz*dz;
|
||||
return dx*dx + dy*dy + dz*dz;*/
|
||||
|
||||
float pqx = (float)(qx - px);
|
||||
float pqz = (float)(qz - pz);
|
||||
float dx = (float)(x - px);
|
||||
float dz = (float)(z - pz);
|
||||
float d = pqx*pqx + pqz*pqz;
|
||||
float t = pqx*dx + pqz*dz;
|
||||
if (d > 0)
|
||||
t /= d;
|
||||
if (t < 0)
|
||||
t = 0;
|
||||
else if (t > 1)
|
||||
t = 1;
|
||||
|
||||
dx = px + t*pqx - x;
|
||||
dz = pz + t*pqz - z;
|
||||
|
||||
return dx*dx + dz*dz;
|
||||
}
|
||||
|
||||
static void simplifyContour(rcIntArray& points, rcIntArray& simplified, float maxError, int maxEdgeLen)
|
||||
@ -672,84 +690,6 @@ bool rcBuildContours(rcCompactHeightfield& chf,
|
||||
return true;
|
||||
}
|
||||
|
||||
struct EdgeSegment
|
||||
{
|
||||
int i0, i1;
|
||||
int v0[3], v1[3];
|
||||
};
|
||||
|
||||
static int findEdgeSegments(rcContourSet* cset, int x, int z, EdgeSegment* segs, const int maxSegs)
|
||||
{
|
||||
int n = 0;
|
||||
|
||||
for (int i = 0; i < cset->nconts; ++i)
|
||||
{
|
||||
const rcContour* c = &cset->conts[i];
|
||||
const int nc = n;
|
||||
for (int j = 0, k = c->nverts-1; j < c->nverts; k=j++)
|
||||
{
|
||||
const int* v0 = &c->verts[k*4];
|
||||
const int* v1 = &c->verts[j*4];
|
||||
if ((v0[0] == x && v1[0] == x) || (v0[2] == z && v1[2] == z))
|
||||
{
|
||||
if (n && segs[n-1].i1 == k)
|
||||
{
|
||||
// Merge with previous
|
||||
segs[n-1].i1 = j;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add new
|
||||
if (n >= maxSegs)
|
||||
return n;
|
||||
segs[n].i0 = k;
|
||||
segs[n].i1 = j;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check if first and last should be merged.
|
||||
if (n && n && segs[n-1].v1 == segs[nc].v0)
|
||||
{
|
||||
segs[nc].i0 = segs[n-1].i0;
|
||||
n--;
|
||||
}
|
||||
// Copy vertices
|
||||
for (int j = nc; j < n; ++j)
|
||||
{
|
||||
segs[j].v0[0] = c->verts[segs[j].i0*4+0];
|
||||
segs[j].v0[1] = c->verts[segs[j].i0*4+1];
|
||||
segs[j].v0[2] = c->verts[segs[j].i0*4+2];
|
||||
segs[j].v1[0] = c->verts[segs[j].i1*4+0];
|
||||
segs[j].v1[1] = c->verts[segs[j].i1*4+1];
|
||||
segs[j].v1[2] = c->verts[segs[j].i1*4+2];
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static bool pointOnEdgeSegment(const int* v0, const int* v1, int x, int z)
|
||||
{
|
||||
const int dx = v1[0] - v0[0];
|
||||
const int dz = v1[2] - v0[2];
|
||||
if (rcAbs(dx) > rcAbs(dz))
|
||||
{
|
||||
const int d = x - v0[0];
|
||||
if (dx < 0)
|
||||
return d < 0 && d > dx;
|
||||
else
|
||||
return d > 0 && d < dx;
|
||||
}
|
||||
else
|
||||
{
|
||||
const int d = z - v0[2];
|
||||
if (dz < 0)
|
||||
return d < 0 && d > dz;
|
||||
else
|
||||
return d > 0 && d < dz;
|
||||
}
|
||||
}
|
||||
|
||||
static bool insertPoint(rcContour* c, int idx, const int* v)
|
||||
{
|
||||
int* newVerts = new int[(c->nverts+1)*4];
|
||||
@ -779,143 +719,131 @@ static bool insertPoint(rcContour* c, int idx, const int* v)
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool ptsEqual(const int* a, const int* b)
|
||||
static void calcBox(const int* v0, const int* v1, int* bounds)
|
||||
{
|
||||
return a[0] == b[0] && a[1] == b[1] && a[2] == b[2];
|
||||
bounds[0] = rcMin(v0[0], v1[0]);
|
||||
bounds[1] = rcMin(v0[1], v1[1]);
|
||||
bounds[2] = rcMin(v0[2], v1[2]);
|
||||
bounds[3] = rcMax(v0[0], v1[0]);
|
||||
bounds[4] = rcMax(v0[1], v1[1]);
|
||||
bounds[5] = rcMax(v0[2], v1[2]);
|
||||
}
|
||||
|
||||
static bool conformEdge(rcContourSet* cset, int ex, int ez, const int* v0, const int* v1)
|
||||
/*inline bool checkOverlapBoxY(const int* a, const int* b)
|
||||
{
|
||||
bool overlap = true;
|
||||
overlap = (a[0] >= b[3+0] || a[3+0] <= b[0]) ? false : overlap;
|
||||
overlap = (a[1] >= b[3+1] || a[3+1] <= b[1]) ? false : overlap;
|
||||
overlap = (a[2] >= b[3+2] || a[3+2] <= b[2]) ? false : overlap;
|
||||
return overlap;
|
||||
}*/
|
||||
|
||||
inline bool checkOverlapBoxY(const int* a, const int* b)
|
||||
{
|
||||
bool overlap = true;
|
||||
overlap = (a[1] > b[3+1] || a[3+1] < b[1]) ? false : overlap;
|
||||
return overlap;
|
||||
}
|
||||
|
||||
static bool conformVertex(rcContourSet* cset, const int* v,
|
||||
const int pminy, const int pmaxy,
|
||||
const int nminy, const int nmaxy,
|
||||
const int walkableClimb)
|
||||
{
|
||||
for (int i = 0; i < cset->nconts; ++i)
|
||||
{
|
||||
rcContour* c = &cset->conts[i];
|
||||
const int nv = c->nverts;
|
||||
for (int j = 0; j < nv; ++j)
|
||||
for (int j = 0; j < c->nverts; ++j)
|
||||
{
|
||||
const int* v = &c->verts[j*4];
|
||||
if (ptsEqual(v, v0))
|
||||
{
|
||||
const int jn = (j+1) % nv;
|
||||
const int* vn = &c->verts[jn*4];
|
||||
const int k = (j+1) % c->nverts;
|
||||
const int* vj = &c->verts[j*4];
|
||||
const int* vk = &c->verts[k*4];
|
||||
|
||||
// Check if the segment is edge segment.
|
||||
if ((v[0] == ex && vn[0] == ex) || (v[2] == ez && vn[2] == ez))
|
||||
const int miny = rcMin(vj[1], vk[1]); // - (walkableClimb-1);
|
||||
const int maxy = rcMax(vj[1], vk[1]); // + (walkableClimb-1);
|
||||
|
||||
// Is edge within y-range.
|
||||
if ((miny > pmaxy || maxy < pminy) &&
|
||||
(miny > nmaxy || maxy < nminy))
|
||||
continue;
|
||||
|
||||
if (vj[0] == vk[0] && vj[0] == v[0])
|
||||
{
|
||||
// The segment is x edge.
|
||||
const int minz = rcMin(vj[2], vk[2]);
|
||||
const int maxz = rcMax(vj[2], vk[2]);
|
||||
if (v[2] > minz && v[2] < maxz)
|
||||
{
|
||||
if (ptsEqual(vn, v1))
|
||||
{
|
||||
// Valid!
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add new vertex
|
||||
if (pointOnEdgeSegment(v, vn, v1[0], v1[2]))
|
||||
{
|
||||
if (!insertPoint(c, jn, v1))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return insertPoint(c, j+1, v);
|
||||
}
|
||||
}
|
||||
else if (ptsEqual(v, v1))
|
||||
else if (vj[2] == vk[2] && vj[2] == v[2])
|
||||
{
|
||||
const int jp = (j+nv-1) % nv;
|
||||
const int* vp = &c->verts[jp*4];
|
||||
// Check if the segment is edge segment.
|
||||
if ((v[0] == ex && vp[0] == ex) || (v[2] == ez && vp[2] == ez))
|
||||
// The segment is z edge.
|
||||
const int minx = rcMin(vj[0], vk[0]);
|
||||
const int maxx = rcMax(vj[0], vk[0]);
|
||||
if (v[0] > minx && v[0] < maxx)
|
||||
{
|
||||
if (ptsEqual(vp, v0))
|
||||
{
|
||||
// Valid!
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add new vertex
|
||||
if (pointOnEdgeSegment(vp, v, v0[0], v0[2]))
|
||||
{
|
||||
if (!insertPoint(c, j, v0))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return insertPoint(c, j+1, v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool rcFixupAdjacentContours(rcContourSet* cseta, rcContourSet* csetb,
|
||||
int edge, int edgePos)
|
||||
const int walkableClimb, const int edgex, const int edgez)
|
||||
{
|
||||
if (!cseta || !csetb)
|
||||
return true;
|
||||
|
||||
rcTimeVal startTime = rcGetPerformanceTimer();
|
||||
|
||||
if (edge == 1)
|
||||
// int nbox[6], pbox[6];
|
||||
|
||||
for (int i = 0; i < cseta->nconts; ++i)
|
||||
{
|
||||
// x+1
|
||||
// Find edge segment
|
||||
static const int MAX_SEGS = 512; // TODO: Do not hardcode.
|
||||
EdgeSegment sa[MAX_SEGS], sb[MAX_SEGS];
|
||||
int nsa = findEdgeSegments(cseta, edgePos, -1, sa, MAX_SEGS);
|
||||
int nsb = findEdgeSegments(csetb, edgePos, -1, sb, MAX_SEGS);
|
||||
|
||||
// Conform set A to set B
|
||||
for (int i = 0; i < nsb; ++i)
|
||||
const rcContour& c = cseta->conts[i];
|
||||
for (int j = 0; j < c.nverts; ++j)
|
||||
{
|
||||
const int* v0 = sb[i].v0;
|
||||
const int* v1 = sb[i].v1;
|
||||
if (!conformEdge(cseta, edgePos, -1, v1, v0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const int* v = &c.verts[j*4];
|
||||
const int* pv = &c.verts[((j+c.nverts-1)%c.nverts)*4];
|
||||
const int* nv = &c.verts[((j+1)%c.nverts)*4];
|
||||
|
||||
// Conform set B to set A
|
||||
for (int i = 0; i < nsa; ++i)
|
||||
{
|
||||
const int* v0 = sa[i].v0;
|
||||
const int* v1 = sa[i].v1;
|
||||
if (!conformEdge(csetb, edgePos, -1, v1, v0))
|
||||
// if (v[0] == edgex || v[2] == edgez)
|
||||
{
|
||||
return false;
|
||||
const int pminy = rcMin(v[1], pv[1]);
|
||||
const int pmaxy = rcMax(v[1], pv[1]);
|
||||
const int nminy = rcMin(v[1], nv[1]);
|
||||
const int nmaxy = rcMax(v[1], nv[1]);
|
||||
|
||||
if (!conformVertex(csetb, v, pminy, pmaxy, nminy, nmaxy, walkableClimb))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (edge == 2)
|
||||
|
||||
for (int i = 0; i < csetb->nconts; ++i)
|
||||
{
|
||||
// y+1
|
||||
// Find edge segment
|
||||
static const int MAX_SEGS = 512; // TODO: Do not hardcode.
|
||||
EdgeSegment sa[MAX_SEGS], sb[MAX_SEGS];
|
||||
int nsa = findEdgeSegments(cseta, -1, edgePos, sa, MAX_SEGS);
|
||||
int nsb = findEdgeSegments(csetb, -1, edgePos, sb, MAX_SEGS);
|
||||
|
||||
// Conform set A to set B
|
||||
for (int i = 0; i < nsb; ++i)
|
||||
const rcContour& c = csetb->conts[i];
|
||||
for (int j = 0; j < c.nverts; ++j)
|
||||
{
|
||||
const int* v0 = sb[i].v0;
|
||||
const int* v1 = sb[i].v1;
|
||||
if (!conformEdge(cseta, -1, edgePos, v1, v0))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const int* v = &c.verts[j*4];
|
||||
const int* pv = &c.verts[((j+c.nverts-1)%c.nverts)*4];
|
||||
const int* nv = &c.verts[((j+1)%c.nverts)*4];
|
||||
|
||||
// Conform set B to set A
|
||||
for (int i = 0; i < nsa; ++i)
|
||||
{
|
||||
const int* v0 = sa[i].v0;
|
||||
const int* v1 = sa[i].v1;
|
||||
if (!conformEdge(csetb, -1, edgePos, v1, v0))
|
||||
// If the vertex is at the tile edge, make sure it also exists in
|
||||
// the neighbour contour set.
|
||||
// if (v[0] == edgex || v[2] == edgez)
|
||||
{
|
||||
return false;
|
||||
const int pminy = rcMin(v[1], pv[1]);
|
||||
const int pmaxy = rcMax(v[1], pv[1]);
|
||||
const int nminy = rcMin(v[1], nv[1]);
|
||||
const int nmaxy = rcMax(v[1], nv[1]);
|
||||
|
||||
if (!conformVertex(cseta, v, pminy, pmaxy, nminy, nmaxy, walkableClimb))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ void rcDebugDrawHeightfieldWalkable(const rcHeightfield& hf,
|
||||
const rcSpan* s = hf.spans[x + y*w];
|
||||
while (s)
|
||||
{
|
||||
bool csel = (s->flags & 0x2) == 0;
|
||||
bool csel = (s->flags & 0x1) == 0;
|
||||
drawBox(fx, orig[1]+s->smin*ch, fz, fx+cs, orig[1] + s->smax*ch, fz+cs, col0, csel ? col0 : col1);
|
||||
s = s->next;
|
||||
}
|
||||
@ -355,10 +355,11 @@ void rcDebugDrawCompactHeightfieldDistance(const rcCompactHeightfield& chf)
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void rcDebugDrawRawContours(const rcContourSet& cset, const float* orig, float cs, float ch)
|
||||
void rcDebugDrawRawContours(const rcContourSet& cset, const float* orig, float cs, float ch, const float alpha)
|
||||
{
|
||||
float col[4] = { 1,1,1,1 };
|
||||
glLineWidth(3.0f);
|
||||
float col[4] = { 1,1,1,alpha };
|
||||
glLineWidth(2.0f);
|
||||
glPointSize(2.0f);
|
||||
for (int i = 0; i < cset.nconts; ++i)
|
||||
{
|
||||
const rcContour& c = cset.conts[i];
|
||||
@ -374,15 +375,32 @@ void rcDebugDrawRawContours(const rcContourSet& cset, const float* orig, float c
|
||||
glVertex3f(fx,fy,fz);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
col[0] *= 0.5f;
|
||||
col[1] *= 0.5f;
|
||||
col[2] *= 0.5f;
|
||||
glColor4fv(col);
|
||||
|
||||
glBegin(GL_POINTS);
|
||||
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;
|
||||
glVertex3f(fx,fy,fz);
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
glLineWidth(1.0f);
|
||||
glPointSize(1.0f);
|
||||
}
|
||||
|
||||
void rcDebugDrawContours(const rcContourSet& cset, const float* orig, float cs, float ch)
|
||||
{
|
||||
float col[4] = { 1,1,1,1 };
|
||||
glLineWidth(3.0f);
|
||||
glPointSize(4.0f);
|
||||
glLineWidth(2.5f);
|
||||
glPointSize(3.0f);
|
||||
for (int i = 0; i < cset.nconts; ++i)
|
||||
{
|
||||
const rcContour& c = cset.conts[i];
|
||||
@ -400,7 +418,10 @@ void rcDebugDrawContours(const rcContourSet& cset, const float* orig, float cs,
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glColor4ub(0,0,0,128);
|
||||
col[0] *= 0.5f;
|
||||
col[1] *= 0.5f;
|
||||
col[2] *= 0.5f;
|
||||
glColor4fv(col);
|
||||
glBegin(GL_POINTS);
|
||||
for (int j = 0; j < c.nverts; ++j)
|
||||
{
|
||||
@ -447,8 +468,8 @@ void rcDebugDrawPolyMesh(const struct rcPolyMesh& mesh)
|
||||
glEnd();
|
||||
|
||||
// Draw tri boundaries
|
||||
glColor4ub(0,0,0,64);
|
||||
glLineWidth(1.0f);
|
||||
glColor4ub(0,48,64,32);
|
||||
glLineWidth(1.5f);
|
||||
glBegin(GL_LINES);
|
||||
for (int i = 0; i < mesh.npolys; ++i)
|
||||
{
|
||||
@ -476,8 +497,8 @@ void rcDebugDrawPolyMesh(const struct rcPolyMesh& mesh)
|
||||
glEnd();
|
||||
|
||||
// Draw boundaries
|
||||
glLineWidth(3.0f);
|
||||
glColor4ub(0,0,0,128);
|
||||
glLineWidth(2.5f);
|
||||
glColor4ub(0,48,64,220);
|
||||
glBegin(GL_LINES);
|
||||
for (int i = 0; i < mesh.npolys; ++i)
|
||||
{
|
||||
@ -506,7 +527,7 @@ void rcDebugDrawPolyMesh(const struct rcPolyMesh& mesh)
|
||||
glLineWidth(1.0f);
|
||||
|
||||
glPointSize(3.0f);
|
||||
glColor4ub(0,0,0,64);
|
||||
glColor4ub(0,0,0,220);
|
||||
glBegin(GL_POINTS);
|
||||
for (int i = 0; i < mesh.nverts; ++i)
|
||||
{
|
||||
|
@ -136,13 +136,14 @@ inline int computeVertexHash(int x, int y, int z)
|
||||
static int addVertex(unsigned short x, unsigned short y, unsigned short z,
|
||||
unsigned short* verts, int* firstVert, int* nextVert, int& nv)
|
||||
{
|
||||
int bucket = computeVertexHash(x, y, z);
|
||||
int bucket = computeVertexHash(x, 0/*y*/, z);
|
||||
int i = firstVert[bucket];
|
||||
|
||||
while (i != -1)
|
||||
{
|
||||
const unsigned short* v = &verts[i*3];
|
||||
if (v[0] == x && v[1] == y && v[2] == z)
|
||||
// if (v[0] == x && v[1] == y && v[2] == z)
|
||||
if (v[0] == x && (rcAbs(v[1] - y) <= 2) && v[2] == z)
|
||||
return i;
|
||||
i = nextVert[i]; // next
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -284,7 +284,7 @@
|
||||
</array>
|
||||
</array>
|
||||
<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
|
||||
<string>{{0, 13}, {228, 660}}</string>
|
||||
<string>{{0, 0}, {228, 660}}</string>
|
||||
</dict>
|
||||
<key>PBXTopSmartGroupGIDs</key>
|
||||
<array/>
|
||||
@ -331,37 +331,38 @@
|
||||
<key>_historyCapacity</key>
|
||||
<integer>0</integer>
|
||||
<key>bookmark</key>
|
||||
<string>6BB788880FC05FB2003C24DB</string>
|
||||
<string>6B09CE770FD5BEC6005637D5</string>
|
||||
<key>history</key>
|
||||
<array>
|
||||
<string>6B8633370F7813A600E2684A</string>
|
||||
<string>6B8DB3890F9798DE007FA9E1</string>
|
||||
<string>6B8DB38A0F9798DE007FA9E1</string>
|
||||
<string>6BB87E0B0F9DE8A300E33F12</string>
|
||||
<string>6B77074C0FBD597500D21BAE</string>
|
||||
<string>6B77074D0FBD597500D21BAE</string>
|
||||
<string>6B7707710FBD5DB300D21BAE</string>
|
||||
<string>6B7707AF0FBD66CF00D21BAE</string>
|
||||
<string>6B7707EF0FBD90F100D21BAE</string>
|
||||
<string>6B7707F00FBD90F100D21BAE</string>
|
||||
<string>6B7707F30FBD90F100D21BAE</string>
|
||||
<string>6B7708F20FBDA96300D21BAE</string>
|
||||
<string>6BB787680FC03EAD003C24DB</string>
|
||||
<string>6BB7876A0FC03EAD003C24DB</string>
|
||||
<string>6BB7876B0FC03EAD003C24DB</string>
|
||||
<string>6BB7876C0FC03EAD003C24DB</string>
|
||||
<string>6BB7876D0FC03EAD003C24DB</string>
|
||||
<string>6BB787710FC03EAD003C24DB</string>
|
||||
<string>6BB7881E0FC0593E003C24DB</string>
|
||||
<string>6BB7881F0FC0593E003C24DB</string>
|
||||
<string>6BB788200FC0593E003C24DB</string>
|
||||
<string>6BB788220FC0593E003C24DB</string>
|
||||
<string>6BB788230FC0593E003C24DB</string>
|
||||
<string>6BB788240FC0593E003C24DB</string>
|
||||
<string>6BB788550FC05C2E003C24DB</string>
|
||||
<string>6BB7886F0FC05EB9003C24DB</string>
|
||||
<string>6BB788820FC05FA5003C24DB</string>
|
||||
<string>6BB788830FC05FA5003C24DB</string>
|
||||
<string>6B8171D70FC327630022159F</string>
|
||||
<string>6B8AD2EA0FCDE25800016452</string>
|
||||
<string>6BB85D1A0FCEA5BD00758966</string>
|
||||
<string>6BB85D2F0FCEA8BE00758966</string>
|
||||
<string>6BB85D3A0FCEAA6300758966</string>
|
||||
<string>6B09CDFF0FD5563E005637D5</string>
|
||||
<string>6B09CE5A0FD5BDE6005637D5</string>
|
||||
<string>6B09CE5B0FD5BDE6005637D5</string>
|
||||
<string>6B09CE5C0FD5BDE6005637D5</string>
|
||||
<string>6B09CE5D0FD5BDE6005637D5</string>
|
||||
<string>6B09CE5E0FD5BDE6005637D5</string>
|
||||
<string>6B09CE5F0FD5BDE6005637D5</string>
|
||||
<string>6B09CE730FD5BEC3005637D5</string>
|
||||
<string>6B09CE740FD5BEC3005637D5</string>
|
||||
</array>
|
||||
<key>prevStack</key>
|
||||
<array>
|
||||
@ -384,128 +385,45 @@
|
||||
<string>6B7707F70FBD90F100D21BAE</string>
|
||||
<string>6B7707F90FBD90F100D21BAE</string>
|
||||
<string>6B7708F70FBDA96300D21BAE</string>
|
||||
<string>6BB787750FC03EAD003C24DB</string>
|
||||
<string>6BB787760FC03EAD003C24DB</string>
|
||||
<string>6BB787770FC03EAD003C24DB</string>
|
||||
<string>6BB787780FC03EAD003C24DB</string>
|
||||
<string>6BB787790FC03EAD003C24DB</string>
|
||||
<string>6BB7877A0FC03EAD003C24DB</string>
|
||||
<string>6BB7877B0FC03EAD003C24DB</string>
|
||||
<string>6BB7877C0FC03EAD003C24DB</string>
|
||||
<string>6BB7877D0FC03EAD003C24DB</string>
|
||||
<string>6BB7877E0FC03EAD003C24DB</string>
|
||||
<string>6BB7877F0FC03EAD003C24DB</string>
|
||||
<string>6BB787800FC03EAD003C24DB</string>
|
||||
<string>6BB787820FC03EAD003C24DB</string>
|
||||
<string>6BB787870FC03EAD003C24DB</string>
|
||||
<string>6BB7878B0FC03EAD003C24DB</string>
|
||||
<string>6BB7878C0FC03EAD003C24DB</string>
|
||||
<string>6BB7878D0FC03EAD003C24DB</string>
|
||||
<string>6BB7878E0FC03EAD003C24DB</string>
|
||||
<string>6BB7878F0FC03EAD003C24DB</string>
|
||||
<string>6BB787920FC03EAD003C24DB</string>
|
||||
<string>6BB787930FC03EAD003C24DB</string>
|
||||
<string>6BB787940FC03EAD003C24DB</string>
|
||||
<string>6BB787950FC03EAD003C24DB</string>
|
||||
<string>6BB787960FC03EAD003C24DB</string>
|
||||
<string>6BB787970FC03EAD003C24DB</string>
|
||||
<string>6BB787980FC03EAD003C24DB</string>
|
||||
<string>6BB787990FC03EAD003C24DB</string>
|
||||
<string>6BB7879A0FC03EAD003C24DB</string>
|
||||
<string>6BB7879B0FC03EAD003C24DB</string>
|
||||
<string>6BB7879C0FC03EAD003C24DB</string>
|
||||
<string>6BB7879D0FC03EAD003C24DB</string>
|
||||
<string>6BB7879E0FC03EAD003C24DB</string>
|
||||
<string>6BB7879F0FC03EAD003C24DB</string>
|
||||
<string>6BB787A00FC03EAD003C24DB</string>
|
||||
<string>6BB787A10FC03EAD003C24DB</string>
|
||||
<string>6BB787A20FC03EAD003C24DB</string>
|
||||
<string>6BB787A30FC03EAD003C24DB</string>
|
||||
<string>6BB787A40FC03EAD003C24DB</string>
|
||||
<string>6BB787A50FC03EAD003C24DB</string>
|
||||
<string>6BB787A60FC03EAD003C24DB</string>
|
||||
<string>6BB787A70FC03EAD003C24DB</string>
|
||||
<string>6BB787A80FC03EAD003C24DB</string>
|
||||
<string>6BB787A90FC03EAD003C24DB</string>
|
||||
<string>6BB787AA0FC03EAD003C24DB</string>
|
||||
<string>6BB787AB0FC03EAD003C24DB</string>
|
||||
<string>6BB787AC0FC03EAD003C24DB</string>
|
||||
<string>6BB787AD0FC03EAD003C24DB</string>
|
||||
<string>6BB787AE0FC03EAD003C24DB</string>
|
||||
<string>6BB787AF0FC03EAD003C24DB</string>
|
||||
<string>6BB787B00FC03EAD003C24DB</string>
|
||||
<string>6BB787B10FC03EAD003C24DB</string>
|
||||
<string>6BB787B20FC03EAD003C24DB</string>
|
||||
<string>6BB787B30FC03EAD003C24DB</string>
|
||||
<string>6BB787B40FC03EAD003C24DB</string>
|
||||
<string>6BB787B50FC03EAD003C24DB</string>
|
||||
<string>6BB787B60FC03EAD003C24DB</string>
|
||||
<string>6BB787B70FC03EAD003C24DB</string>
|
||||
<string>6BB787B80FC03EAD003C24DB</string>
|
||||
<string>6BB787B90FC03EAD003C24DB</string>
|
||||
<string>6BB787BA0FC03EAD003C24DB</string>
|
||||
<string>6BB787BB0FC03EAD003C24DB</string>
|
||||
<string>6BB787BC0FC03EAD003C24DB</string>
|
||||
<string>6BB787BD0FC03EAD003C24DB</string>
|
||||
<string>6BB787BE0FC03EAD003C24DB</string>
|
||||
<string>6BB787BF0FC03EAD003C24DB</string>
|
||||
<string>6BB787C00FC03EAD003C24DB</string>
|
||||
<string>6BB787C10FC03EAD003C24DB</string>
|
||||
<string>6BB787C20FC03EAD003C24DB</string>
|
||||
<string>6BB787C30FC03EAD003C24DB</string>
|
||||
<string>6BB787C40FC03EAD003C24DB</string>
|
||||
<string>6BB787C50FC03EAD003C24DB</string>
|
||||
<string>6BB787C60FC03EAD003C24DB</string>
|
||||
<string>6BB787C70FC03EAD003C24DB</string>
|
||||
<string>6BB787C80FC03EAD003C24DB</string>
|
||||
<string>6BB787C90FC03EAD003C24DB</string>
|
||||
<string>6BB787CA0FC03EAD003C24DB</string>
|
||||
<string>6BB787CB0FC03EAD003C24DB</string>
|
||||
<string>6BB787CC0FC03EAD003C24DB</string>
|
||||
<string>6BB787CD0FC03EAD003C24DB</string>
|
||||
<string>6BB787CE0FC03EAD003C24DB</string>
|
||||
<string>6BB787CF0FC03EAD003C24DB</string>
|
||||
<string>6BB787D00FC03EAD003C24DB</string>
|
||||
<string>6BB787D10FC03EAD003C24DB</string>
|
||||
<string>6BB787D20FC03EAD003C24DB</string>
|
||||
<string>6BB787D30FC03EAD003C24DB</string>
|
||||
<string>6BB787D40FC03EAD003C24DB</string>
|
||||
<string>6BB787D50FC03EAD003C24DB</string>
|
||||
<string>6BB787D60FC03EAD003C24DB</string>
|
||||
<string>6BB787D70FC03EAD003C24DB</string>
|
||||
<string>6BB787D80FC03EAD003C24DB</string>
|
||||
<string>6BB787DA0FC03EAD003C24DB</string>
|
||||
<string>6BB787DB0FC03EAD003C24DB</string>
|
||||
<string>6BB787DC0FC03EAD003C24DB</string>
|
||||
<string>6BB787DE0FC03EAD003C24DB</string>
|
||||
<string>6BB787DF0FC03EAD003C24DB</string>
|
||||
<string>6BB787E00FC03EAD003C24DB</string>
|
||||
<string>6BB787E10FC03EAD003C24DB</string>
|
||||
<string>6BB788270FC0593E003C24DB</string>
|
||||
<string>6BB788280FC0593E003C24DB</string>
|
||||
<string>6BB788290FC0593E003C24DB</string>
|
||||
<string>6BB7882A0FC0593E003C24DB</string>
|
||||
<string>6BB7882B0FC0593E003C24DB</string>
|
||||
<string>6BB7882C0FC0593E003C24DB</string>
|
||||
<string>6BB7882D0FC0593E003C24DB</string>
|
||||
<string>6BB7882E0FC0593E003C24DB</string>
|
||||
<string>6BB7882F0FC0593E003C24DB</string>
|
||||
<string>6BB788300FC0593E003C24DB</string>
|
||||
<string>6BB788310FC0593E003C24DB</string>
|
||||
<string>6BB788320FC0593E003C24DB</string>
|
||||
<string>6BB788330FC0593E003C24DB</string>
|
||||
<string>6BB788340FC0593E003C24DB</string>
|
||||
<string>6BB788350FC0593E003C24DB</string>
|
||||
<string>6BB788360FC0593E003C24DB</string>
|
||||
<string>6BB788370FC0593E003C24DB</string>
|
||||
<string>6BB788380FC0593E003C24DB</string>
|
||||
<string>6BB788390FC0593E003C24DB</string>
|
||||
<string>6BB7883A0FC0593E003C24DB</string>
|
||||
<string>6BB7883B0FC0593E003C24DB</string>
|
||||
<string>6BB7883C0FC0593E003C24DB</string>
|
||||
<string>6BB788420FC05981003C24DB</string>
|
||||
<string>6BB788710FC05EB9003C24DB</string>
|
||||
<string>6BB788840FC05FA5003C24DB</string>
|
||||
<string>6BB85D3E0FCEAA6300758966</string>
|
||||
<string>6B09CE050FD5563E005637D5</string>
|
||||
<string>6B09CE060FD5563E005637D5</string>
|
||||
<string>6B09CE070FD5563E005637D5</string>
|
||||
<string>6B09CE080FD5563E005637D5</string>
|
||||
<string>6B09CE090FD5563E005637D5</string>
|
||||
<string>6B09CE0A0FD5563E005637D5</string>
|
||||
<string>6B09CE0B0FD5563E005637D5</string>
|
||||
<string>6B09CE0C0FD5563E005637D5</string>
|
||||
<string>6B09CE0D0FD5563E005637D5</string>
|
||||
<string>6B09CE100FD5563E005637D5</string>
|
||||
<string>6B09CE130FD5563E005637D5</string>
|
||||
<string>6B09CE1E0FD55805005637D5</string>
|
||||
<string>6B09CE2D0FD55B4D005637D5</string>
|
||||
<string>6B09CE360FD55B99005637D5</string>
|
||||
<string>6B09CE470FD55FA2005637D5</string>
|
||||
<string>6B09CE480FD55FA2005637D5</string>
|
||||
<string>6B09CE490FD55FA2005637D5</string>
|
||||
<string>6B09CE4A0FD55FA2005637D5</string>
|
||||
<string>6B09CE620FD5BDE6005637D5</string>
|
||||
<string>6B09CE630FD5BDE6005637D5</string>
|
||||
<string>6B09CE640FD5BDE6005637D5</string>
|
||||
<string>6B09CE650FD5BDE6005637D5</string>
|
||||
<string>6B09CE660FD5BDE6005637D5</string>
|
||||
<string>6B09CE670FD5BDE6005637D5</string>
|
||||
<string>6B09CE680FD5BDE6005637D5</string>
|
||||
<string>6B09CE690FD5BDE6005637D5</string>
|
||||
<string>6B09CE6A0FD5BDE6005637D5</string>
|
||||
<string>6B09CE6B0FD5BDE6005637D5</string>
|
||||
<string>6B09CE6C0FD5BDE6005637D5</string>
|
||||
<string>6B09CE6D0FD5BDE6005637D5</string>
|
||||
<string>6B09CE6E0FD5BDE6005637D5</string>
|
||||
<string>6B09CE750FD5BEC3005637D5</string>
|
||||
</array>
|
||||
</dict>
|
||||
<key>SplitCount</key>
|
||||
@ -544,7 +462,7 @@
|
||||
<key>GeometryConfiguration</key>
|
||||
<dict>
|
||||
<key>Frame</key>
|
||||
<string>{{10, 27}, {1030, 100}}</string>
|
||||
<string>{{10, 27}, {1030, 61}}</string>
|
||||
</dict>
|
||||
<key>Module</key>
|
||||
<string>XCDetailModule</string>
|
||||
@ -628,11 +546,11 @@
|
||||
</array>
|
||||
<key>TableOfContents</key>
|
||||
<array>
|
||||
<string>6BB787E50FC03EB7003C24DB</string>
|
||||
<string>6B09CDD80FD52128005637D5</string>
|
||||
<string>1CA23ED40692098700951B8B</string>
|
||||
<string>6BB787E60FC03EB7003C24DB</string>
|
||||
<string>6B09CDD90FD52128005637D5</string>
|
||||
<string>6B8632A30F78115100E2684A</string>
|
||||
<string>6BB787E70FC03EB7003C24DB</string>
|
||||
<string>6B09CDDA0FD52128005637D5</string>
|
||||
<string>1CA23EDF0692099D00951B8B</string>
|
||||
<string>1CA23EE00692099D00951B8B</string>
|
||||
<string>1CA23EE10692099D00951B8B</string>
|
||||
@ -779,14 +697,14 @@
|
||||
</array>
|
||||
<key>TableOfContents</key>
|
||||
<array>
|
||||
<string>6BB787E80FC03EB7003C24DB</string>
|
||||
<string>6B09CDDB0FD52128005637D5</string>
|
||||
<string>1CCC7628064C1048000F2A68</string>
|
||||
<string>1CCC7629064C1048000F2A68</string>
|
||||
<string>6BB787E90FC03EB7003C24DB</string>
|
||||
<string>6BB787EA0FC03EB7003C24DB</string>
|
||||
<string>6BB787EB0FC03EB7003C24DB</string>
|
||||
<string>6BB787EC0FC03EB7003C24DB</string>
|
||||
<string>6BB786F40FC0091C003C24DB</string>
|
||||
<string>6B09CDDC0FD52128005637D5</string>
|
||||
<string>6B09CDDD0FD52128005637D5</string>
|
||||
<string>6B09CDDE0FD52128005637D5</string>
|
||||
<string>6B09CDDF0FD52128005637D5</string>
|
||||
<string>6B09CDE00FD52128005637D5</string>
|
||||
</array>
|
||||
<key>ToolbarConfiguration</key>
|
||||
<string>xcode.toolbar.config.debugV3</string>
|
||||
@ -816,9 +734,8 @@
|
||||
<integer>5</integer>
|
||||
<key>WindowOrderList</key>
|
||||
<array>
|
||||
<string>6BB788570FC05C2E003C24DB</string>
|
||||
<string>6BB788580FC05C2E003C24DB</string>
|
||||
<string>6BB788730FC05EB9003C24DB</string>
|
||||
<string>6B09CE700FD5BDE6005637D5</string>
|
||||
<string>6B09CE710FD5BDE6005637D5</string>
|
||||
<string>/Users/memon/Code/recastnavigation/RecastDemo/Build/Xcode/Recast.xcodeproj</string>
|
||||
</array>
|
||||
<key>WindowString</key>
|
||||
|
@ -192,6 +192,7 @@ enum DrawMode
|
||||
DRAWMODE_NAVMESH,
|
||||
DRAWMODE_NAVMESH_TRANS,
|
||||
DRAWMODE_NAVMESH_BVTREE,
|
||||
DRAWMODE_NAVMESH_INVIS,
|
||||
DRAWMODE_MESH,
|
||||
DRAWMODE_VOXELS,
|
||||
DRAWMODE_VOXELS_WALKABLE,
|
||||
@ -199,6 +200,7 @@ enum DrawMode
|
||||
DRAWMODE_COMPACT_DISTANCE,
|
||||
DRAWMODE_COMPACT_REGIONS,
|
||||
DRAWMODE_RAW_CONTOURS,
|
||||
DRAWMODE_BOTH_CONTOURS,
|
||||
DRAWMODE_CONTOURS,
|
||||
DRAWMODE_POLYMESH,
|
||||
};
|
||||
@ -255,6 +257,123 @@ rcLog g_log;
|
||||
rcBuildTimes g_buildTimes;
|
||||
|
||||
|
||||
struct Portal
|
||||
{
|
||||
float bmin[3], bmax[3];
|
||||
};
|
||||
static const int MAX_PORTALS = 2000;
|
||||
|
||||
Portal g_portals[MAX_PORTALS];
|
||||
int g_portalCount = 0;
|
||||
|
||||
Portal g_cportals[MAX_PORTALS];
|
||||
int g_cportalCount = 0;
|
||||
|
||||
void findContourPortals(const rcContour* cont, const int tx, const int tz, const int tileSize,
|
||||
const int climb, const float* bmin, const float cs, const float ch)
|
||||
{
|
||||
if (!cont) return;
|
||||
if (!cont->nverts) return;
|
||||
for (int i = 0, j = cont->nverts-1; i < cont->nverts; j=i++)
|
||||
{
|
||||
const int* vj = &cont->verts[j*4];
|
||||
const int* vi = &cont->verts[i*4];
|
||||
int edge = 0;
|
||||
if (vj[0] == tx && vi[0] == tx)
|
||||
edge = 1;
|
||||
else if (vj[0] == tx+tileSize && vi[0] == tx+tileSize)
|
||||
edge = 2;
|
||||
else if (vj[2] == tz && vi[2] == tz)
|
||||
edge = 3;
|
||||
else if (vj[2] == tz+tileSize && vi[2] == tz+tileSize)
|
||||
edge = 4;
|
||||
|
||||
if (edge != 0)
|
||||
{
|
||||
if (g_portalCount >= MAX_PORTALS)
|
||||
return;
|
||||
Portal& p = g_portals[g_portalCount];
|
||||
g_portalCount++;
|
||||
|
||||
float v0[3], v1[3];
|
||||
v0[0] = bmin[0] + vj[0]*cs;
|
||||
v0[1] = bmin[1] + vj[1]*ch;
|
||||
v0[2] = bmin[2] + vj[2]*cs;
|
||||
v1[0] = bmin[0] + vi[0]*cs;
|
||||
v1[1] = bmin[1] + vi[1]*ch;
|
||||
v1[2] = bmin[2] + vi[2]*cs;
|
||||
vcopy(p.bmin, v0);
|
||||
vcopy(p.bmax, v0);
|
||||
vmin(p.bmin, v1);
|
||||
vmax(p.bmax, v1);
|
||||
|
||||
if (edge == 1)
|
||||
{
|
||||
p.bmin[2] += cs/4;
|
||||
p.bmax[2] -= cs/4;
|
||||
p.bmax[1] += climb*ch;
|
||||
p.bmin[0] -= cs/4;
|
||||
p.bmax[0] += cs/4;
|
||||
}
|
||||
else if (edge == 2)
|
||||
{
|
||||
p.bmin[2] += cs/4;
|
||||
p.bmax[2] -= cs/4;
|
||||
p.bmax[1] += climb*ch;
|
||||
p.bmin[0] -= cs/4;
|
||||
p.bmax[0] += cs/4;
|
||||
}
|
||||
else if (edge == 3)
|
||||
{
|
||||
p.bmin[0] += cs/4;
|
||||
p.bmax[0] -= cs/4;
|
||||
p.bmax[1] += climb*ch;
|
||||
p.bmin[2] -= cs/4;
|
||||
p.bmax[2] += cs/4;
|
||||
}
|
||||
else if (edge == 4)
|
||||
{
|
||||
p.bmin[0] += cs/4;
|
||||
p.bmax[0] -= cs/4;
|
||||
p.bmax[1] += climb*ch;
|
||||
p.bmin[2] -= cs/4;
|
||||
p.bmax[2] += cs/4;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void findPortals(const rcContourSet* cset, const int tx, const int ty, const int tileSize,
|
||||
const int climb, const float* bmin, const float cs, const float ch)
|
||||
{
|
||||
if (!cset) return;
|
||||
if (!cset->nconts) return;
|
||||
for (int i = 0; i < cset->nconts; ++i)
|
||||
findContourPortals(&cset->conts[i], tx, ty, tileSize, climb, bmin, cs, ch);
|
||||
}
|
||||
|
||||
void connectPortals()
|
||||
{
|
||||
for (int i = 0; i < g_portalCount-1; ++i)
|
||||
{
|
||||
for (int j = i+1; j < g_portalCount; ++j)
|
||||
{
|
||||
if (g_portalCount >= MAX_PORTALS)
|
||||
return;
|
||||
Portal& pi = g_portals[i];
|
||||
Portal& pj = g_portals[j];
|
||||
Portal& p = g_cportals[g_cportalCount];
|
||||
vcopy(p.bmin, pi.bmin);
|
||||
vcopy(p.bmax, pi.bmax);
|
||||
vmax(p.bmin, pj.bmin);
|
||||
vmin(p.bmax, pj.bmax);
|
||||
if (p.bmin[0] >= p.bmax[0] || p.bmin[1] >= p.bmax[1] || p.bmin[2] >= p.bmax[2])
|
||||
continue;
|
||||
g_cportalCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool buildTiledNavigation(const rcConfig& cfg,
|
||||
const rcMeshLoaderObj* mesh,
|
||||
const rcChunkyTriMesh* chunkyMesh,
|
||||
@ -482,6 +601,19 @@ bool buildTiledNavigation(const rcConfig& cfg,
|
||||
delete solid;
|
||||
delete chf;
|
||||
|
||||
g_portalCount = 0;
|
||||
g_cportalCount = 0;
|
||||
/* for (int y = 0; y < tileSet->height; ++y)
|
||||
{
|
||||
for (int x = 0; x < tileSet->width; ++x)
|
||||
{
|
||||
findPortals(tileSet->tiles[x + y*tileSet->width].cset,
|
||||
x*tileCfg.tileSize, y*tileCfg.tileSize, tileCfg.tileSize,
|
||||
cfg.walkableClimb, cfg.bmin, cfg.cs, cfg.ch);
|
||||
}
|
||||
}
|
||||
connectPortals();*/
|
||||
|
||||
for (int y = 0; y < tileSet->height; ++y)
|
||||
{
|
||||
for (int x = 0; x < tileSet->width; ++x)
|
||||
@ -491,7 +623,7 @@ bool buildTiledNavigation(const rcConfig& cfg,
|
||||
{
|
||||
if (!rcFixupAdjacentContours(tileSet->tiles[x + y*tileSet->width].cset,
|
||||
tileSet->tiles[x+1 + y*tileSet->width].cset,
|
||||
1, (x+1)*cfg.tileSize))
|
||||
cfg.walkableClimb, (x+1)*cfg.tileSize, -1))
|
||||
{
|
||||
if (rcGetLog())
|
||||
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: [%d,%d] Could not fixup x+1.", x, y);
|
||||
@ -503,7 +635,7 @@ bool buildTiledNavigation(const rcConfig& cfg,
|
||||
{
|
||||
if (!rcFixupAdjacentContours(tileSet->tiles[x + y*tileSet->width].cset,
|
||||
tileSet->tiles[x + (y+1)*tileSet->width].cset,
|
||||
2, (y+1)*cfg.tileSize))
|
||||
cfg.walkableClimb, -1, (y+1)*cfg.tileSize))
|
||||
{
|
||||
if (rcGetLog())
|
||||
rcGetLog()->log(RC_LOG_ERROR, "buildTiledNavigation: [%d,%d] Could not fixup y+1.", x, y);
|
||||
@ -515,6 +647,7 @@ bool buildTiledNavigation(const rcConfig& cfg,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Combine contours.
|
||||
rcContourSet combSet;
|
||||
|
||||
@ -569,22 +702,25 @@ bool buildTiledNavigation(const rcConfig& cfg,
|
||||
}
|
||||
|
||||
|
||||
unsigned char* navData = 0;
|
||||
int navDataSize = 0;
|
||||
if (!dtCreateNavMeshData(polyMesh->verts, polyMesh->nverts,
|
||||
polyMesh->polys, polyMesh->npolys, polyMesh->nvp,
|
||||
cfg.bmin, cfg.bmax, cfg.cs, cfg.ch, &navData, &navDataSize))
|
||||
if (cfg.maxVertsPerPoly == DT_VERTS_PER_POLYGON)
|
||||
{
|
||||
if (rcGetLog())
|
||||
rcGetLog()->log(RC_LOG_ERROR, "Could not build Detour navmesh.");
|
||||
return false;
|
||||
}
|
||||
unsigned char* navData = 0;
|
||||
int navDataSize = 0;
|
||||
if (!dtCreateNavMeshData(polyMesh->verts, polyMesh->nverts,
|
||||
polyMesh->polys, polyMesh->npolys, polyMesh->nvp,
|
||||
cfg.bmin, cfg.bmax, cfg.cs, cfg.ch, &navData, &navDataSize))
|
||||
{
|
||||
if (rcGetLog())
|
||||
rcGetLog()->log(RC_LOG_ERROR, "Could not build Detour navmesh.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!navMesh->init(navData, navDataSize, true))
|
||||
{
|
||||
if (rcGetLog())
|
||||
rcGetLog()->log(RC_LOG_ERROR, "Could not init Detour navmesh");
|
||||
return false;
|
||||
if (!navMesh->init(navData, navDataSize, true))
|
||||
{
|
||||
if (rcGetLog())
|
||||
rcGetLog()->log(RC_LOG_ERROR, "Could not init Detour navmesh");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
rcTimeVal totEndTime = rcGetPerformanceTimer();
|
||||
@ -802,22 +938,25 @@ bool buildNavigation(const rcConfig& cfg,
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned char* navData = 0;
|
||||
int navDataSize = 0;
|
||||
if (!dtCreateNavMeshData(polyMesh->verts, polyMesh->nverts,
|
||||
polyMesh->polys, polyMesh->npolys, polyMesh->nvp,
|
||||
cfg.bmin, cfg.bmax, cfg.cs, cfg.ch, &navData, &navDataSize))
|
||||
if (cfg.maxVertsPerPoly == DT_VERTS_PER_POLYGON)
|
||||
{
|
||||
if (rcGetLog())
|
||||
rcGetLog()->log(RC_LOG_ERROR, "Could not build Detour navmesh.");
|
||||
return false;
|
||||
}
|
||||
unsigned char* navData = 0;
|
||||
int navDataSize = 0;
|
||||
if (!dtCreateNavMeshData(polyMesh->verts, polyMesh->nverts,
|
||||
polyMesh->polys, polyMesh->npolys, polyMesh->nvp,
|
||||
cfg.bmin, cfg.bmax, cfg.cs, cfg.ch, &navData, &navDataSize))
|
||||
{
|
||||
if (rcGetLog())
|
||||
rcGetLog()->log(RC_LOG_ERROR, "Could not build Detour navmesh.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!navMesh->init(navData, navDataSize, true))
|
||||
{
|
||||
if (rcGetLog())
|
||||
rcGetLog()->log(RC_LOG_ERROR, "Could not init Detour navmesh");
|
||||
return false;
|
||||
if (!navMesh->init(navData, navDataSize, true))
|
||||
{
|
||||
if (rcGetLog())
|
||||
rcGetLog()->log(RC_LOG_ERROR, "Could not init Detour navmesh");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
rcTimeVal totEndTime = rcGetPerformanceTimer();
|
||||
@ -874,9 +1013,9 @@ int main(int argc, char *argv[])
|
||||
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
|
||||
|
||||
int width = 1200;
|
||||
int height = 700;
|
||||
SDL_Surface* screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL);
|
||||
int width = 1024; //1200;
|
||||
int height = 768; //700;
|
||||
SDL_Surface* screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL /*| SDL_FULLSCREEN*/);
|
||||
if (!screen)
|
||||
{
|
||||
printf("Could not initialise SDL opengl\n");
|
||||
@ -901,13 +1040,14 @@ int main(int argc, char *argv[])
|
||||
float regionMinSize = 50;
|
||||
float regionMergeSize = 20;
|
||||
float edgeMaxLen = 12.0f;
|
||||
float edgeMaxError = 1.5f;
|
||||
float edgeMaxError = 1.3f;
|
||||
float vertsPerPoly = 6.0f;
|
||||
float tileSize = 0.0f;
|
||||
int drawMode = DRAWMODE_CONTOURS;
|
||||
int drawMode = DRAWMODE_NAVMESH;
|
||||
int toolMode = TOOLMODE_PATHFIND;
|
||||
bool showLevels = false;
|
||||
bool showLog = false;
|
||||
bool showTools = true;
|
||||
char curLevel[256] = "Choose Level...";
|
||||
bool mouseOverMenu = false;
|
||||
bool keepInterResults = false;
|
||||
@ -936,23 +1076,29 @@ int main(int argc, char *argv[])
|
||||
float rays[3], raye[3];
|
||||
float spos[3] = {0,0,0};
|
||||
float epos[3] = {0,0,0};
|
||||
float mpos[3] = {0,0,0};
|
||||
float hitPos[3] = {0,0,0};
|
||||
float hitNormal[3] = {0,0,0};
|
||||
float distanceToWall = 0;
|
||||
bool sposSet = false, eposSet = false;
|
||||
bool mposSet = false;
|
||||
static const float startCol[4] = { 0.6f, 0.1f, 0.1f, 0.75f };
|
||||
static const float endCol[4] = { 0.1f, 0.6f, 0.1f, 0.75f };
|
||||
bool recalcTool = false;
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
float fogCol[4] = { 0.1f,0.12f,0.14f,1 };
|
||||
// float fogCol[4] = { 0.1f,0.12f,0.14f,1 };
|
||||
float fogCol[4] = { 0.32f,0.25f,0.07f,1 };
|
||||
glEnable(GL_FOG);
|
||||
glFogi(GL_FOG_MODE, GL_LINEAR);
|
||||
glFogf(GL_FOG_START, 0);
|
||||
glFogf(GL_FOG_END, 10);
|
||||
glFogfv(GL_FOG_COLOR, fogCol);
|
||||
|
||||
glEnable(GL_POINT_SMOOTH);
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
|
||||
bool done = false;
|
||||
while(!done)
|
||||
{
|
||||
@ -991,7 +1137,14 @@ int main(int argc, char *argv[])
|
||||
float t;
|
||||
if (raycast(*g_mesh, rays, raye, t))
|
||||
{
|
||||
if (SDL_GetModState() & KMOD_SHIFT)
|
||||
if (SDL_GetModState() & KMOD_CTRL)
|
||||
{
|
||||
mposSet = true;
|
||||
mpos[0] = rays[0] + (raye[0] - rays[0])*t;
|
||||
mpos[1] = rays[1] + (raye[1] - rays[1])*t;
|
||||
mpos[2] = rays[2] + (raye[2] - rays[2])*t;
|
||||
}
|
||||
else if (SDL_GetModState() & KMOD_SHIFT)
|
||||
{
|
||||
sposSet = true;
|
||||
spos[0] = rays[0] + (raye[0] - rays[0])*t;
|
||||
@ -1012,6 +1165,13 @@ int main(int argc, char *argv[])
|
||||
recalcTool = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GetModState() & KMOD_CTRL)
|
||||
{
|
||||
mposSet = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1120,106 +1280,19 @@ int main(int argc, char *argv[])
|
||||
rcDebugDrawMesh(*g_mesh, 0);
|
||||
}
|
||||
|
||||
|
||||
if (g_mesh)
|
||||
{
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
// Agent dimensions.
|
||||
const float r = agentRadius;
|
||||
const float h = agentHeight;
|
||||
|
||||
float col[4];
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
const float* pos = 0;
|
||||
const float* c = 0;
|
||||
if (i == 0 && sposSet)
|
||||
{
|
||||
pos = spos;
|
||||
c = startCol;
|
||||
}
|
||||
else if (i == 1 && eposSet)
|
||||
{
|
||||
pos = epos;
|
||||
c = endCol;
|
||||
}
|
||||
if (!pos)
|
||||
continue;
|
||||
glLineWidth(2.0f);
|
||||
rcDebugDrawCylinderWire(pos[0]-r, pos[1]+0.02f, pos[2]-r, pos[0]+r, pos[1]+h, pos[2]+r, c);
|
||||
glLineWidth(1.0f);
|
||||
|
||||
glColor4ub(0,0,0,196);
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(pos[0], pos[1]-agentMaxClimb, pos[2]);
|
||||
glVertex3f(pos[0], pos[1]+agentMaxClimb, pos[2]);
|
||||
glVertex3f(pos[0]-r/2, pos[1]+0.02f, pos[2]);
|
||||
glVertex3f(pos[0]+r/2, pos[1]+0.02f, pos[2]);
|
||||
glVertex3f(pos[0], pos[1]+0.02f, pos[2]-r/2);
|
||||
glVertex3f(pos[0], pos[1]+0.02f, pos[2]+r/2);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
// Tile bboxes
|
||||
if ((int)tileSize > 0)
|
||||
{
|
||||
const int ts = (int)tileSize;
|
||||
col[0] = 0.5f; col[1] = 0.1f; col[2] = 0.1f; col[3] = 0.15f;
|
||||
int gw = 0, gh = 0;
|
||||
rcCalcGridSize(g_meshBMin, g_meshBMax, cellSize, &gw, &gh);
|
||||
int tx = (gw + ts-1) / ts;
|
||||
int ty = (gh + ts-1) / ts;
|
||||
|
||||
const float s = ts*cellSize;
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor4ub(0,0,0,64);
|
||||
for (int y = 0; y < ty; ++y)
|
||||
{
|
||||
for (int x = 0; x < tx; ++x)
|
||||
{
|
||||
float fx, fy, fz;
|
||||
fx = g_meshBMin[0] + x*s;
|
||||
fy = g_meshBMin[1];
|
||||
fz = g_meshBMin[2] + y*s;
|
||||
|
||||
glVertex3f(fx,fy,fz);
|
||||
glVertex3f(fx+s,fy,fz);
|
||||
glVertex3f(fx,fy,fz);
|
||||
glVertex3f(fx,fy,fz+s);
|
||||
|
||||
if (x+1 >= tx)
|
||||
{
|
||||
glVertex3f(fx+s,fy,fz);
|
||||
glVertex3f(fx+s,fy,fz+s);
|
||||
}
|
||||
if (y+1 >= ty)
|
||||
{
|
||||
glVertex3f(fx,fy,fz+s);
|
||||
glVertex3f(fx+s,fy,fz+s);
|
||||
}
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
// Mesh bbox.
|
||||
col[0] = 1.0f; col[1] = 1.0f; col[2] = 1.0f; col[3] = 0.25f;
|
||||
rcDebugDrawBoxWire(g_meshBMin[0], g_meshBMin[1], g_meshBMin[2],
|
||||
g_meshBMax[0], g_meshBMax[1], g_meshBMax[2], col);
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
glDisable(GL_FOG);
|
||||
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
if (drawMode == DRAWMODE_NAVMESH || drawMode == DRAWMODE_NAVMESH_TRANS || drawMode == DRAWMODE_NAVMESH_BVTREE)
|
||||
if (drawMode == DRAWMODE_NAVMESH ||
|
||||
drawMode == DRAWMODE_NAVMESH_TRANS ||
|
||||
drawMode == DRAWMODE_NAVMESH_BVTREE ||
|
||||
drawMode == DRAWMODE_NAVMESH_INVIS)
|
||||
{
|
||||
if (g_navMesh)
|
||||
{
|
||||
dtDebugDrawStatNavMesh(g_navMesh);
|
||||
if (drawMode != DRAWMODE_NAVMESH_INVIS)
|
||||
dtDebugDrawStatNavMesh(g_navMesh);
|
||||
|
||||
if (toolMode == TOOLMODE_PATHFIND)
|
||||
{
|
||||
@ -1345,6 +1418,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
if (drawMode == DRAWMODE_VOXELS)
|
||||
{
|
||||
glEnable(GL_FOG);
|
||||
if (g_tileSet)
|
||||
{
|
||||
for (int i = 0; i < g_tileSet->width*g_tileSet->height; ++i)
|
||||
@ -1353,9 +1427,11 @@ int main(int argc, char *argv[])
|
||||
rcDebugDrawHeightfieldSolid(*g_tileSet->tiles[i].solid, g_tileSet->bmin, g_tileSet->cs, g_tileSet->ch);
|
||||
}
|
||||
}
|
||||
glDisable(GL_FOG);
|
||||
}
|
||||
if (drawMode == DRAWMODE_VOXELS_WALKABLE)
|
||||
{
|
||||
glEnable(GL_FOG);
|
||||
if (g_tileSet)
|
||||
{
|
||||
for (int i = 0; i < g_tileSet->width*g_tileSet->height; ++i)
|
||||
@ -1364,9 +1440,11 @@ int main(int argc, char *argv[])
|
||||
rcDebugDrawHeightfieldWalkable(*g_tileSet->tiles[i].solid, g_tileSet->bmin, g_tileSet->cs, g_tileSet->ch);
|
||||
}
|
||||
}
|
||||
glDisable(GL_FOG);
|
||||
}
|
||||
if (drawMode == DRAWMODE_RAW_CONTOURS)
|
||||
{
|
||||
glDepthMask(GL_FALSE);
|
||||
if (g_tileSet)
|
||||
{
|
||||
for (int i = 0; i < g_tileSet->width*g_tileSet->height; ++i)
|
||||
@ -1375,9 +1453,27 @@ int main(int argc, char *argv[])
|
||||
rcDebugDrawRawContours(*(g_tileSet->tiles[i].cset), g_tileSet->bmin, g_tileSet->cs, g_tileSet->ch);
|
||||
}
|
||||
}
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
if (drawMode == DRAWMODE_BOTH_CONTOURS)
|
||||
{
|
||||
glDepthMask(GL_FALSE);
|
||||
if (g_tileSet)
|
||||
{
|
||||
for (int i = 0; i < g_tileSet->width*g_tileSet->height; ++i)
|
||||
{
|
||||
if (g_tileSet->tiles[i].cset)
|
||||
{
|
||||
rcDebugDrawRawContours(*(g_tileSet->tiles[i].cset), g_tileSet->bmin, g_tileSet->cs, g_tileSet->ch, 0.5f);
|
||||
rcDebugDrawContours(*(g_tileSet->tiles[i].cset), g_tileSet->bmin, g_tileSet->cs, g_tileSet->ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
if (drawMode == DRAWMODE_CONTOURS)
|
||||
{
|
||||
glDepthMask(GL_FALSE);
|
||||
if (g_tileSet)
|
||||
{
|
||||
for (int i = 0; i < g_tileSet->width*g_tileSet->height; ++i)
|
||||
@ -1386,16 +1482,120 @@ int main(int argc, char *argv[])
|
||||
rcDebugDrawContours(*(g_tileSet->tiles[i].cset), g_tileSet->bmin, g_tileSet->cs, g_tileSet->ch);
|
||||
}
|
||||
}
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
if (drawMode == DRAWMODE_POLYMESH)
|
||||
{
|
||||
glDepthMask(GL_FALSE);
|
||||
if (g_polyMesh)
|
||||
rcDebugDrawPolyMesh(*g_polyMesh);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
if (g_mesh)
|
||||
{
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
glDisable(GL_FOG);
|
||||
// Agent dimensions.
|
||||
const float r = agentRadius;
|
||||
const float h = agentHeight;
|
||||
|
||||
float col[4];
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
const float* pos = 0;
|
||||
const float* c = 0;
|
||||
if (i == 0 && sposSet)
|
||||
{
|
||||
pos = spos;
|
||||
c = startCol;
|
||||
}
|
||||
else if (i == 1 && eposSet)
|
||||
{
|
||||
pos = epos;
|
||||
c = endCol;
|
||||
}
|
||||
if (!pos)
|
||||
continue;
|
||||
glLineWidth(2.0f);
|
||||
rcDebugDrawCylinderWire(pos[0]-r, pos[1]+0.02f, pos[2]-r, pos[0]+r, pos[1]+h, pos[2]+r, c);
|
||||
glLineWidth(1.0f);
|
||||
|
||||
glColor4ub(0,0,0,196);
|
||||
glBegin(GL_LINES);
|
||||
glVertex3f(pos[0], pos[1]-agentMaxClimb, pos[2]);
|
||||
glVertex3f(pos[0], pos[1]+agentMaxClimb, pos[2]);
|
||||
glVertex3f(pos[0]-r/2, pos[1]+0.02f, pos[2]);
|
||||
glVertex3f(pos[0]+r/2, pos[1]+0.02f, pos[2]);
|
||||
glVertex3f(pos[0], pos[1]+0.02f, pos[2]-r/2);
|
||||
glVertex3f(pos[0], pos[1]+0.02f, pos[2]+r/2);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
// Tile bboxes
|
||||
if ((int)tileSize > 0)
|
||||
{
|
||||
const int ts = (int)tileSize;
|
||||
col[0] = 0.5f; col[1] = 0.1f; col[2] = 0.1f; col[3] = 0.15f;
|
||||
int gw = 0, gh = 0;
|
||||
rcCalcGridSize(g_meshBMin, g_meshBMax, cellSize, &gw, &gh);
|
||||
int tx = (gw + ts-1) / ts;
|
||||
int ty = (gh + ts-1) / ts;
|
||||
|
||||
const float s = ts*cellSize;
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor4ub(0,0,0,64);
|
||||
for (int y = 0; y < ty; ++y)
|
||||
{
|
||||
for (int x = 0; x < tx; ++x)
|
||||
{
|
||||
float fx, fy, fz;
|
||||
fx = g_meshBMin[0] + x*s;
|
||||
fy = g_meshBMin[1];
|
||||
fz = g_meshBMin[2] + y*s;
|
||||
|
||||
glVertex3f(fx,fy,fz);
|
||||
glVertex3f(fx+s,fy,fz);
|
||||
glVertex3f(fx,fy,fz);
|
||||
glVertex3f(fx,fy,fz+s);
|
||||
|
||||
if (x+1 >= tx)
|
||||
{
|
||||
glVertex3f(fx+s,fy,fz);
|
||||
glVertex3f(fx+s,fy,fz+s);
|
||||
}
|
||||
if (y+1 >= ty)
|
||||
{
|
||||
glVertex3f(fx,fy,fz+s);
|
||||
glVertex3f(fx+s,fy,fz+s);
|
||||
}
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
// Mesh bbox.
|
||||
col[0] = 1.0f; col[1] = 1.0f; col[2] = 1.0f; col[3] = 0.25f;
|
||||
rcDebugDrawBoxWire(g_meshBMin[0], g_meshBMin[1], g_meshBMin[2],
|
||||
g_meshBMax[0], g_meshBMax[1], g_meshBMax[2], col);
|
||||
|
||||
|
||||
col[0] = 0.1f; col[1] = 0.5f; col[2] = 0.75f; col[3] = 0.5f;
|
||||
/* for (int i = 0; i < g_portalCount; ++i)
|
||||
{
|
||||
rcDebugDrawBoxWire(g_portals[i].bmin[0], g_portals[i].bmin[1], g_portals[i].bmin[2],
|
||||
g_portals[i].bmax[0], g_portals[i].bmax[1], g_portals[i].bmax[2], col);
|
||||
}*/
|
||||
for (int i = 0; i < g_cportalCount; ++i)
|
||||
{
|
||||
rcDebugDrawBoxWire(g_cportals[i].bmin[0], g_cportals[i].bmin[1], g_cportals[i].bmin[2],
|
||||
g_cportals[i].bmax[0], g_cportals[i].bmax[1], g_cportals[i].bmax[2], col);
|
||||
}
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
|
||||
// Render GUI
|
||||
@ -1417,8 +1617,15 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (imguiButton(GENID, curLevel))
|
||||
{
|
||||
showLevels = true;
|
||||
scanDirectory("meshes", ".obj", fileList);
|
||||
if (showLevels)
|
||||
{
|
||||
showLevels = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
showLevels = true;
|
||||
scanDirectory("meshes", ".obj", fileList);
|
||||
}
|
||||
}
|
||||
|
||||
imguiSeparator();
|
||||
@ -1427,6 +1634,14 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
if (imguiButton(GENID, "Build"))
|
||||
{
|
||||
npolys = 0;
|
||||
nstraightPath = 0;
|
||||
sposSet = false;
|
||||
eposSet = false;
|
||||
startRef = 0;
|
||||
endRef = 0;
|
||||
distanceToWall = 0;
|
||||
|
||||
rcConfig cfg;
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
cfg.cs = cellSize;
|
||||
@ -1439,7 +1654,7 @@ int main(int argc, char *argv[])
|
||||
cfg.maxSimplificationError = edgeMaxError;
|
||||
cfg.minRegionSize = (int)rcSqr(regionMinSize);
|
||||
cfg.mergeRegionSize = (int)rcSqr(regionMergeSize);
|
||||
cfg.maxVertsPerPoly = DT_VERTS_PER_POLYGON; // TODO: Handle better. (int)vertsPerPoly;
|
||||
cfg.maxVertsPerPoly = /*DT_VERTS_PER_POLYGON; // TODO: Handle better.*/ (int)vertsPerPoly;
|
||||
rcCalcBounds(g_mesh->getVerts(), g_mesh->getVertCount(), cfg.bmin, cfg.bmax);
|
||||
rcCalcGridSize(cfg.bmin, cfg.bmax, cfg.cs, &cfg.width, &cfg.height);
|
||||
|
||||
@ -1483,6 +1698,9 @@ int main(int argc, char *argv[])
|
||||
if (imguiCheck(GENID, "Show Log", showLog))
|
||||
showLog = !showLog;
|
||||
|
||||
if (imguiCheck(GENID, "Show Tools", showTools))
|
||||
showTools = !showTools;
|
||||
|
||||
if (imguiCheck(GENID, "Keep Itermediate Results", keepInterResults))
|
||||
keepInterResults = !keepInterResults;
|
||||
|
||||
@ -1527,6 +1745,8 @@ int main(int argc, char *argv[])
|
||||
drawMode = DRAWMODE_NAVMESH;
|
||||
if (imguiCheck(GENID, "Navmesh BVTree", drawMode == DRAWMODE_NAVMESH_BVTREE))
|
||||
drawMode = DRAWMODE_NAVMESH_BVTREE;
|
||||
if (imguiCheck(GENID, "Navmesh Invis", drawMode == DRAWMODE_NAVMESH_INVIS))
|
||||
drawMode = DRAWMODE_NAVMESH_INVIS;
|
||||
if (imguiCheck(GENID, "Navmesh Trans", drawMode == DRAWMODE_NAVMESH_TRANS))
|
||||
drawMode = DRAWMODE_NAVMESH_TRANS;
|
||||
if (imguiCheck(GENID, "Voxels", drawMode == DRAWMODE_VOXELS))
|
||||
@ -1541,6 +1761,8 @@ int main(int argc, char *argv[])
|
||||
drawMode = DRAWMODE_COMPACT_REGIONS;
|
||||
if (imguiCheck(GENID, "Raw Contours", drawMode == DRAWMODE_RAW_CONTOURS))
|
||||
drawMode = DRAWMODE_RAW_CONTOURS;
|
||||
if (imguiCheck(GENID, "Both Contours", drawMode == DRAWMODE_BOTH_CONTOURS))
|
||||
drawMode = DRAWMODE_BOTH_CONTOURS;
|
||||
if (imguiCheck(GENID, "Contours", drawMode == DRAWMODE_CONTOURS))
|
||||
drawMode = DRAWMODE_CONTOURS;
|
||||
if (imguiCheck(GENID, "Poly Mesh", drawMode == DRAWMODE_POLYMESH))
|
||||
@ -1549,7 +1771,6 @@ int main(int argc, char *argv[])
|
||||
imguiEndScrollArea();
|
||||
|
||||
// Tools
|
||||
bool showTools = true;
|
||||
if (showTools)
|
||||
{
|
||||
static int toolsScroll = 0;
|
||||
@ -1728,8 +1949,8 @@ int main(int argc, char *argv[])
|
||||
rx = 45;
|
||||
ry = -45;
|
||||
|
||||
glFogf(GL_FOG_START, camr*0.5f);
|
||||
glFogf(GL_FOG_END, camr*2.5f);
|
||||
glFogf(GL_FOG_START, camr*0.2f);
|
||||
glFogf(GL_FOG_END, camr*1.25f);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1738,25 +1959,48 @@ int main(int argc, char *argv[])
|
||||
|
||||
}
|
||||
|
||||
imguiEndFrame();
|
||||
imguiRender(&drawText);
|
||||
|
||||
g_font.drawText(10.0f, (float)height-20.0f, "W/S/A/D: Move RMB: Rotate LMB: Place Start LMB+SHIFT: Place End", GLFont::RGBA(255,255,255,128));
|
||||
|
||||
// Draw start and end point labels
|
||||
if (sposSet && gluProject((GLdouble)spos[0], (GLdouble)spos[1], (GLdouble)spos[2],
|
||||
model, proj, view, &x, &y, &z))
|
||||
model, proj, view, &x, &y, &z))
|
||||
{
|
||||
const float len = g_font.getTextLength("Start");
|
||||
g_font.drawText((float)x - len/2, (float)y-g_font.getLineHeight(), "Start", GLFont::RGBA(0,0,0,220));
|
||||
}
|
||||
if (eposSet && gluProject((GLdouble)epos[0], (GLdouble)epos[1], (GLdouble)epos[2],
|
||||
model, proj, view, &x, &y, &z))
|
||||
model, proj, view, &x, &y, &z))
|
||||
{
|
||||
const float len = g_font.getTextLength("End");
|
||||
g_font.drawText((float)x-len/2, (float)y-g_font.getLineHeight(), "End", GLFont::RGBA(0,0,0,220));
|
||||
}
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
// Marker
|
||||
if (mposSet && gluProject((GLdouble)mpos[0], (GLdouble)mpos[1], (GLdouble)mpos[2],
|
||||
model, proj, view, &x, &y, &z))
|
||||
{
|
||||
// Draw marker circle
|
||||
glLineWidth(5.0f);
|
||||
glColor4ub(240,16,0,196);
|
||||
glBegin(GL_LINE_LOOP);
|
||||
const float r = 25.0f;
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
const float a = (float)i / 20.0f * M_PI*2;
|
||||
const float fx = (float)x + cosf(a)*r;
|
||||
const float fy = (float)y + sinf(a)*r;
|
||||
glVertex2f(fx,fy);
|
||||
}
|
||||
glEnd();
|
||||
glLineWidth(1.0f);
|
||||
}
|
||||
|
||||
imguiEndFrame();
|
||||
imguiRender(&drawText);
|
||||
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
SDL_GL_SwapBuffers();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user