Debian Codegraph @

RecastDemo/Include/Sample.h

raw symbols SCIP
1 //
2 // Copyright (c) 2009-2010 Mikko Mononen [email protected]
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
19 #ifndef RECASTSAMPLE_H
20 #define RECASTSAMPLE_H
21
22 #include "Recast.h"
23 #include "SampleInterfaces.h"
24
25
26 /// Tool types.
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 /// These are just sample areas to use consistent values across the samples.
42 /// The use should specify these base on his needs.
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, // Ability to walk (ground, grass, road)
55 SAMPLE_POLYFLAGS_SWIM = 0x02, // Ability to swim (water).
56 SAMPLE_POLYFLAGS_DOOR = 0x04, // Ability to move through doors.
57 SAMPLE_POLYFLAGS_JUMP = 0x08, // Ability to jump.
58 SAMPLE_POLYFLAGS_DISABLED = 0x10, // Disabled polygon
59 SAMPLE_POLYFLAGS_ALL = 0xffff // All abilities.
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 // Explicitly disabled copy constructor and copy assignment operator.
185 Sample(const Sample&);
186 Sample& operator=(const Sample&);
187 };
188
189
190 #endif // RECASTSAMPLE_H