NavMeshTesterTool.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
  3. //
  4. // This software is provided 'as-is', without any express or implied
  5. // warranty. In no event will the authors be held liable for any damages
  6. // arising from the use of this software.
  7. // Permission is granted to anyone to use this software for any purpose,
  8. // including commercial applications, and to alter it and redistribute it
  9. // freely, subject to the following restrictions:
  10. // 1. The origin of this software must not be misrepresented; you must not
  11. // claim that you wrote the original software. If you use this software
  12. // in a product, an acknowledgment in the product documentation would be
  13. // appreciated but is not required.
  14. // 2. Altered source versions must be plainly marked as such, and must not be
  15. // misrepresented as being the original software.
  16. // 3. This notice may not be removed or altered from any source distribution.
  17. //
  18. #ifndef NAVMESHTESTERTOOL_H
  19. #define NAVMESHTESTERTOOL_H
  20. #include "Sample.h"
  21. #include "DetourNavMesh.h"
  22. #include "DetourNavMeshQuery.h"
  23. class NavMeshTesterTool : public SampleTool
  24. {
  25. Sample* m_sample;
  26. dtNavMesh* m_navMesh;
  27. dtNavMeshQuery* m_navQuery;
  28. dtQueryFilter m_filter;
  29. dtStatus m_pathFindStatus;
  30. enum ToolMode
  31. {
  32. TOOLMODE_PATHFIND_FOLLOW,
  33. TOOLMODE_PATHFIND_STRAIGHT,
  34. TOOLMODE_PATHFIND_SLICED,
  35. TOOLMODE_RAYCAST,
  36. TOOLMODE_DISTANCE_TO_WALL,
  37. TOOLMODE_FIND_POLYS_IN_CIRCLE,
  38. TOOLMODE_FIND_POLYS_IN_SHAPE,
  39. TOOLMODE_FIND_LOCAL_NEIGHBOURHOOD,
  40. };
  41. ToolMode m_toolMode;
  42. int m_straightPathOptions;
  43. static const int MAX_POLYS = 256;
  44. static const int MAX_SMOOTH = 2048;
  45. dtPolyRef m_startRef;
  46. dtPolyRef m_endRef;
  47. dtPolyRef m_polys[MAX_POLYS];
  48. dtPolyRef m_parent[MAX_POLYS];
  49. int m_npolys;
  50. float m_straightPath[MAX_POLYS*3];
  51. unsigned char m_straightPathFlags[MAX_POLYS];
  52. dtPolyRef m_straightPathPolys[MAX_POLYS];
  53. int m_nstraightPath;
  54. float m_polyPickExt[3];
  55. float m_smoothPath[MAX_SMOOTH*3];
  56. int m_nsmoothPath;
  57. float m_queryPoly[4*3];
  58. static const int MAX_RAND_POINTS = 64;
  59. float m_randPoints[MAX_RAND_POINTS*3];
  60. int m_nrandPoints;
  61. bool m_randPointsInCircle;
  62. float m_spos[3];
  63. float m_epos[3];
  64. float m_hitPos[3];
  65. float m_hitNormal[3];
  66. bool m_hitResult;
  67. float m_distanceToWall;
  68. float m_neighbourhoodRadius;
  69. float m_randomRadius;
  70. bool m_sposSet;
  71. bool m_eposSet;
  72. int m_pathIterNum;
  73. dtPolyRef m_pathIterPolys[MAX_POLYS];
  74. int m_pathIterPolyCount;
  75. float m_prevIterPos[3], m_iterPos[3], m_steerPos[3], m_targetPos[3];
  76. static const int MAX_STEER_POINTS = 10;
  77. float m_steerPoints[MAX_STEER_POINTS*3];
  78. int m_steerPointCount;
  79. public:
  80. NavMeshTesterTool();
  81. virtual int type() { return TOOL_NAVMESH_TESTER; }
  82. virtual void init(Sample* sample);
  83. virtual void reset();
  84. virtual void handleMenu();
  85. virtual void handleClick(const float* s, const float* p, bool shift);
  86. virtual void handleToggle();
  87. virtual void handleStep();
  88. virtual void handleUpdate(const float dt);
  89. virtual void handleRender();
  90. virtual void handleRenderOverlay(double* proj, double* model, int* view);
  91. void recalc();
  92. void drawAgent(const float* pos, float r, float h, float c, const unsigned int col);
  93. };
  94. #endif // NAVMESHTESTERTOOL_H