| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#ifndef RECASTSAMPLE_H |
| 20 |
#define RECASTSAMPLE_H |
| 21 |
|
| 22 |
#include "Recast.h" |
| 23 |
#include "SampleInterfaces.h" |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
enum SampleToolType |
| 28 |
{ |
| 29 |
TOOL_NONE = 0, |
| 30 |
TOOL_TILE_EDIT, |
| 31 |
TOOL_TILE_HIGHLIGHT, |
| 32 |
TOOL_TEMP_OBSTACLE, |
| 33 |
TOOL_NAVMESH_TESTER, |
| 34 |
TOOL_NAVMESH_PRUNE, |
| 35 |
TOOL_OFFMESH_CONNECTION, |
| 36 |
TOOL_CONVEX_VOLUME, |
| 37 |
TOOL_CROWD, |
| 38 |
MAX_TOOLS |
| 39 |
}; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
enum SamplePolyAreas |
| 44 |
{ |
| 45 |
SAMPLE_POLYAREA_GROUND, |
| 46 |
SAMPLE_POLYAREA_WATER, |
| 47 |
SAMPLE_POLYAREA_ROAD, |
| 48 |
SAMPLE_POLYAREA_DOOR, |
| 49 |
SAMPLE_POLYAREA_GRASS, |
| 50 |
SAMPLE_POLYAREA_JUMP |
| 51 |
}; |
| 52 |
enum SamplePolyFlags |
| 53 |
{ |
| 54 |
SAMPLE_POLYFLAGS_WALK = 0x01, |
| 55 |
SAMPLE_POLYFLAGS_SWIM = 0x02, |
| 56 |
SAMPLE_POLYFLAGS_DOOR = 0x04, |
| 57 |
SAMPLE_POLYFLAGS_JUMP = 0x08, |
| 58 |
SAMPLE_POLYFLAGS_DISABLED = 0x10, |
| 59 |
SAMPLE_POLYFLAGS_ALL = 0xffff |
| 60 |
}; |
| 61 |
|
| 62 |
class SampleDebugDraw : public DebugDrawGL |
| 63 |
{ |
| 64 |
public: |
| 65 |
virtual unsigned int areaToCol(unsigned int area); |
| 66 |
}; |
| 67 |
|
| 68 |
enum SamplePartitionType |
| 69 |
{ |
| 70 |
SAMPLE_PARTITION_WATERSHED, |
| 71 |
SAMPLE_PARTITION_MONOTONE, |
| 72 |
SAMPLE_PARTITION_LAYERS |
| 73 |
}; |
| 74 |
|
| 75 |
struct SampleTool |
| 76 |
{ |
| 77 |
virtual ~SampleTool(); |
| 78 |
virtual int type() = 0; |
| 79 |
virtual void init(class Sample* sample) = 0; |
| 80 |
virtual void reset() = 0; |
| 81 |
virtual void handleMenu() = 0; |
| 82 |
virtual void handleClick(const float* s, const float* p, bool shift) = 0; |
| 83 |
virtual void handleRender() = 0; |
| 84 |
virtual void handleRenderOverlay(double* proj, double* model, int* view) = 0; |
| 85 |
virtual void handleToggle() = 0; |
| 86 |
virtual void handleStep() = 0; |
| 87 |
virtual void handleUpdate(const float dt) = 0; |
| 88 |
}; |
| 89 |
|
| 90 |
struct SampleToolState { |
| 91 |
virtual ~SampleToolState(); |
| 92 |
virtual void init(class Sample* sample) = 0; |
| 93 |
virtual void reset() = 0; |
| 94 |
virtual void handleRender() = 0; |
| 95 |
virtual void handleRenderOverlay(double* proj, double* model, int* view) = 0; |
| 96 |
virtual void handleUpdate(const float dt) = 0; |
| 97 |
}; |
| 98 |
|
| 99 |
class Sample |
| 100 |
{ |
| 101 |
protected: |
| 102 |
class InputGeom* m_geom; |
| 103 |
class dtNavMesh* m_navMesh; |
| 104 |
class dtNavMeshQuery* m_navQuery; |
| 105 |
class dtCrowd* m_crowd; |
| 106 |
|
| 107 |
unsigned char m_navMeshDrawFlags; |
| 108 |
|
| 109 |
float m_cellSize; |
| 110 |
float m_cellHeight; |
| 111 |
float m_agentHeight; |
| 112 |
float m_agentRadius; |
| 113 |
float m_agentMaxClimb; |
| 114 |
float m_agentMaxSlope; |
| 115 |
float m_regionMinSize; |
| 116 |
float m_regionMergeSize; |
| 117 |
float m_edgeMaxLen; |
| 118 |
float m_edgeMaxError; |
| 119 |
float m_vertsPerPoly; |
| 120 |
float m_detailSampleDist; |
| 121 |
float m_detailSampleMaxError; |
| 122 |
int m_partitionType; |
| 123 |
|
| 124 |
bool m_filterLowHangingObstacles; |
| 125 |
bool m_filterLedgeSpans; |
| 126 |
bool m_filterWalkableLowHeightSpans; |
| 127 |
|
| 128 |
SampleTool* m_tool; |
| 129 |
SampleToolState* m_toolStates[MAX_TOOLS]; |
| 130 |
|
| 131 |
BuildContext* m_ctx; |
| 132 |
|
| 133 |
SampleDebugDraw m_dd; |
| 134 |
|
| 135 |
dtNavMesh* loadAll(const char* path); |
| 136 |
void saveAll(const char* path, const dtNavMesh* mesh); |
| 137 |
|
| 138 |
public: |
| 139 |
Sample(); |
| 140 |
virtual ~Sample(); |
| 141 |
|
| 142 |
void setContext(BuildContext* ctx) { m_ctx = ctx; } |
| 143 |
|
| 144 |
void setTool(SampleTool* tool); |
| 145 |
SampleToolState* getToolState(int type) { return m_toolStates[type]; } |
| 146 |
void setToolState(int type, SampleToolState* s) { m_toolStates[type] = s; } |
| 147 |
|
| 148 |
SampleDebugDraw& getDebugDraw() { return m_dd; } |
| 149 |
|
| 150 |
virtual void handleSettings(); |
| 151 |
virtual void handleTools(); |
| 152 |
virtual void handleDebugMode(); |
| 153 |
virtual void handleClick(const float* s, const float* p, bool shift); |
| 154 |
virtual void handleToggle(); |
| 155 |
virtual void handleStep(); |
| 156 |
virtual void handleRender(); |
| 157 |
virtual void handleRenderOverlay(double* proj, double* model, int* view); |
| 158 |
virtual void handleMeshChanged(class InputGeom* geom); |
| 159 |
virtual bool handleBuild(); |
| 160 |
virtual void handleUpdate(const float dt); |
| 161 |
virtual void collectSettings(struct BuildSettings& settings); |
| 162 |
|
| 163 |
virtual class InputGeom* getInputGeom() { return m_geom; } |
| 164 |
virtual class dtNavMesh* getNavMesh() { return m_navMesh; } |
| 165 |
virtual class dtNavMeshQuery* getNavMeshQuery() { return m_navQuery; } |
| 166 |
virtual class dtCrowd* getCrowd() { return m_crowd; } |
| 167 |
virtual float getAgentRadius() { return m_agentRadius; } |
| 168 |
virtual float getAgentHeight() { return m_agentHeight; } |
| 169 |
virtual float getAgentClimb() { return m_agentMaxClimb; } |
| 170 |
|
| 171 |
unsigned char getNavMeshDrawFlags() const { return m_navMeshDrawFlags; } |
| 172 |
void setNavMeshDrawFlags(unsigned char flags) { m_navMeshDrawFlags = flags; } |
| 173 |
|
| 174 |
void updateToolStates(const float dt); |
| 175 |
void initToolStates(Sample* sample); |
| 176 |
void resetToolStates(); |
| 177 |
void renderToolStates(); |
| 178 |
void renderOverlayToolStates(double* proj, double* model, int* view); |
| 179 |
|
| 180 |
void resetCommonSettings(); |
| 181 |
void handleCommonSettings(); |
| 182 |
|
| 183 |
private: |
| 184 |
|
| 185 |
Sample(const Sample&); |
| 186 |
Sample& operator=(const Sample&); |
| 187 |
}; |
| 188 |
|
| 189 |
|
| 190 |
#endif |