CRecastHelper.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include <map>
  3. #include "../../../../Detour/Include/DetourNavMesh.h"
  4. #include "../../../../Detour/Include/DetourNavMeshQuery.h"
  5. static const int MAX_POLYS = 256;
  6. static const int MAX_SMOOTH = 2048;
  7. class CRecast
  8. {
  9. dtNavMesh* m_navMesh;
  10. dtNavMeshQuery* m_navQuery;
  11. float m_spos[3];
  12. float m_epos[3];
  13. dtPolyRef m_startRef, m_endRef;
  14. float m_polyPickExt[3] = { 2,40,2 };
  15. dtQueryFilter m_filter;
  16. dtPolyRef m_polys[MAX_POLYS];
  17. int m_npolys = 0;
  18. float m_smoothPath[MAX_SMOOTH * 3];
  19. int m_nsmoothPath;
  20. float m_fixPos[3];
  21. float m_hitPos[3];
  22. public:
  23. CRecast();
  24. bool LoadMap(const char* path);
  25. void FreeMap();
  26. dtStatus FindPath(const float* spos, const float* epos);
  27. dtStatus Raycast(const float* spos, const float* epos);
  28. // stepSize : 如果给0,会自动变成0.5f
  29. // slop : 如果给0,会自动变成0.01f
  30. void Smooth(float STEP_SIZE, float SLOP);
  31. int GetCountPoly() { return m_npolys; }
  32. int GetCountSmooth() { return m_nsmoothPath; }
  33. dtPolyRef* GetPathPoly(int* polyCount) { *polyCount = m_npolys; return m_polys; }
  34. float* GetPathSmooth(int* smoothCount) { *smoothCount = m_nsmoothPath; return m_smoothPath; }
  35. float* fixPosition(const float* pos);
  36. float* GetHitPosition() { return m_hitPos; }
  37. };
  38. class CRecastHelper
  39. {
  40. std::map<int, CRecast*> m_mapRecast;
  41. public:
  42. CRecastHelper() {}
  43. ~CRecastHelper();
  44. CRecast* Get(int id) { return m_mapRecast[id]; }
  45. bool LoadMap(int id, const char* path);
  46. void FreeMap(int id);
  47. };