Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef NavMesher_HEADER_DEFINED
- #define NavMesher_HEADER_DEFINED
- #include <d3dx9.h>
- #include "Recast/Recast.h"
- #include "Detour/DetourNavMeshQuery.h"
- #include "Detour/DetourNavMeshBuilder.h"
- /// These are just sample areas to use consistent values across the samples.
- /// The use should specify these base on his needs.
- enum SamplePolyAreas
- {
- SAMPLE_POLYAREA_GROUND,
- SAMPLE_POLYAREA_WATER,
- SAMPLE_POLYAREA_ROAD,
- SAMPLE_POLYAREA_DOOR,
- SAMPLE_POLYAREA_GRASS,
- SAMPLE_POLYAREA_JUMP,
- };
- enum SamplePolyFlags
- {
- SAMPLE_POLYFLAGS_WALK = 0x01, // Ability to walk (ground, grass, road)
- SAMPLE_POLYFLAGS_SWIM = 0x02, // Ability to swim (water).
- SAMPLE_POLYFLAGS_DOOR = 0x04, // Ability to move through doors.
- SAMPLE_POLYFLAGS_JUMP = 0x08, // Ability to jump.
- SAMPLE_POLYFLAGS_DISABLED = 0x10, // Disabled polygon
- SAMPLE_POLYFLAGS_ALL = 0xffff // All abilities.
- };
- #define MAX_PATH_NODES 256
- struct NavPath
- {
- D3DXVECTOR3 pos[MAX_PATH_NODES];
- std::size_t count;
- };
- class NavMesher
- {
- private:
- struct BuildOpts
- {
- float m_cellSize;
- float m_cellHeight;
- float m_agentHeight;
- float m_agentRadius;
- float m_agentMaxClimb;
- float m_agentMaxSlope;
- float m_regionMinSize;
- float m_regionMergeSize;
- bool m_monotonePartitioning;
- float m_edgeMaxLen;
- float m_edgeMaxError;
- float m_vertsPerPoly;
- float m_detailSampleDist;
- float m_detailSampleMaxError;
- };
- BuildOpts m_buildOpts;
- dtNavMeshQuery* m_navQuery;
- dtNavMesh* m_navMesh;
- D3DXVECTOR3 m_boundsMin;
- D3DXVECTOR3 m_boundsMax;
- LPD3DXMESH m_dxDebugMesh; // built nav mesh as dx mesh so we can see it
- LPDIRECT3DDEVICE9 m_d3d9device;
- bool extractMeshData(LPD3DXMESH dxMesh, std::vector<float>& verts, std::vector<int>& tris);
- bool buildDebugMesh(rcPolyMeshDetail* dmesh);
- public:
- NavMesher(LPDIRECT3DDEVICE9 device);
- ~NavMesher();
- bool buildNavMesh(LPD3DXMESH fromMesh);
- bool findPath(const D3DXVECTOR3& from, const D3DXVECTOR3& to, NavPath* path);
- LPD3DXMESH getDebugMesh() { return m_dxDebugMesh; }
- dtNavMesh* getNavMesh() { return m_navMesh; }
- dtNavMeshQuery* getNavQuery() { return m_navQuery; }
- const BuildOpts& getBuildOpts() { return m_buildOpts; }
- void togglePolyActiveState(float* p);
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement