Presentation mode tweaks. Fix for Issue 74: added FileIO interface, Fix for Issue 76: added pure virtual destructor for duDebugDraw.

This commit is contained in:
Mikko Mononen 2010-05-07 07:14:42 +00:00
parent 87800abc28
commit 49f2b03cd8
15 changed files with 2193 additions and 1932 deletions

View File

@ -30,6 +30,8 @@ enum duDebugDrawPrimitives
// Abstrace debug draw interface.
struct duDebugDraw
{
virtual ~duDebugDraw() = 0;
virtual void depthMask(bool state) = 0;
// Begin drawing primitives.

View File

@ -19,10 +19,19 @@
#ifndef RECAST_DUMP_H
#define RECAST_DUMP_H
bool duDumpPolyMeshToObj(struct rcPolyMesh& pmesh, const char* filepath);
bool duDumpPolyMeshDetailToObj(struct rcPolyMeshDetail& dmesh, const char* filepath);
struct duFileIO
{
virtual ~duFileIO() = 0;
virtual bool isWriting() const = 0;
virtual bool isReading() const = 0;
virtual bool write(const void* ptr, const size_t size) = 0;
virtual bool read(void* ptr, const size_t size) = 0;
};
bool duDumpCompactHeightfield(struct rcCompactHeightfield& chf, const char* filepath);
bool duReadCompactHeightfield(struct rcCompactHeightfield& chf, const char* filepath);
bool duDumpPolyMeshToObj(struct rcPolyMesh& pmesh, duFileIO* io);
bool duDumpPolyMeshDetailToObj(struct rcPolyMeshDetail& dmesh, duFileIO* io);
bool duDumpCompactHeightfield(struct rcCompactHeightfield& chf, duFileIO* io);
bool duReadCompactHeightfield(struct rcCompactHeightfield& chf, duFileIO* io);
#endif // RECAST_DUMP_H

View File

@ -21,6 +21,13 @@
#include <string.h>
#include "DebugDraw.h"
duDebugDraw::~duDebugDraw()
{
// Empty
}
inline int bit(int a, int b)
{
return (a & (1 << b)) >> b;

View File

@ -19,25 +19,49 @@
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <stdarg.h>
#include "Recast.h"
#include "RecastDump.h"
bool duDumpPolyMeshToObj(rcPolyMesh& pmesh, const char* filepath)
duFileIO::~duFileIO()
{
FILE* fp = fopen(filepath, "w");
if (!fp)
// Empty
}
static void ioprintf(duFileIO* io, const char* format, ...)
{
char line[256];
va_list ap;
va_start(ap, format);
const int n = vsnprintf(line, sizeof(line), format, ap);
va_end(ap);
if (n > 0)
io->write(line, sizeof(char)*n);
}
bool duDumpPolyMeshToObj(rcPolyMesh& pmesh, duFileIO* io)
{
if (!io)
{
printf("duDumpPolyMeshToObj: input IO is null.\n");
return false;
}
if (!io->isWriting())
{
printf("duDumpPolyMeshToObj: input IO not writing.\n");
return false;
}
const int nvp = pmesh.nvp;
const float cs = pmesh.cs;
const float ch = pmesh.ch;
const float* orig = pmesh.bmin;
fprintf(fp, "# Recast Navmesh\n");
fprintf(fp, "o NavMesh\n");
ioprintf(io, "# Recast Navmesh\n");
ioprintf(io, "o NavMesh\n");
fprintf(fp, "\n");
ioprintf(io, "\n");
for (int i = 0; i < pmesh.nverts; ++i)
{
@ -45,10 +69,10 @@ bool duDumpPolyMeshToObj(rcPolyMesh& pmesh, const char* filepath)
const float x = orig[0] + v[0]*cs;
const float y = orig[1] + (v[1]+1)*ch + 0.1f;
const float z = orig[2] + v[2]*cs;
fprintf(fp, "v %f %f %f\n", x,y,z);
ioprintf(io, "v %f %f %f\n", x,y,z);
}
fprintf(fp, "\n");
ioprintf(io, "\n");
for (int i = 0; i < pmesh.npolys; ++i)
{
@ -56,33 +80,38 @@ bool duDumpPolyMeshToObj(rcPolyMesh& pmesh, const char* filepath)
for (int j = 2; j < nvp; ++j)
{
if (p[j] == RC_MESH_NULL_IDX) break;
fprintf(fp, "f %d %d %d\n", p[0]+1, p[j-1]+1, p[j]+1);
ioprintf(io, "f %d %d %d\n", p[0]+1, p[j-1]+1, p[j]+1);
}
}
fclose(fp);
return true;
}
bool duDumpPolyMeshDetailToObj(rcPolyMeshDetail& dmesh, const char* filepath)
bool duDumpPolyMeshDetailToObj(rcPolyMeshDetail& dmesh, duFileIO* io)
{
FILE* fp = fopen(filepath, "w");
if (!fp)
if (!io)
{
printf("duDumpPolyMeshDetailToObj: input IO is null.\n");
return false;
}
if (!io->isWriting())
{
printf("duDumpPolyMeshDetailToObj: input IO not writing.\n");
return false;
}
fprintf(fp, "# Recast Navmesh\n");
fprintf(fp, "o NavMesh\n");
ioprintf(io, "# Recast Navmesh\n");
ioprintf(io, "o NavMesh\n");
fprintf(fp, "\n");
ioprintf(io, "\n");
for (int i = 0; i < dmesh.nverts; ++i)
{
const float* v = &dmesh.verts[i*3];
fprintf(fp, "v %f %f %f\n", v[0],v[1],v[2]);
ioprintf(io, "v %f %f %f\n", v[0],v[1],v[2]);
}
fprintf(fp, "\n");
ioprintf(io, "\n");
for (int i = 0; i < dmesh.nmeshes; ++i)
{
@ -93,15 +122,13 @@ bool duDumpPolyMeshDetailToObj(rcPolyMeshDetail& dmesh, const char* filepath)
const unsigned char* tris = &dmesh.tris[btris*4];
for (int j = 0; j < ntris; ++j)
{
fprintf(fp, "f %d %d %d\n",
ioprintf(io, "f %d %d %d\n",
(int)(bverts+tris[j*4+0])+1,
(int)(bverts+tris[j*4+1])+1,
(int)(bverts+tris[j*4+2])+1);
}
}
fclose(fp);
return true;
}
@ -109,33 +136,37 @@ bool duDumpPolyMeshDetailToObj(rcPolyMeshDetail& dmesh, const char* filepath)
static const int CHF_MAGIC = ('r' << 24) | ('c' << 16) | ('h' << 8) | 'f';
static const int CHF_VERSION = 2;
bool duDumpCompactHeightfield(struct rcCompactHeightfield& chf, const char* filepath)
bool duDumpCompactHeightfield(struct rcCompactHeightfield& chf, duFileIO* io)
{
FILE* fp = fopen(filepath, "wb");
if (!fp)
if (!io)
{
printf("duDumpCompactHeightfield: Could not open '%s' for writing.\n", filepath);
printf("duDumpCompactHeightfield: input IO is null.\n");
return false;
}
if (!io->isWriting())
{
printf("duDumpCompactHeightfield: input IO not writing.\n");
return false;
}
fwrite(&CHF_MAGIC, sizeof(CHF_MAGIC), 1, fp);
fwrite(&CHF_VERSION, sizeof(CHF_VERSION), 1, fp);
io->write(&CHF_MAGIC, sizeof(CHF_MAGIC));
io->write(&CHF_VERSION, sizeof(CHF_VERSION));
fwrite(&chf.width, sizeof(chf.width), 1, fp);
fwrite(&chf.height, sizeof(chf.height), 1, fp);
fwrite(&chf.spanCount, sizeof(chf.spanCount), 1, fp);
io->write(&chf.width, sizeof(chf.width));
io->write(&chf.height, sizeof(chf.height));
io->write(&chf.spanCount, sizeof(chf.spanCount));
fwrite(&chf.walkableHeight, sizeof(chf.walkableHeight), 1, fp);
fwrite(&chf.walkableClimb, sizeof(chf.walkableClimb), 1, fp);
io->write(&chf.walkableHeight, sizeof(chf.walkableHeight));
io->write(&chf.walkableClimb, sizeof(chf.walkableClimb));
fwrite(&chf.maxDistance, sizeof(chf.maxDistance), 1, fp);
fwrite(&chf.maxRegions, sizeof(chf.maxRegions), 1, fp);
io->write(&chf.maxDistance, sizeof(chf.maxDistance));
io->write(&chf.maxRegions, sizeof(chf.maxRegions));
fwrite(chf.bmin, sizeof(chf.bmin), 1, fp);
fwrite(chf.bmax, sizeof(chf.bmax), 1, fp);
io->write(chf.bmin, sizeof(chf.bmin));
io->write(chf.bmax, sizeof(chf.bmax));
fwrite(&chf.cs, sizeof(chf.cs), 1, fp);
fwrite(&chf.ch, sizeof(chf.ch), 1, fp);
io->write(&chf.cs, sizeof(chf.cs));
io->write(&chf.ch, sizeof(chf.ch));
int tmp = 0;
if (chf.cells) tmp |= 1;
@ -143,67 +174,68 @@ bool duDumpCompactHeightfield(struct rcCompactHeightfield& chf, const char* file
if (chf.dist) tmp |= 4;
if (chf.areas) tmp |= 8;
fwrite(&tmp, sizeof(tmp), 1, fp);
io->write(&tmp, sizeof(tmp));
if (chf.cells)
fwrite(chf.cells, sizeof(rcCompactCell)*chf.width*chf.height, 1, fp);
io->write(chf.cells, sizeof(rcCompactCell)*chf.width*chf.height);
if (chf.spans)
fwrite(chf.spans, sizeof(rcCompactSpan)*chf.spanCount, 1, fp);
io->write(chf.spans, sizeof(rcCompactSpan)*chf.spanCount);
if (chf.dist)
fwrite(chf.dist, sizeof(unsigned short)*chf.spanCount, 1, fp);
io->write(chf.dist, sizeof(unsigned short)*chf.spanCount);
if (chf.areas)
fwrite(chf.areas, sizeof(unsigned char)*chf.spanCount, 1, fp);
fclose(fp);
io->write(chf.areas, sizeof(unsigned char)*chf.spanCount);
return true;
}
bool duReadCompactHeightfield(struct rcCompactHeightfield& chf, const char* filepath)
bool duReadCompactHeightfield(struct rcCompactHeightfield& chf, duFileIO* io)
{
FILE* fp = fopen(filepath, "rb");
if (!fp)
if (!io)
{
printf("duReadCompactHeightfield: Could not open '%s' for reading.\n", filepath);
printf("duReadCompactHeightfield: input IO is null.\n");
return false;
}
if (!io->isReading())
{
printf("duReadCompactHeightfield: input IO not reading.\n");
return false;
}
int magic = 0;
int version = 0;
fread(&magic, sizeof(magic), 1, fp);
fread(&version, sizeof(version), 1, fp);
io->read(&magic, sizeof(magic));
io->read(&version, sizeof(version));
if (magic != CHF_MAGIC)
{
printf("duReadCompactHeightfield: Bad voodoo.\n");
fclose(fp);
return false;
}
if (version != CHF_VERSION)
{
printf("duReadCompactHeightfield: Bad version.\n");
fclose(fp);
return false;
}
fread(&chf.width, sizeof(chf.width), 1, fp);
fread(&chf.height, sizeof(chf.height), 1, fp);
fread(&chf.spanCount, sizeof(chf.spanCount), 1, fp);
io->read(&chf.width, sizeof(chf.width));
io->read(&chf.height, sizeof(chf.height));
io->read(&chf.spanCount, sizeof(chf.spanCount));
fread(&chf.walkableHeight, sizeof(chf.walkableHeight), 1, fp);
fread(&chf.walkableClimb, sizeof(chf.walkableClimb), 1, fp);
io->read(&chf.walkableHeight, sizeof(chf.walkableHeight));
io->read(&chf.walkableClimb, sizeof(chf.walkableClimb));
fread(&chf.maxDistance, sizeof(chf.maxDistance), 1, fp);
fread(&chf.maxRegions, sizeof(chf.maxRegions), 1, fp);
io->read(&chf.maxDistance, sizeof(chf.maxDistance));
io->read(&chf.maxRegions, sizeof(chf.maxRegions));
fread(chf.bmin, sizeof(chf.bmin), 1, fp);
fread(chf.bmax, sizeof(chf.bmax), 1, fp);
io->read(chf.bmin, sizeof(chf.bmin));
io->read(chf.bmax, sizeof(chf.bmax));
fread(&chf.cs, sizeof(chf.cs), 1, fp);
fread(&chf.ch, sizeof(chf.ch), 1, fp);
io->read(&chf.cs, sizeof(chf.cs));
io->read(&chf.ch, sizeof(chf.ch));
int tmp = 0;
fread(&tmp, sizeof(tmp), 1, fp);
io->read(&tmp, sizeof(tmp));
if (tmp & 1)
{
@ -211,10 +243,9 @@ bool duReadCompactHeightfield(struct rcCompactHeightfield& chf, const char* file
if (!chf.cells)
{
printf("duReadCompactHeightfield: Could not alloc cells (%d)\n", chf.width*chf.height);
fclose(fp);
return false;
}
fread(chf.cells, sizeof(rcCompactCell)*chf.width*chf.height, 1, fp);
io->read(chf.cells, sizeof(rcCompactCell)*chf.width*chf.height);
}
if (tmp & 2)
{
@ -222,10 +253,9 @@ bool duReadCompactHeightfield(struct rcCompactHeightfield& chf, const char* file
if (!chf.spans)
{
printf("duReadCompactHeightfield: Could not alloc spans (%d)\n", chf.spanCount);
fclose(fp);
return false;
}
fread(chf.spans, sizeof(rcCompactSpan)*chf.spanCount, 1, fp);
io->read(chf.spans, sizeof(rcCompactSpan)*chf.spanCount);
}
if (tmp & 4)
{
@ -233,10 +263,9 @@ bool duReadCompactHeightfield(struct rcCompactHeightfield& chf, const char* file
if (!chf.dist)
{
printf("duReadCompactHeightfield: Could not alloc dist (%d)\n", chf.spanCount);
fclose(fp);
return false;
}
fread(chf.dist, sizeof(unsigned short)*chf.spanCount, 1, fp);
io->read(chf.dist, sizeof(unsigned short)*chf.spanCount);
}
if (tmp & 8)
{
@ -244,14 +273,11 @@ bool duReadCompactHeightfield(struct rcCompactHeightfield& chf, const char* file
if (!chf.areas)
{
printf("duReadCompactHeightfield: Could not alloc areas (%d)\n", chf.spanCount);
fclose(fp);
return false;
}
fread(chf.areas, sizeof(unsigned char)*chf.spanCount, 1, fp);
io->read(chf.areas, sizeof(unsigned char)*chf.spanCount);
}
fclose(fp);
return true;
}

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -197,48 +197,7 @@
<key>Notifications</key>
<array/>
<key>OpenEditors</key>
<array>
<dict>
<key>Content</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>6BF5F29911747CFA000502A6</string>
<key>PBXProjectModuleLabel</key>
<string>glimage.h</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>6BF5F29A11747CFA000502A6</string>
<key>PBXProjectModuleLabel</key>
<string>glimage.h</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>6B6C4675117D8D60002CDD36</string>
<key>history</key>
<array>
<string>6BF5F55B1176FEC8000502A6</string>
</array>
</dict>
<key>SplitCount</key>
<string>1</string>
</dict>
<key>StatusBarVisibility</key>
<true/>
</dict>
<key>Geometry</key>
<dict>
<key>Frame</key>
<string>{{0, 20}, {1214, 625}}</string>
<key>PBXModuleWindowStatusBarHidden2</key>
<false/>
<key>RubberWindowFrame</key>
<string>15 107 1214 666 0 0 1280 778 </string>
</dict>
</dict>
</array>
<array/>
<key>PerspectiveWidths</key>
<array>
<integer>1256</integer>
@ -329,7 +288,7 @@
</array>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
<string>{{0, 427}, {264, 643}}</string>
<string>{{0, 348}, {264, 643}}</string>
</dict>
<key>PBXTopSmartGroupGIDs</key>
<array/>
@ -376,26 +335,19 @@
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>6B6C4674117D8D60002CDD36</string>
<string>6B5562FE1193F50A00843384</string>
<key>history</key>
<array>
<string>6BBB4A96115B4F3400CF791D</string>
<string>6BBB4A9E115B4F3400CF791D</string>
<string>6BBB4AA1115B4F3400CF791D</string>
<string>6BBB4AA3115B4F3400CF791D</string>
<string>6BBB4AA4115B4F3400CF791D</string>
<string>6BBB4AA5115B4F3400CF791D</string>
<string>6BBB4AA6115B4F3400CF791D</string>
<string>6BBB4AA7115B4F3400CF791D</string>
<string>6BBB4AAB115B4F3400CF791D</string>
<string>6BBB4AB0115B4F3400CF791D</string>
<string>6BBB4AB2115B4F3400CF791D</string>
<string>6BBB4AB3115B4F3400CF791D</string>
<string>6BBB4AB4115B4F3400CF791D</string>
<string>6BBB4ABB115B4F3400CF791D</string>
<string>6BBB4ABE115B4F3400CF791D</string>
<string>6BBB4ABF115B4F3400CF791D</string>
<string>6BBB4AC1115B4F3400CF791D</string>
<string>6BBB4AC2115B4F3400CF791D</string>
<string>6BBB4AC4115B4F3400CF791D</string>
<string>6BBB4AC6115B4F3400CF791D</string>
@ -409,41 +361,47 @@
<string>6BF5F2E511748884000502A6</string>
<string>6BF5F2E611748884000502A6</string>
<string>6BF5F2E711748884000502A6</string>
<string>6BF5F2EA11748884000502A6</string>
<string>6BF5F31C117490A1000502A6</string>
<string>6BF5F32E11759C3C000502A6</string>
<string>6BF5F32F11759C3C000502A6</string>
<string>6BF5F33011759C3C000502A6</string>
<string>6BF5F33111759C3C000502A6</string>
<string>6BF5F36F1175AACB000502A6</string>
<string>6BF5F472117644A2000502A6</string>
<string>6BF5F473117644A2000502A6</string>
<string>6BF5F474117644A2000502A6</string>
<string>6BF5F475117644A2000502A6</string>
<string>6BF5F476117644A2000502A6</string>
<string>6BF5F477117644A2000502A6</string>
<string>6BF5F478117644A2000502A6</string>
<string>6BF5F47B117644A2000502A6</string>
<string>6BF5F47D117644A2000502A6</string>
<string>6BF5F47E117644A2000502A6</string>
<string>6BF5F47F117644A2000502A6</string>
<string>6BF5F4EB1176F3A4000502A6</string>
<string>6BF5F5041176F5F8000502A6</string>
<string>6BF5F5051176F5F8000502A6</string>
<string>6BF5F5061176F5F8000502A6</string>
<string>6BF5F5071176F5F8000502A6</string>
<string>6BF5F5081176F5F8000502A6</string>
<string>6BF5F5091176F5F8000502A6</string>
<string>6BF5F50A1176F5F8000502A6</string>
<string>6BF5F50B1176F5F8000502A6</string>
<string>6BF5F50C1176F5F8000502A6</string>
<string>6BF5F50D1176F5F8000502A6</string>
<string>6BF5F52C1176FA0B000502A6</string>
<string>6B6C464C117C9962002CDD36</string>
<string>6B6C464D117C9962002CDD36</string>
<string>6B6C466F117D8D60002CDD36</string>
<string>6B6C4670117D8D60002CDD36</string>
<string>6B6C4671117D8D60002CDD36</string>
<string>6B4214AB11802FAA006C347B</string>
<string>6B4214AD11802FAA006C347B</string>
<string>6B4214D911803923006C347B</string>
<string>6B4215CB118066FE006C347B</string>
<string>6B6F8E2311837A7400A069D7</string>
<string>6B6F8E2411837A7400A069D7</string>
<string>6B6F8E2511837A7400A069D7</string>
<string>6B555F431191AA4400843384</string>
<string>6B555F441191AA4400843384</string>
<string>6B555F451191AA4400843384</string>
<string>6B55622C119305F200843384</string>
<string>6B55623D1193E79A00843384</string>
<string>6B5562501193EF2F00843384</string>
<string>6B5562511193EF2F00843384</string>
<string>6B5562531193EF2F00843384</string>
<string>6B5562541193EF2F00843384</string>
<string>6B5562841193EFC500843384</string>
<string>6B5562D41193F20700843384</string>
<string>6B5562D51193F20700843384</string>
<string>6B5562DF1193F2A300843384</string>
<string>6B5562E01193F2A300843384</string>
<string>6B5562E11193F2A300843384</string>
<string>6B5562F21193F4CC00843384</string>
<string>6B5562F31193F4CC00843384</string>
<string>6B5562F41193F4CC00843384</string>
<string>6B5562FB1193F50A00843384</string>
<string>6B5562FC1193F50A00843384</string>
</array>
<key>prevStack</key>
<array>
@ -452,14 +410,10 @@
<string>6BBB4AD3115B4F3400CF791D</string>
<string>6BBB4AD4115B4F3400CF791D</string>
<string>6BBB4AD8115B4F3400CF791D</string>
<string>6BBB4ADD115B4F3400CF791D</string>
<string>6BBB4ADE115B4F3400CF791D</string>
<string>6BBB4ADF115B4F3400CF791D</string>
<string>6BBB4AE0115B4F3400CF791D</string>
<string>6BBB4AE1115B4F3400CF791D</string>
<string>6BBB4AE2115B4F3400CF791D</string>
<string>6BBB4AE3115B4F3400CF791D</string>
<string>6BBB4AE4115B4F3400CF791D</string>
<string>6BBB4AE6115B4F3400CF791D</string>
<string>6BBB4AE7115B4F3400CF791D</string>
<string>6BBB4AE8115B4F3400CF791D</string>
@ -478,46 +432,83 @@
<string>6BBB4AF9115B4F3400CF791D</string>
<string>6BBB4AFA115B4F3400CF791D</string>
<string>6BBB4AFB115B4F3400CF791D</string>
<string>6BBB4AFC115B4F3400CF791D</string>
<string>6BBB4AFD115B4F3400CF791D</string>
<string>6BBB4AFE115B4F3400CF791D</string>
<string>6BBB4AFF115B4F3400CF791D</string>
<string>6BBB4B03115B4F3400CF791D</string>
<string>6BBB4B04115B4F3400CF791D</string>
<string>6BBB4B05115B4F3400CF791D</string>
<string>6BBB4B06115B4F3400CF791D</string>
<string>6BBB4B07115B4F3400CF791D</string>
<string>6BBB4B08115B4F3400CF791D</string>
<string>6BBB4B09115B4F3400CF791D</string>
<string>6BBB4B0A115B4F3400CF791D</string>
<string>6BBB4B0B115B4F3400CF791D</string>
<string>6BBB4B0C115B4F3400CF791D</string>
<string>6BBB4B0D115B4F3400CF791D</string>
<string>6BBB4B0E115B4F3400CF791D</string>
<string>6BBB4B0F115B4F3400CF791D</string>
<string>6BBB4B10115B4F3400CF791D</string>
<string>6BBB4B11115B4F3400CF791D</string>
<string>6BBB4B3A115B5BFA00CF791D</string>
<string>6BBB4B87115B639200CF791D</string>
<string>6BBB4C3B115B7A3D00CF791D</string>
<string>6BED8AF0117455CB00582F38</string>
<string>6BF5F233117474CF000502A6</string>
<string>6BF5F27811747CFA000502A6</string>
<string>6BF5F28011747CFA000502A6</string>
<string>6BF5F28D11747CFA000502A6</string>
<string>6BF5F2ED11748884000502A6</string>
<string>6BF5F2EE11748884000502A6</string>
<string>6BF5F2F811748884000502A6</string>
<string>6BF5F33811759C3C000502A6</string>
<string>6BF5F33911759C3C000502A6</string>
<string>6BF5F34A11759C3C000502A6</string>
<string>6B6C464F117C9962002CDD36</string>
<string>6B6C4650117C9962002CDD36</string>
<string>6B6C4651117C9962002CDD36</string>
<string>6B6C4652117C9962002CDD36</string>
<string>6B6C4653117C9962002CDD36</string>
<string>6B6C4672117D8D60002CDD36</string>
<string>6B6C4673117D8D60002CDD36</string>
<string>6B4215CF118066FE006C347B</string>
<string>6B4215D1118066FE006C347B</string>
<string>6B4215DF1180672F006C347B</string>
<string>6B4216881180725E006C347B</string>
<string>6B4217131180803D006C347B</string>
<string>6B555F471191AA4400843384</string>
<string>6B555F481191AA4400843384</string>
<string>6B55623F1193E79A00843384</string>
<string>6B55625A1193EF2F00843384</string>
<string>6B55625B1193EF2F00843384</string>
<string>6B55625C1193EF2F00843384</string>
<string>6B55625D1193EF2F00843384</string>
<string>6B55625E1193EF2F00843384</string>
<string>6B55625F1193EF2F00843384</string>
<string>6B5562601193EF2F00843384</string>
<string>6B5562611193EF2F00843384</string>
<string>6B5562621193EF2F00843384</string>
<string>6B5562631193EF2F00843384</string>
<string>6B5562641193EF2F00843384</string>
<string>6B5562651193EF2F00843384</string>
<string>6B5562661193EF2F00843384</string>
<string>6B5562671193EF2F00843384</string>
<string>6B5562681193EF2F00843384</string>
<string>6B5562691193EF2F00843384</string>
<string>6B55626A1193EF2F00843384</string>
<string>6B55626B1193EF2F00843384</string>
<string>6B55626C1193EF2F00843384</string>
<string>6B55626D1193EF2F00843384</string>
<string>6B55626E1193EF2F00843384</string>
<string>6B55626F1193EF2F00843384</string>
<string>6B5562701193EF2F00843384</string>
<string>6B55627E1193EF9F00843384</string>
<string>6B5562871193EFC500843384</string>
<string>6B5562881193EFC500843384</string>
<string>6B5562891193EFC500843384</string>
<string>6B5562961193F05700843384</string>
<string>6B5562A21193F08C00843384</string>
<string>6B5562A31193F08C00843384</string>
<string>6B5562A41193F08C00843384</string>
<string>6B5562A51193F08C00843384</string>
<string>6B5562AD1193F0BA00843384</string>
<string>6B5562B91193F10000843384</string>
<string>6B5562CD1193F1C000843384</string>
<string>6B5562D71193F20700843384</string>
<string>6B5562D81193F20700843384</string>
<string>6B5562D91193F20700843384</string>
<string>6B5562DA1193F20700843384</string>
<string>6B5562E31193F2A300843384</string>
<string>6B5562E41193F2A300843384</string>
<string>6B5562E51193F2A300843384</string>
<string>6B5562E61193F2A300843384</string>
<string>6B5562F61193F4CC00843384</string>
<string>6B5562F71193F4CC00843384</string>
<string>6B5562F81193F4CC00843384</string>
<string>6B5562FD1193F50A00843384</string>
</array>
</dict>
<key>SplitCount</key>
@ -531,18 +522,18 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 0}, {970, 572}}</string>
<string>{{0, 0}, {970, 535}}</string>
<key>RubberWindowFrame</key>
<string>13 75 1256 702 0 0 1280 778 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
<key>Proportion</key>
<string>572pt</string>
<string>535pt</string>
</dict>
<dict>
<key>Proportion</key>
<string>84pt</string>
<string>121pt</string>
<key>Tabs</key>
<array>
<dict>
@ -556,7 +547,7 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{10, 27}, {970, 139}}</string>
<string>{{10, 27}, {970, 56}}</string>
</dict>
<key>Module</key>
<string>XCDetailModule</string>
@ -610,7 +601,7 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{10, 27}, {970, 57}}</string>
<string>{{10, 27}, {970, 94}}</string>
<key>RubberWindowFrame</key>
<string>13 75 1256 702 0 0 1280 778 </string>
</dict>
@ -640,11 +631,11 @@
</array>
<key>TableOfContents</key>
<array>
<string>6B6C463C117C97EF002CDD36</string>
<string>6B5562411193E79A00843384</string>
<string>1CA23ED40692098700951B8B</string>
<string>6B6C463D117C97EF002CDD36</string>
<string>6B5562421193E79A00843384</string>
<string>6B8632A30F78115100E2684A</string>
<string>6B6C463E117C97EF002CDD36</string>
<string>6B5562431193E79A00843384</string>
<string>1CA23EDF0692099D00951B8B</string>
<string>1CA23EE00692099D00951B8B</string>
<string>1CA23EE10692099D00951B8B</string>
@ -793,14 +784,14 @@
</array>
<key>TableOfContents</key>
<array>
<string>6B6C4659117C998D002CDD36</string>
<string>6B5562721193EF2F00843384</string>
<string>1CCC7628064C1048000F2A68</string>
<string>1CCC7629064C1048000F2A68</string>
<string>6B6C465A117C998D002CDD36</string>
<string>6B6C465B117C998D002CDD36</string>
<string>6B6C465C117C998D002CDD36</string>
<string>6B6C465D117C998D002CDD36</string>
<string>6B6C465E117C998D002CDD36</string>
<string>6B5562731193EF2F00843384</string>
<string>6B5562741193EF2F00843384</string>
<string>6B5562751193EF2F00843384</string>
<string>6B5562761193EF2F00843384</string>
<string>6B5562771193EF2F00843384</string>
</array>
<key>ToolbarConfigUserDefaultsMinorVersion</key>
<string>2</string>
@ -832,7 +823,8 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
<string>6BF5F29911747CFA000502A6</string>
<string>6B5562811193EF9F00843384</string>
<string>6B5562821193EF9F00843384</string>
<string>/Users/memon/Code/recastnavigation/RecastDemo/Build/Xcode/Recast.xcodeproj</string>
</array>
<key>WindowString</key>

View File

@ -20,6 +20,7 @@
#define RECASTSAMPLE_H
#include "DebugDraw.h"
#include "RecastDump.h"
#include "DetourNavMesh.h"
@ -45,8 +46,9 @@ enum SamplePolyFlags
// OpenGL debug draw implementation.
struct DebugDrawGL : public duDebugDraw
class DebugDrawGL : public duDebugDraw
{
public:
virtual void depthMask(bool state);
virtual void begin(duDebugDrawPrimitives prim, float size = 1.0f);
virtual void vertex(const float* pos, unsigned int color);
@ -54,6 +56,22 @@ struct DebugDrawGL : public duDebugDraw
virtual void end();
};
// stdio file implementation.
class FileIO : public duFileIO
{
FILE* m_fp;
int m_mode;
public:
FileIO();
virtual ~FileIO();
bool openForWrite(const char* path);
bool openForRead(const char* path);
virtual bool isWriting() const;
virtual bool isReading() const;
virtual bool write(const void* ptr, const size_t size);
virtual bool read(void* ptr, const size_t size);
};
// Tool types.
enum SampleToolType
{

View File

@ -32,6 +32,7 @@ protected:
bool m_buildAll;
rcBuildTimes m_buildTimes;
float m_totalBuildTimeMs;
bool m_drawPortals;
unsigned char* m_triflags;
rcHeightfield* m_solid;

View File

@ -79,6 +79,61 @@ void DebugDrawGL::end()
}
FileIO::FileIO() :
m_fp(0),
m_mode(-1)
{
}
FileIO::~FileIO()
{
if (m_fp) fclose(m_fp);
}
bool FileIO::openForWrite(const char* path)
{
if (m_fp) return false;
m_fp = fopen(path, "wb");
if (!m_fp) return false;
m_mode = 1;
return true;
}
bool FileIO::openForRead(const char* path)
{
if (m_fp) return false;
m_fp = fopen(path, "rb");
if (!m_fp) return false;
m_mode = 2;
return true;
}
bool FileIO::isWriting() const
{
return m_mode == 1;
}
bool FileIO::isReading() const
{
return m_mode == 2;
}
bool FileIO::write(const void* ptr, const size_t size)
{
if (!m_fp || m_mode != 1) return false;
fwrite(ptr, size, 1, m_fp);
return true;
}
bool FileIO::read(void* ptr, const size_t size)
{
if (!m_fp || m_mode != 2) return false;
fread(ptr, size, 1, m_fp);
return true;
}
Sample::Sample() :
m_geom(0),
m_navMesh(0),

View File

@ -58,11 +58,20 @@ Sample_Debug::Sample_Debug() :
// Test
m_chf = new rcCompactHeightfield;
if (!duReadCompactHeightfield(*m_chf, "Tile_-13_-14_chf.bin"))
FileIO io;
if (!io.openForRead("test.chf"))
{
delete m_chf;
m_chf = 0;
}
else
{
if (!duReadCompactHeightfield(*m_chf, &io))
{
delete m_chf;
m_chf = 0;
}
}
/* if (m_chf)
{

View File

@ -158,6 +158,7 @@ Sample_TileMesh::Sample_TileMesh() :
m_keepInterResults(false),
m_buildAll(true),
m_totalBuildTimeMs(0),
m_drawPortals(false),
m_triflags(0),
m_solid(0),
m_chf(0),
@ -404,6 +405,11 @@ void Sample_TileMesh::handleDebugMode()
{
if (m_navMesh)
{
if (imguiCheck("Draw Portals", m_drawPortals))
m_drawPortals = !m_drawPortals;
imguiSeparator();
imguiValue("Navmesh ready.");
imguiValue("Use 'Create Tiles' tool to experiment.");
imguiValue("LMB: (Re)Create tiles.");
@ -447,7 +453,11 @@ void Sample_TileMesh::handleRender()
duDebugDrawBoxWire(&dd, m_tileBmin[0],m_tileBmin[1],m_tileBmin[2], m_tileBmax[0],m_tileBmax[1],m_tileBmax[2], m_tileCol, 2.0f);
if (m_navMesh)
{
duDebugDrawNavMesh(&dd, *m_navMesh, m_navMeshDrawFlags);
if (m_drawPortals)
duDebugDrawNavMeshPortals(&dd, *m_navMesh);
}
if (m_tool)
m_tool->handleRender();

View File

@ -104,7 +104,7 @@ void SlideShow::setSlide(int n)
if (m_nextSlide > maxIdx) m_nextSlide = maxIdx;
}
void SlideShow::updateAndDraw(float dt, const float /*w*/, const float /*h*/)
void SlideShow::updateAndDraw(float dt, const float w, const float h)
{
float slideAlphaTarget = (m_showCurSlide && m_texId) ? 1.0f : 0.0f;
if (m_curSlide != m_nextSlide)
@ -138,8 +138,8 @@ void SlideShow::updateAndDraw(float dt, const float /*w*/, const float /*h*/)
const float tw = (float)m_width;
const float th = (float)m_height;
const float hw = tw/2; //w*0.5f;
const float hh = th/2; //h*0.5f;
const float hw = w*0.5f;
const float hh = h*0.5f;
glColor4ub(255,255,255,alpha);
glBegin(GL_QUADS);

View File

@ -79,9 +79,24 @@ int main(int /*argc*/, char** /*argv*/)
const SDL_VideoInfo* vi = SDL_GetVideoInfo();
int width = vi->current_w - 20;
int height = vi->current_h - 80;
SDL_Surface* screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL);
const bool presentationMode = false;
int width, height;
SDL_Surface* screen = 0;
if (presentationMode)
{
width = vi->current_w;
height = vi->current_h;
screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL|SDL_FULLSCREEN);
}
else
{
width = vi->current_w - 20;
height = vi->current_h - 80;
screen = SDL_SetVideoMode(width, height, 0, SDL_OPENGL);
}
if (!screen)
{
printf("Could not initialise SDL opengl\n");
@ -111,7 +126,7 @@ int main(int /*argc*/, char** /*argv*/)
bool movedDuringRotate = false;
float rays[3], raye[3];
bool mouseOverMenu = false;
bool showMenu = true;
bool showMenu = !presentationMode;
bool showLog = false;
bool showDebugMode = true;
bool showTools = true;
@ -446,7 +461,6 @@ int main(int /*argc*/, char** /*argv*/)
if (test)
test->handleRender();
glDisable(GL_FOG);
// Render GUI
@ -559,7 +573,6 @@ int main(int /*argc*/, char** /*argv*/)
imguiSeparator();
}
imguiEndScrollArea();
if (showDebugMode)
@ -580,7 +593,7 @@ int main(int /*argc*/, char** /*argv*/)
if (showSample)
{
static int levelScroll = 0;
if (imguiBeginScrollArea("Choose Level", width-10-250-10-200, height-10-250, 200, 250, &levelScroll))
if (imguiBeginScrollArea("Choose Sample", width-10-250-10-200, height-10-250, 200, 250, &levelScroll))
mouseOverMenu = true;
Sample* newSample = 0;
@ -641,7 +654,7 @@ int main(int /*argc*/, char** /*argv*/)
if (showLevels)
{
static int levelScroll = 0;
if (imguiBeginScrollArea("Choose Level", width-10-250-10-200, height-10-350, 200, 350, &levelScroll))
if (imguiBeginScrollArea("Choose Level", width-10-250-10-200, height-10-450, 200, 450, &levelScroll))
mouseOverMenu = true;
int levelToLoad = -1;