Recast Navigation
Navigation-mesh Toolset for Games
Sample.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
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 
28 {
29  TOOL_NONE = 0,
38  MAX_TOOLS
39 };
40 
44 {
51 };
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 
63 {
64 public:
65  virtual unsigned int areaToCol(unsigned int area);
66 };
67 
69 {
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 
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:
105  class dtCrowd* m_crowd;
106 
107  unsigned char m_navMeshDrawFlags;
108 
109  float m_cellSize;
123 
127 
130 
132 
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 
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
SamplePolyAreas
These are just sample areas to use consistent values across the samples.
Definition: Sample.h:44
@ SAMPLE_POLYAREA_WATER
Definition: Sample.h:46
@ SAMPLE_POLYAREA_DOOR
Definition: Sample.h:48
@ SAMPLE_POLYAREA_GRASS
Definition: Sample.h:49
@ SAMPLE_POLYAREA_JUMP
Definition: Sample.h:50
@ SAMPLE_POLYAREA_ROAD
Definition: Sample.h:47
@ SAMPLE_POLYAREA_GROUND
Definition: Sample.h:45
SamplePartitionType
Definition: Sample.h:69
@ SAMPLE_PARTITION_LAYERS
Definition: Sample.h:72
@ SAMPLE_PARTITION_WATERSHED
Definition: Sample.h:70
@ SAMPLE_PARTITION_MONOTONE
Definition: Sample.h:71
SamplePolyFlags
Definition: Sample.h:53
@ SAMPLE_POLYFLAGS_SWIM
Definition: Sample.h:55
@ SAMPLE_POLYFLAGS_JUMP
Definition: Sample.h:57
@ SAMPLE_POLYFLAGS_DISABLED
Definition: Sample.h:58
@ SAMPLE_POLYFLAGS_WALK
Definition: Sample.h:54
@ SAMPLE_POLYFLAGS_DOOR
Definition: Sample.h:56
@ SAMPLE_POLYFLAGS_ALL
Definition: Sample.h:59
SampleToolType
Tool types.
Definition: Sample.h:28
@ TOOL_CONVEX_VOLUME
Definition: Sample.h:36
@ TOOL_NAVMESH_TESTER
Definition: Sample.h:33
@ TOOL_OFFMESH_CONNECTION
Definition: Sample.h:35
@ TOOL_NAVMESH_PRUNE
Definition: Sample.h:34
@ TOOL_CROWD
Definition: Sample.h:37
@ TOOL_TILE_EDIT
Definition: Sample.h:30
@ TOOL_TEMP_OBSTACLE
Definition: Sample.h:32
@ TOOL_TILE_HIGHLIGHT
Definition: Sample.h:31
@ TOOL_NONE
Definition: Sample.h:29
@ MAX_TOOLS
Definition: Sample.h:38
Recast build context.
Definition: SampleInterfaces.h:31
OpenGL debug draw implementation.
Definition: SampleInterfaces.h:66
Definition: InputGeom.h:73
Definition: Sample.h:63
virtual unsigned int areaToCol(unsigned int area)
Compute a color for given area.
Definition: Sample.cpp:47
Definition: Sample.h:100
virtual void handleDebugMode()
Definition: Sample.cpp:114
virtual void handleClick(const float *s, const float *p, bool shift)
Definition: Sample.cpp:258
void setTool(SampleTool *tool)
Definition: Sample.cpp:98
virtual void handleSettings()
Definition: Sample.cpp:106
float m_cellSize
Definition: Sample.h:109
void setNavMeshDrawFlags(unsigned char flags)
Definition: Sample.h:172
unsigned char m_navMeshDrawFlags
Definition: Sample.h:107
virtual class dtNavMeshQuery * getNavMeshQuery()
Definition: Sample.h:165
float m_regionMergeSize
Definition: Sample.h:116
unsigned char getNavMeshDrawFlags() const
Definition: Sample.h:171
class dtNavMeshQuery * m_navQuery
Definition: Sample.h:104
BuildContext * m_ctx
Definition: Sample.h:131
SampleTool * m_tool
Definition: Sample.h:128
void resetCommonSettings()
Definition: Sample.cpp:179
void initToolStates(Sample *sample)
Definition: Sample.cpp:298
void setToolState(int type, SampleToolState *s)
Definition: Sample.h:146
virtual float getAgentRadius()
Definition: Sample.h:167
void renderOverlayToolStates(double *proj, double *model, int *view)
Definition: Sample.cpp:325
dtNavMesh * loadAll(const char *path)
Definition: Sample.cpp:351
virtual void handleMeshChanged(class InputGeom *geom)
Definition: Sample.cpp:136
Sample()
Definition: Sample.cpp:68
virtual void handleTools()
Definition: Sample.cpp:110
class InputGeom * m_geom
Definition: Sample.h:102
void saveAll(const char *path, const dtNavMesh *mesh)
Definition: Sample.cpp:421
bool m_filterLedgeSpans
Definition: Sample.h:125
bool m_filterLowHangingObstacles
Definition: Sample.h:124
float m_regionMinSize
Definition: Sample.h:115
float m_edgeMaxLen
Definition: Sample.h:117
void updateToolStates(const float dt)
Definition: Sample.cpp:289
virtual void handleStep()
Definition: Sample.cpp:270
SampleToolState * getToolState(int type)
Definition: Sample.h:145
virtual float getAgentHeight()
Definition: Sample.h:168
SampleDebugDraw & getDebugDraw()
Definition: Sample.h:148
SampleToolState * m_toolStates[MAX_TOOLS]
Definition: Sample.h:129
class dtNavMesh * m_navMesh
Definition: Sample.h:103
void setContext(BuildContext *ctx)
Definition: Sample.h:142
float m_agentMaxSlope
Definition: Sample.h:114
int m_partitionType
Definition: Sample.h:122
float m_detailSampleDist
Definition: Sample.h:120
float m_detailSampleMaxError
Definition: Sample.h:121
virtual void handleToggle()
Definition: Sample.cpp:264
float m_edgeMaxError
Definition: Sample.h:118
float m_cellHeight
Definition: Sample.h:110
virtual void handleRenderOverlay(double *proj, double *model, int *view)
Definition: Sample.cpp:132
virtual void collectSettings(struct BuildSettings &settings)
Definition: Sample.cpp:160
virtual class InputGeom * getInputGeom()
Definition: Sample.h:163
SampleDebugDraw m_dd
Definition: Sample.h:133
virtual class dtNavMesh * getNavMesh()
Definition: Sample.h:164
class dtCrowd * m_crowd
Definition: Sample.h:105
void resetToolStates()
Definition: Sample.cpp:307
void handleCommonSettings()
Definition: Sample.cpp:197
virtual void handleRender()
Definition: Sample.cpp:118
bool m_filterWalkableLowHeightSpans
Definition: Sample.h:126
float m_agentMaxClimb
Definition: Sample.h:113
virtual void handleUpdate(const float dt)
Definition: Sample.cpp:281
void renderToolStates()
Definition: Sample.cpp:316
float m_agentRadius
Definition: Sample.h:112
virtual float getAgentClimb()
Definition: Sample.h:169
virtual ~Sample()
Definition: Sample.cpp:88
virtual bool handleBuild()
Definition: Sample.cpp:276
virtual class dtCrowd * getCrowd()
Definition: Sample.h:166
float m_vertsPerPoly
Definition: Sample.h:119
float m_agentHeight
Definition: Sample.h:111
Provides local steering behaviors for a group of agents.
Definition: DetourCrowd.h:204
Provides the ability to perform pathfinding related queries against a navigation mesh.
Definition: DetourNavMeshQuery.h:166
A navigation mesh based on tiles of convex polygons.
Definition: DetourNavMesh.h:339
Definition: InputGeom.h:35
Definition: Sample.h:90
virtual ~SampleToolState()
Definition: Sample.cpp:42
virtual void handleUpdate(const float dt)=0
virtual void reset()=0
virtual void handleRenderOverlay(double *proj, double *model, int *view)=0
virtual void init(class Sample *sample)=0
virtual void handleRender()=0
Definition: Sample.h:76
virtual void handleStep()=0
virtual void handleRenderOverlay(double *proj, double *model, int *view)=0
virtual void handleMenu()=0
virtual int type()=0
virtual ~SampleTool()
Definition: Sample.cpp:37
virtual void init(class Sample *sample)=0
virtual void handleToggle()=0
virtual void reset()=0
virtual void handleClick(const float *s, const float *p, bool shift)=0
virtual void handleUpdate(const float dt)=0
virtual void handleRender()=0