diff --git a/RecastDemo/Bin/Recast.app/Contents/MacOS/Recast b/RecastDemo/Bin/Recast.app/Contents/MacOS/Recast index 0e3d4df..bffdd5c 100755 Binary files a/RecastDemo/Bin/Recast.app/Contents/MacOS/Recast and b/RecastDemo/Bin/Recast.app/Contents/MacOS/Recast differ diff --git a/RecastDemo/Build/Xcode/Recast.xcodeproj/memon.pbxuser b/RecastDemo/Build/Xcode/Recast.xcodeproj/memon.pbxuser index 642c137..62dbdb7 100644 --- a/RecastDemo/Build/Xcode/Recast.xcodeproj/memon.pbxuser +++ b/RecastDemo/Build/Xcode/Recast.xcodeproj/memon.pbxuser @@ -540,17 +540,17 @@ }; 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {915, 1344}}"; - sepNavSelRange = "{1772, 0}"; - sepNavVisRange = "{1599, 833}"; + sepNavIntBoundsRect = "{{0, 0}, {915, 1376}}"; + sepNavSelRange = "{2395, 13}"; + sepNavVisRange = "{1664, 810}"; sepNavWindowFrame = "{{15, 78}, {1011, 695}}"; }; }; 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {1034, 14096}}"; - sepNavSelRange = "{9782, 10}"; - sepNavVisRange = "{9366, 678}"; + sepNavIntBoundsRect = "{{0, 0}, {1034, 14320}}"; + sepNavSelRange = "{12554, 0}"; + sepNavVisRange = "{12501, 672}"; }; }; 6B555DAE100B211D00247EA3 /* imguiRenderGL.h */ = { @@ -838,9 +838,9 @@ }; 6BA1E88810C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp */ = { uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {915, 9728}}"; - sepNavSelRange = "{386, 31}"; - sepNavVisRange = "{0, 625}"; + sepNavIntBoundsRect = "{{0, 0}, {915, 9904}}"; + sepNavSelRange = "{1126, 109}"; + sepNavVisRange = "{814, 527}"; }; }; 6BA1E88910C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp */ = { @@ -1066,13 +1066,25 @@ vrLoc = 1343; }; 6BBB87CE10EA8EF2008FEA1F /* NavMeshTesterTool.h */ = { + isa = PBXFileReference; + fileEncoding = 4; + lastKnownFileType = sourcecode.c.h; + name = NavMeshTesterTool.h; + path = /Users/memon/Code/recastnavigation/RecastDemo/Build/Xcode/NavMeshTesterTool.h; + sourceTree = ""; uiCtxt = { - sepNavIntBoundsRect = "{{0, 0}, {915, 1008}}"; + sepNavIntBoundsRect = "{{0, 0}, {915, 1104}}"; sepNavSelRange = "{362, 0}"; - sepNavVisRange = "{329, 590}"; + sepNavVisRange = "{300, 618}"; }; }; 6BBB87CF10EA8EFA008FEA1F /* NavMeshTesterTool.cpp */ = { + isa = PBXFileReference; + fileEncoding = 4; + lastKnownFileType = sourcecode.cpp.cpp; + name = NavMeshTesterTool.cpp; + path = /Users/memon/Code/recastnavigation/RecastDemo/Build/Xcode/NavMeshTesterTool.cpp; + sourceTree = ""; uiCtxt = { sepNavIntBoundsRect = "{{0, 0}, {1174, 7280}}"; sepNavSelRange = "{1511, 0}"; @@ -1414,7 +1426,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 74"; rLen = 0; - rLoc = 1668; + rLoc = 1686; rType = 0; vrLen = 557; vrLoc = 1701; @@ -1434,7 +1446,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 63"; rLen = 0; - rLoc = 1667; + rLoc = 1685; rType = 0; vrLen = 566; vrLoc = 1556; @@ -1444,7 +1456,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 65"; rLen = 0; - rLoc = 1668; + rLoc = 1686; rType = 0; vrLen = 537; vrLoc = 1556; @@ -1504,7 +1516,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 63"; rLen = 0; - rLoc = 1667; + rLoc = 1685; rType = 0; vrLen = 524; vrLoc = 1556; @@ -1534,7 +1546,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 64"; rLen = 0; - rLoc = 1667; + rLoc = 1685; rType = 0; vrLen = 524; vrLoc = 1556; @@ -1584,7 +1596,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 303"; rLen = 0; - rLoc = 5340; + rLoc = 5546; rType = 0; vrLen = 716; vrLoc = 6712; @@ -1614,7 +1626,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 119"; rLen = 0; - rLoc = 2394; + rLoc = 2436; rType = 0; vrLen = 179; vrLoc = 2253; @@ -1624,7 +1636,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 308"; rLen = 0; - rLoc = 5340; + rLoc = 5546; rType = 0; vrLen = 719; vrLoc = 6799; @@ -1634,7 +1646,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 119"; rLen = 23; - rLoc = 2371; + rLoc = 2389; rType = 0; vrLen = 131; vrLoc = 2301; @@ -1654,7 +1666,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 424"; rLen = 0; - rLoc = 7331; + rLoc = 7537; rType = 0; vrLen = 597; vrLoc = 9490; @@ -1704,7 +1716,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 306"; rLen = 0; - rLoc = 5143; + rLoc = 5349; rType = 0; vrLen = 701; vrLoc = 7092; @@ -1714,7 +1726,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 119"; rLen = 23; - rLoc = 2371; + rLoc = 2389; rType = 0; vrLen = 151; vrLoc = 2281; @@ -1854,7 +1866,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 63"; rLen = 0; - rLoc = 1667; + rLoc = 1685; rType = 0; vrLen = 496; vrLoc = 1513; @@ -1864,7 +1876,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 306"; rLen = 0; - rLoc = 5183; + rLoc = 5389; rType = 0; vrLen = 514; vrLoc = 6951; @@ -1884,7 +1896,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 312"; rLen = 19; - rLoc = 5278; + rLoc = 5484; rType = 0; vrLen = 543; vrLoc = 7057; @@ -1926,7 +1938,7 @@ rLen = 0; rLoc = 919; rType = 0; - vrLen = 643; + vrLen = 626; vrLoc = 722; }; 6BBB886E10EA9ECC008FEA1F /* PBXTextBookmark */ = { @@ -1934,7 +1946,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 310"; rLen = 0; - rLoc = 5235; + rLoc = 5441; rType = 0; vrLen = 509; vrLoc = 7055; @@ -1946,7 +1958,7 @@ rLen = 0; rLoc = 1140; rType = 0; - vrLen = 634; + vrLen = 626; vrLoc = 722; }; 6BBB887010EA9ECC008FEA1F /* PBXTextBookmark */ = { @@ -2056,7 +2068,7 @@ rLen = 0; rLoc = 1164; rType = 0; - vrLen = 646; + vrLen = 625; vrLoc = 723; }; 6BBB888410EA9FE6008FEA1F /* PBXTextBookmark */ = { @@ -2174,7 +2186,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 109"; rLen = 0; - rLoc = 2207; + rLoc = 2225; rType = 0; vrLen = 154; vrLoc = 2278; @@ -2184,7 +2196,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 159"; rLen = 0; - rLoc = 3649; + rLoc = 3668; rType = 0; vrLen = 500; vrLoc = 3320; @@ -2331,7 +2343,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 573"; rLen = 0; - rLoc = 8662; + rLoc = 8868; rType = 0; vrLen = 407; vrLoc = 14553; @@ -2361,7 +2373,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 632"; rLen = 0; - rLoc = 10073; + rLoc = 10279; rType = 0; vrLen = 565; vrLoc = 15643; @@ -2371,7 +2383,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 111"; rLen = 0; - rLoc = 2237; + rLoc = 2255; rType = 0; vrLen = 174; vrLoc = 2258; @@ -2381,7 +2393,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 622"; rLen = 0; - rLoc = 9864; + rLoc = 10070; rType = 0; vrLen = 723; vrLoc = 2508; @@ -2421,7 +2433,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 289"; rLen = 0; - rLoc = 5235; + rLoc = 5441; rType = 0; vrLen = 641; vrLoc = 6480; @@ -2501,7 +2513,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 216"; rLen = 0; - rLoc = 5053; + rLoc = 5259; rType = 0; vrLen = 809; vrLoc = 4384; @@ -2511,7 +2523,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 35"; rLen = 0; - rLoc = 1240; + rLoc = 1258; rType = 0; vrLen = 785; vrLoc = 1452; @@ -2521,7 +2533,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 165"; rLen = 0; - rLoc = 3836; + rLoc = 3855; rType = 0; vrLen = 875; vrLoc = 3936; @@ -2551,7 +2563,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 229"; rLen = 34; - rLoc = 5303; + rLoc = 5509; rType = 0; vrLen = 749; vrLoc = 4504; @@ -2631,7 +2643,7 @@ fRef = 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */; name = "Sample_TileMesh.cpp: 377"; rLen = 60; - rLoc = 8628; + rLoc = 8834; rType = 0; vrLen = 516; vrLoc = 8290; @@ -2761,7 +2773,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 75"; rLen = 61; - rLoc = 2237; + rLoc = 2255; rType = 0; vrLen = 809; vrLoc = 1623; @@ -2941,7 +2953,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 60"; rLen = 0; - rLoc = 1772; + rLoc = 1790; rType = 0; vrLen = 833; vrLoc = 1599; @@ -2981,7 +2993,7 @@ fRef = 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */; name = "Sample_TileMesh.h: 60"; rLen = 0; - rLoc = 1772; + rLoc = 1790; rType = 0; vrLen = 833; vrLoc = 1599; diff --git a/RecastDemo/Build/Xcode/Recast.xcodeproj/project.pbxproj b/RecastDemo/Build/Xcode/Recast.xcodeproj/project.pbxproj index d829e0a..affada4 100644 --- a/RecastDemo/Build/Xcode/Recast.xcodeproj/project.pbxproj +++ b/RecastDemo/Build/Xcode/Recast.xcodeproj/project.pbxproj @@ -34,11 +34,11 @@ 6BA1E88B10C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BA1E88810C7BFC9008007F6 /* Sample_SoloMeshSimple.cpp */; }; 6BA1E88C10C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BA1E88910C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp */; }; 6BB788170FC0472B003C24DB /* ChunkyTriMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BB788160FC0472B003C24DB /* ChunkyTriMesh.cpp */; }; + 6BB7FC0B10EBB6AA006DA0A6 /* NavMeshTesterTool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BB7FC0A10EBB6AA006DA0A6 /* NavMeshTesterTool.cpp */; }; 6BB93C7D10CFE1D500F74F2B /* DebugDraw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BB93C7A10CFE1D500F74F2B /* DebugDraw.cpp */; }; 6BB93C7E10CFE1D500F74F2B /* DetourDebugDraw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BB93C7B10CFE1D500F74F2B /* DetourDebugDraw.cpp */; }; 6BB93C7F10CFE1D500F74F2B /* RecastDebugDraw.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BB93C7C10CFE1D500F74F2B /* RecastDebugDraw.cpp */; }; 6BB93CF610CFEC4500F74F2B /* RecastDump.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BB93CF510CFEC4500F74F2B /* RecastDump.cpp */; }; - 6BBB87D010EA8EFA008FEA1F /* NavMeshTesterTool.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6BBB87CF10EA8EFA008FEA1F /* NavMeshTesterTool.cpp */; }; 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; /* End PBXBuildFile section */ @@ -94,6 +94,8 @@ 6BA1E88F10C7BFD3008007F6 /* Sample_SoloMeshTiled.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Sample_SoloMeshTiled.h; path = ../../Include/Sample_SoloMeshTiled.h; sourceTree = SOURCE_ROOT; }; 6BB788160FC0472B003C24DB /* ChunkyTriMesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ChunkyTriMesh.cpp; path = ../../Source/ChunkyTriMesh.cpp; sourceTree = SOURCE_ROOT; }; 6BB788180FC04753003C24DB /* ChunkyTriMesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ChunkyTriMesh.h; path = ../../Include/ChunkyTriMesh.h; sourceTree = SOURCE_ROOT; }; + 6BB7FC0910EBB6AA006DA0A6 /* NavMeshTesterTool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NavMeshTesterTool.h; path = ../../Include/NavMeshTesterTool.h; sourceTree = SOURCE_ROOT; }; + 6BB7FC0A10EBB6AA006DA0A6 /* NavMeshTesterTool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = NavMeshTesterTool.cpp; path = ../../Source/NavMeshTesterTool.cpp; sourceTree = SOURCE_ROOT; }; 6BB93C7710CFE1D500F74F2B /* DebugDraw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DebugDraw.h; path = ../../../DebugUtils/Include/DebugDraw.h; sourceTree = SOURCE_ROOT; }; 6BB93C7810CFE1D500F74F2B /* DetourDebugDraw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DetourDebugDraw.h; path = ../../../DebugUtils/Include/DetourDebugDraw.h; sourceTree = SOURCE_ROOT; }; 6BB93C7910CFE1D500F74F2B /* RecastDebugDraw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RecastDebugDraw.h; path = ../../../DebugUtils/Include/RecastDebugDraw.h; sourceTree = SOURCE_ROOT; }; @@ -102,8 +104,6 @@ 6BB93C7C10CFE1D500F74F2B /* RecastDebugDraw.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RecastDebugDraw.cpp; path = ../../../DebugUtils/Source/RecastDebugDraw.cpp; sourceTree = SOURCE_ROOT; }; 6BB93CF410CFEC4500F74F2B /* RecastDump.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RecastDump.h; path = ../../../DebugUtils/Include/RecastDump.h; sourceTree = SOURCE_ROOT; }; 6BB93CF510CFEC4500F74F2B /* RecastDump.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RecastDump.cpp; path = ../../../DebugUtils/Source/RecastDump.cpp; sourceTree = SOURCE_ROOT; }; - 6BBB87CE10EA8EF2008FEA1F /* NavMeshTesterTool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NavMeshTesterTool.h; sourceTree = ""; }; - 6BBB87CF10EA8EFA008FEA1F /* NavMeshTesterTool.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = NavMeshTesterTool.cpp; sourceTree = ""; }; 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 8D1107320486CEB800E47090 /* Recast.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Recast.app; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -235,6 +235,8 @@ 6B555DF5100B25FC00247EA3 /* Samples */ = { isa = PBXGroup; children = ( + 6BB7FC0910EBB6AA006DA0A6 /* NavMeshTesterTool.h */, + 6BB7FC0A10EBB6AA006DA0A6 /* NavMeshTesterTool.cpp */, 6B25B6100FFA62AD004F1BC4 /* Sample.h */, 6B25B6140FFA62BE004F1BC4 /* Sample.cpp */, 6BA1E88E10C7BFD3008007F6 /* Sample_SoloMeshSimple.h */, @@ -243,8 +245,6 @@ 6BA1E88910C7BFC9008007F6 /* Sample_SoloMeshTiled.cpp */, 6B2AEC510FFB8946005BE9CC /* Sample_TileMesh.h */, 6B2AEC520FFB8958005BE9CC /* Sample_TileMesh.cpp */, - 6BBB87CE10EA8EF2008FEA1F /* NavMeshTesterTool.h */, - 6BBB87CF10EA8EFA008FEA1F /* NavMeshTesterTool.cpp */, ); name = Samples; sourceTree = ""; @@ -362,7 +362,7 @@ 6BB93C7E10CFE1D500F74F2B /* DetourDebugDraw.cpp in Sources */, 6BB93C7F10CFE1D500F74F2B /* RecastDebugDraw.cpp in Sources */, 6BB93CF610CFEC4500F74F2B /* RecastDump.cpp in Sources */, - 6BBB87D010EA8EFA008FEA1F /* NavMeshTesterTool.cpp in Sources */, + 6BB7FC0B10EBB6AA006DA0A6 /* NavMeshTesterTool.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/RecastDemo/Include/NavMeshTesterTool.h b/RecastDemo/Include/NavMeshTesterTool.h new file mode 100644 index 0000000..e25173a --- /dev/null +++ b/RecastDemo/Include/NavMeshTesterTool.h @@ -0,0 +1,63 @@ +#ifndef NAVMESHTESTERTOOL_H +#define NAVMESHTESTERTOOL_H + +#include "Sample.h" +#include "DetourNavMesh.h" + +class NavMeshTesterTool : public SampleTool +{ + Sample* m_sample; + + dtNavMesh* m_navMesh; + float m_agentRadius; + float m_agentHeight; + + enum ToolMode + { + TOOLMODE_PATHFIND, + TOOLMODE_RAYCAST, + TOOLMODE_DISTANCE_TO_WALL, + TOOLMODE_FIND_POLYS_AROUND, + }; + + ToolMode m_toolMode; + + static const int MAX_POLYS = 256; + static const int MAX_SMOOTH = 2048; + + dtPolyRef m_startRef; + dtPolyRef m_endRef; + dtPolyRef m_polys[MAX_POLYS]; + dtPolyRef m_parent[MAX_POLYS]; + int m_npolys; + float m_straightPath[MAX_POLYS*3]; + int m_nstraightPath; + float m_polyPickExt[3]; + float m_smoothPath[MAX_SMOOTH*3]; + int m_nsmoothPath; + + float m_spos[3]; + float m_epos[3]; + float m_hitPos[3]; + float m_hitNormal[3]; + float m_distanceToWall; + bool m_sposSet; + bool m_eposSet; + +public: + NavMeshTesterTool(); + ~NavMeshTesterTool(); + + virtual int type() { return TOOL_NAVMESH_TESTER; } + virtual void init(Sample* sample); + virtual void reset(); + virtual void handleMenu(); + virtual void handleClick(const float* p, bool shift); + virtual void handleRender(); + virtual void handleRenderOverlay(double* proj, double* model, int* view); + + void recalc(); + void drawAgent(const float* pos, float r, float h, float c, const float* col); +}; + +#endif // NAVMESHTESTERTOOL_H \ No newline at end of file diff --git a/RecastDemo/Source/NavMeshTesterTool.cpp b/RecastDemo/Source/NavMeshTesterTool.cpp new file mode 100644 index 0000000..6e6b68c --- /dev/null +++ b/RecastDemo/Source/NavMeshTesterTool.cpp @@ -0,0 +1,454 @@ +#define _USE_MATH_DEFINES +#include +#include +#include +#include "SDL.h" +#include "SDL_opengl.h" +#include "imgui.h" +#include "NavMeshTesterTool.h" +#include "Sample.h" +#include "Recast.h" +#include "RecastDebugDraw.h" +#include "DetourNavMesh.h" +#include "DetourNavMeshBuilder.h" +#include "DetourDebugDraw.h" + +#ifdef WIN32 +# define snprintf _snprintf +#endif + +inline bool inRange(const float* v1, const float* v2, const float r, const float h) +{ + const float dx = v2[0] - v1[0]; + const float dy = v2[1] - v1[1]; + const float dz = v2[2] - v1[2]; + return (dx*dx + dz*dz) < r*r && fabsf(dy) < h; +} + + +NavMeshTesterTool::NavMeshTesterTool() : + m_sample(0), + m_navMesh(0), + m_agentRadius(0), + m_agentHeight(0), + m_toolMode(TOOLMODE_PATHFIND), + m_startRef(0), + m_endRef(0), + m_npolys(0), + m_nstraightPath(0), + m_nsmoothPath(0), + m_distanceToWall(0), + m_sposSet(false), + m_eposSet(false) +{ + m_polyPickExt[0] = 2; + m_polyPickExt[1] = 4; + m_polyPickExt[2] = 2; +} + +NavMeshTesterTool::~NavMeshTesterTool() +{ +} + +void NavMeshTesterTool::init(Sample* sample) +{ + m_sample = sample; + m_agentRadius = sample->getAgentRadius(); + m_agentHeight = sample->getAgentHeight(); + m_navMesh = sample->getNavMesh(); + recalc(); +} + +void NavMeshTesterTool::handleMenu() +{ + if (imguiCheck("Pathfind", m_toolMode == TOOLMODE_PATHFIND)) + { + m_toolMode = TOOLMODE_PATHFIND; + recalc(); + } + if (imguiCheck("Distance to Wall", m_toolMode == TOOLMODE_DISTANCE_TO_WALL)) + { + m_toolMode = TOOLMODE_DISTANCE_TO_WALL; + recalc(); + } + if (imguiCheck("Raycast", m_toolMode == TOOLMODE_RAYCAST)) + { + m_toolMode = TOOLMODE_RAYCAST; + recalc(); + } + if (imguiCheck("Find Polys Around", m_toolMode == TOOLMODE_FIND_POLYS_AROUND)) + { + m_toolMode = TOOLMODE_FIND_POLYS_AROUND; + recalc(); + } +} + +void NavMeshTesterTool::handleClick(const float* p, bool shift) +{ + if (shift) + { + m_sposSet = true; + vcopy(m_spos, p); + } + else + { + m_eposSet = true; + vcopy(m_epos, p); + } + recalc(); +} + +void NavMeshTesterTool::reset() +{ + m_startRef = 0; + m_endRef = 0; + m_npolys = 0; + m_nstraightPath = 0; + m_nsmoothPath = 0; + memset(m_hitPos, 0, sizeof(m_hitPos)); + memset(m_hitNormal, 0, sizeof(m_hitNormal)); + m_distanceToWall = 0; +} + +void NavMeshTesterTool::recalc() +{ + if (!m_navMesh) + return; + + if (m_sposSet) + m_startRef = m_navMesh->findNearestPoly(m_spos, m_polyPickExt); + else + m_startRef = 0; + + if (m_eposSet) + m_endRef = m_navMesh->findNearestPoly(m_epos, m_polyPickExt); + else + m_endRef = 0; + + if (m_toolMode == TOOLMODE_PATHFIND) + { + if (m_sposSet && m_eposSet && m_startRef && m_endRef) + { + m_npolys = m_navMesh->findPath(m_startRef, m_endRef, m_spos, m_epos, m_polys, MAX_POLYS); + if (m_npolys) + { + m_nstraightPath = m_navMesh->findStraightPath(m_spos, m_epos, m_polys, m_npolys, m_straightPath, MAX_POLYS); + + // Iterate over the path to find smooth path on the detail mesh surface. + const dtPolyRef* polys = m_polys; + int npolys = m_npolys; + + float iterPos[3], targetPos[3]; + m_navMesh->closestPointOnPolyBoundary(m_startRef, m_spos, iterPos); + m_navMesh->closestPointOnPolyBoundary(polys[npolys-1], m_epos, targetPos); + + static const float STEP_SIZE = 0.5f; + static const float SLOP = 0.01f; + + m_nsmoothPath = 0; + + vcopy(&m_smoothPath[m_nsmoothPath*3], iterPos); + m_nsmoothPath++; + + while (npolys && m_nsmoothPath < MAX_SMOOTH) + { + // Find steer target. + static const int MAX_STEER = 3; + float steerPath[MAX_STEER*3]; + int nsteerPath = m_navMesh->findStraightPath(iterPos, m_epos, polys, npolys, steerPath, MAX_STEER); + if (!nsteerPath) + break; + // Find vertex far enough to steer to. + int ns = 0; + while (ns < nsteerPath) + { + if (!inRange(&steerPath[ns*3], iterPos, SLOP, 1000.0f)) + break; + ns++; + } + if (ns >= nsteerPath) + break; + bool endOfPath = inRange(&steerPath[ns*3], targetPos, SLOP*SLOP, 1.0f); + + // Find movement delta. + float delta[3], len; + vsub(delta, &steerPath[ns*3], iterPos); + len = sqrtf(vdot(delta,delta)); + if (endOfPath && len < STEP_SIZE) + len = 1; + else + len = STEP_SIZE / len; + float moveTgt[3]; + vmad(moveTgt, iterPos, delta, len); + + // Move + float result[3]; + int n = m_navMesh->moveAlongPathCorridor(iterPos, moveTgt, result, polys, npolys); + float h = 0; + m_navMesh->getPolyHeight(polys[n], result, &h); + result[1] = h; + // Shrink path corridor of possible. + polys += n; + npolys -= n; + + vcopy(iterPos, result); + + // Close enough to the target. + if (inRange(iterPos, targetPos, SLOP, 1.0f)) + { + vcopy(iterPos, targetPos); + npolys = 0; + } + + // Store results. + if (m_nsmoothPath < MAX_SMOOTH) + { + vcopy(&m_smoothPath[m_nsmoothPath*3], iterPos); + m_nsmoothPath++; + } + } + + } + } + else + { + m_npolys = 0; + m_nstraightPath = 0; + } + } + else if (m_toolMode == TOOLMODE_RAYCAST) + { + m_nstraightPath = 0; + if (m_sposSet && m_eposSet && m_startRef) + { + float t = 0; + m_npolys = 0; + m_nstraightPath = 2; + m_straightPath[0] = m_spos[0]; + m_straightPath[1] = m_spos[1]; + m_straightPath[2] = m_spos[2]; + vcopy(m_hitPos, m_epos); + m_npolys = m_navMesh->raycast(m_startRef, m_spos, m_epos, t, m_hitNormal, m_polys, MAX_POLYS); + if (m_npolys && t < 1) + { + m_hitPos[0] = m_spos[0] + (m_epos[0] - m_spos[0]) * t; + m_hitPos[1] = m_spos[1] + (m_epos[1] - m_spos[1]) * t; + m_hitPos[2] = m_spos[2] + (m_epos[2] - m_spos[2]) * t; + } + vcopy(&m_straightPath[3], m_hitPos); + } + } + else if (m_toolMode == TOOLMODE_DISTANCE_TO_WALL) + { + m_distanceToWall = 0; + if (m_sposSet && m_startRef) + m_distanceToWall = m_navMesh->findDistanceToWall(m_startRef, m_spos, 100.0f, m_hitPos, m_hitNormal); + } + else if (m_toolMode == TOOLMODE_FIND_POLYS_AROUND) + { + if (m_sposSet && m_startRef && m_eposSet) + { + const float dx = m_epos[0] - m_spos[0]; + const float dz = m_epos[2] - m_spos[2]; + float dist = sqrtf(dx*dx + dz*dz); + m_npolys = m_navMesh->findPolysAround(m_startRef, m_spos, dist, m_polys, m_parent, 0, MAX_POLYS); + } + } +} + +static void getPolyCenter(dtNavMesh* navMesh, dtPolyRef ref, float* center) +{ + const dtPoly* p = navMesh->getPolyByRef(ref); + if (!p) return; + const float* verts = navMesh->getPolyVertsByRef(ref); + center[0] = 0; + center[1] = 0; + center[2] = 0; + for (int i = 0; i < (int)p->nv; ++i) + { + const float* v = &verts[p->v[i]*3]; + center[0] += v[0]; + center[1] += v[1]; + center[2] += v[2]; + } + const float s = 1.0f / p->nv; + center[0] *= s; + center[1] *= s; + center[2] *= s; +} + +void NavMeshTesterTool::handleRender() +{ + if (!m_navMesh) + return; + + DebugDrawGL dd; + + static const float startCol[4] = { 0.5f, 0.1f, 0.0f, 0.75f }; + static const float endCol[4] = { 0.2f, 0.4f, 0.0f, 0.75f }; + static const float pathCol[4] = {0,0,0,0.25f}; + + glDepthMask(GL_FALSE); + + if (m_sposSet) + drawAgent(m_spos, m_agentRadius, m_agentHeight, 0/*m_agentMaxClimb*/, startCol); + if (m_eposSet) + drawAgent(m_epos, m_agentRadius, m_agentHeight, 0/*m_agentMaxClimb*/, endCol); + +/* if (flags & NAVMESH_POLYS) + duDebugDrawNavMesh(&dd, m_navMesh, m_toolMode == TOOLMODE_PATHFIND); + + if (flags & NAVMESH_BVTREE) + duDebugDrawNavMeshBVTree(&dd, m_navMesh); + + if (flags & NAVMESH_TOOLS)*/ + { + if (m_toolMode == TOOLMODE_PATHFIND) + { + duDebugDrawNavMeshPoly(&dd, m_navMesh, m_startRef, startCol); + duDebugDrawNavMeshPoly(&dd, m_navMesh, m_endRef, endCol); + + if (m_npolys) + { + for (int i = 1; i < m_npolys-1; ++i) + duDebugDrawNavMeshPoly(&dd, m_navMesh, m_polys[i], pathCol); + } + if (m_nstraightPath) + { + glColor4ub(64,16,0,64); + glLineWidth(2.0f); + glBegin(GL_LINE_STRIP); + for (int i = 0; i < m_nstraightPath; ++i) + glVertex3f(m_straightPath[i*3], m_straightPath[i*3+1]+0.4f, m_straightPath[i*3+2]); + glEnd(); + glLineWidth(1.0f); + glColor4ub(64,16,0,128); + glPointSize(3.0f); + glBegin(GL_POINTS); + for (int i = 0; i < m_nstraightPath; ++i) + glVertex3f(m_straightPath[i*3], m_straightPath[i*3+1]+0.4f, m_straightPath[i*3+2]); + glEnd(); + glPointSize(1.0f); + } + if (m_nsmoothPath) + { + glColor4ub(0,0,0,220); + glLineWidth(3.0f); + glBegin(GL_LINES); + for (int i = 0; i < m_nsmoothPath; ++i) + glVertex3f(m_smoothPath[i*3], m_smoothPath[i*3+1]+0.1f, m_smoothPath[i*3+2]); + glEnd(); + glLineWidth(1.0f); + } + } + else if (m_toolMode == TOOLMODE_RAYCAST) + { + duDebugDrawNavMeshPoly(&dd, m_navMesh, m_startRef, startCol); + + if (m_nstraightPath) + { + for (int i = 1; i < m_npolys; ++i) + duDebugDrawNavMeshPoly(&dd, m_navMesh, m_polys[i], pathCol); + + glColor4ub(64,16,0,220); + glLineWidth(3.0f); + glBegin(GL_LINE_STRIP); + for (int i = 0; i < m_nstraightPath; ++i) + glVertex3f(m_straightPath[i*3], m_straightPath[i*3+1]+0.4f, m_straightPath[i*3+2]); + glEnd(); + glLineWidth(1.0f); + glPointSize(4.0f); + glBegin(GL_POINTS); + for (int i = 0; i < m_nstraightPath; ++i) + glVertex3f(m_straightPath[i*3], m_straightPath[i*3+1]+0.4f, m_straightPath[i*3+2]); + glEnd(); + glPointSize(1.0f); + + glColor4ub(255,255,255,128); + glBegin(GL_LINES); + glVertex3f(m_hitPos[0], m_hitPos[1] + 0.4f, m_hitPos[2]); + glVertex3f(m_hitPos[0] + m_hitNormal[0]*m_agentRadius, m_hitPos[1] + 0.4f + m_hitNormal[1]*m_agentRadius, m_hitPos[2] + m_hitNormal[2]*m_agentRadius); + glEnd(); + } + } + else if (m_toolMode == TOOLMODE_DISTANCE_TO_WALL) + { + duDebugDrawNavMeshPoly(&dd, m_navMesh, m_startRef, startCol); + const float col[4] = {1,1,1,0.5f}; + duDebugDrawCylinderWire(&dd, m_spos[0]-m_distanceToWall, m_spos[1]+0.02f, m_spos[2]-m_distanceToWall, + m_spos[0]+m_distanceToWall, m_spos[1]+m_agentHeight, m_spos[2]+m_distanceToWall, col); + glLineWidth(3.0f); + glColor4fv(col); + glBegin(GL_LINES); + glVertex3f(m_hitPos[0], m_hitPos[1] + 0.02f, m_hitPos[2]); + glVertex3f(m_hitPos[0], m_hitPos[1] + m_agentHeight, m_hitPos[2]); + glEnd(); + glLineWidth(1.0f); + } + else if (m_toolMode == TOOLMODE_FIND_POLYS_AROUND) + { + const float cola[4] = {0,0,0,0.5f}; + for (int i = 0; i < m_npolys; ++i) + { + duDebugDrawNavMeshPoly(&dd, m_navMesh, m_polys[i], pathCol); + if (m_parent[i]) + { + float p0[3], p1[3]; + getPolyCenter(m_navMesh, m_polys[i], p0); + getPolyCenter(m_navMesh, m_parent[i], p1); + duDebugDrawArc(&dd, p0, p1, cola, 2.0f); + } + } + + const float dx = m_epos[0] - m_spos[0]; + const float dz = m_epos[2] - m_spos[2]; + float dist = sqrtf(dx*dx + dz*dz); + const float col[4] = {1,1,1,0.5f}; + duDebugDrawCylinderWire(&dd, m_spos[0]-dist, m_spos[1]+0.02f, m_spos[2]-dist, + m_spos[0]+dist, m_spos[1]+m_agentHeight, m_spos[2]+dist, col); + } + } + + glDepthMask(GL_TRUE); +} + +void NavMeshTesterTool::handleRenderOverlay(double* proj, double* model, int* view) +{ + GLdouble x, y, z; + + // Draw start and end point labels + if (m_sposSet && gluProject((GLdouble)m_spos[0], (GLdouble)m_spos[1], (GLdouble)m_spos[2], + model, proj, view, &x, &y, &z)) + { + imguiDrawText((int)x, (int)(y-25), IMGUI_ALIGN_CENTER, "Start", imguiRGBA(0,0,0,220)); + } + if (m_eposSet && gluProject((GLdouble)m_epos[0], (GLdouble)m_epos[1], (GLdouble)m_epos[2], + model, proj, view, &x, &y, &z)) + { + imguiDrawText((int)x, (int)(y-25), IMGUI_ALIGN_CENTER, "End", imguiRGBA(0,0,0,220)); + } +} + +void NavMeshTesterTool::drawAgent(const float* pos, float r, float h, float c, const float* col) +{ + DebugDrawGL dd; + + glDepthMask(GL_FALSE); + + // Agent dimensions. + glLineWidth(2.0f); + duDebugDrawCylinderWire(&dd, pos[0]-r, pos[1]+0.02f, pos[2]-r, pos[0]+r, pos[1]+h, pos[2]+r, col); + glLineWidth(1.0f); + + glColor4ub(0,0,0,196); + glBegin(GL_LINES); + glVertex3f(pos[0], pos[1]-c, pos[2]); + glVertex3f(pos[0], pos[1]+c, 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(); + + glDepthMask(GL_TRUE); +}