Advertisement
Guest User

NavMesher.h

a guest
Jun 25th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. #ifndef NavMesher_HEADER_DEFINED
  2. #define NavMesher_HEADER_DEFINED
  3.  
  4. #include <d3dx9.h>
  5.  
  6. #include "Recast/Recast.h"
  7. #include "Detour/DetourNavMeshQuery.h"
  8. #include "Detour/DetourNavMeshBuilder.h"
  9.  
  10. /// These are just sample areas to use consistent values across the samples.
  11. /// The use should specify these base on his needs.
  12. enum SamplePolyAreas
  13. {
  14.     SAMPLE_POLYAREA_GROUND,
  15.     SAMPLE_POLYAREA_WATER,
  16.     SAMPLE_POLYAREA_ROAD,
  17.     SAMPLE_POLYAREA_DOOR,
  18.     SAMPLE_POLYAREA_GRASS,
  19.     SAMPLE_POLYAREA_JUMP,
  20. };
  21. enum SamplePolyFlags
  22. {
  23.     SAMPLE_POLYFLAGS_WALK = 0x01,       // Ability to walk (ground, grass, road)
  24.     SAMPLE_POLYFLAGS_SWIM = 0x02,       // Ability to swim (water).
  25.     SAMPLE_POLYFLAGS_DOOR = 0x04,       // Ability to move through doors.
  26.     SAMPLE_POLYFLAGS_JUMP = 0x08,       // Ability to jump.
  27.     SAMPLE_POLYFLAGS_DISABLED = 0x10,       // Disabled polygon
  28.     SAMPLE_POLYFLAGS_ALL = 0xffff   // All abilities.
  29. };
  30.  
  31. #define MAX_PATH_NODES 256
  32.  
  33. struct NavPath
  34. {
  35.     D3DXVECTOR3 pos[MAX_PATH_NODES];
  36.     std::size_t count;
  37. };
  38.  
  39. class NavMesher
  40. {
  41. private:
  42.  
  43.     struct BuildOpts
  44.     {
  45.         float m_cellSize;
  46.         float m_cellHeight;
  47.         float m_agentHeight;
  48.         float m_agentRadius;
  49.         float m_agentMaxClimb;
  50.         float m_agentMaxSlope;
  51.         float m_regionMinSize;
  52.         float m_regionMergeSize;
  53.         bool m_monotonePartitioning;
  54.         float m_edgeMaxLen;
  55.         float m_edgeMaxError;
  56.         float m_vertsPerPoly;
  57.         float m_detailSampleDist;
  58.         float m_detailSampleMaxError;
  59.     };
  60.  
  61.     BuildOpts         m_buildOpts;
  62.     dtNavMeshQuery*   m_navQuery;
  63.     dtNavMesh*        m_navMesh;
  64.    
  65.     D3DXVECTOR3       m_boundsMin;
  66.     D3DXVECTOR3       m_boundsMax;
  67.    
  68.     LPD3DXMESH        m_dxDebugMesh; // built nav mesh as dx mesh so we can see it
  69.     LPDIRECT3DDEVICE9 m_d3d9device;
  70.  
  71.     bool extractMeshData(LPD3DXMESH dxMesh, std::vector<float>& verts, std::vector<int>& tris);
  72.     bool buildDebugMesh(rcPolyMeshDetail* dmesh);
  73.  
  74. public:
  75.  
  76.     NavMesher(LPDIRECT3DDEVICE9 device);
  77.     ~NavMesher();
  78.  
  79.     bool buildNavMesh(LPD3DXMESH fromMesh);
  80.  
  81.     bool findPath(const D3DXVECTOR3& from, const D3DXVECTOR3& to, NavPath* path);
  82.     LPD3DXMESH getDebugMesh() { return m_dxDebugMesh; }
  83.     dtNavMesh* getNavMesh() { return m_navMesh; }
  84.     dtNavMeshQuery* getNavQuery() { return m_navQuery; }
  85.     const BuildOpts& getBuildOpts() { return m_buildOpts; }
  86.     void togglePolyActiveState(float* p);
  87. };
  88.  
  89. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement