Recast Navigation
Navigation-mesh Toolset for Games
Loading...
Searching...
No Matches
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#pragma once
20
21#include "SampleInterfaces.h"
22
23#include <cstdint>
24
25class Sample;
26class InputGeom;
27class dtNavMesh;
28class dtNavMeshQuery;
29class dtCrowd;
30
32enum class SampleToolType : uint8_t
33{
34 NONE = 0,
35
43 CROWD,
44
46};
47
48extern const char* toolNames[];
49
62{
63 SAMPLE_POLYFLAGS_WALK = 1 << 0, // 0x01, // Ability to walk (ground, grass, road)
64 SAMPLE_POLYFLAGS_SWIM = 1 << 1, // 0x02, // Ability to swim (water).
65 SAMPLE_POLYFLAGS_DOOR = 1 << 2, // 0x04, // Ability to move through doors.
66 SAMPLE_POLYFLAGS_JUMP = 1 << 3, // 0x08, // Ability to jump.
67 SAMPLE_POLYFLAGS_DISABLED = 1 << 4, // 0x10, // Disabled polygon
68 SAMPLE_POLYFLAGS_ALL = ~0 // 0xff // All abilities.
69};
70
71enum class SamplePartitionType : uint8_t
72{
75 LAYERS
76};
77
79{
80public:
81 unsigned int areaToCol(unsigned int area) override;
82};
83
85{
86 virtual ~SampleTool() = default;
87
88 virtual SampleToolType type() = 0;
89 virtual void init(Sample* sample) = 0;
90 virtual void reset() = 0;
91
92 virtual void singleStep() = 0;
93 virtual void update(float dt) = 0;
94 virtual void render() = 0;
95
96 virtual void drawMenuUI() = 0;
97 virtual void drawOverlayUI() = 0;
98
99 virtual void onClick(const float* rayStartPos, const float* rayHitPos, bool shift) = 0;
100 virtual void onToggle() = 0;
101};
102
104{
105 virtual ~SampleToolState() = default;
106 virtual void init(Sample* sample) = 0;
107
108 virtual void update(float dt) = 0;
109
110 virtual void reset() = 0;
111 virtual void render() = 0;
112 virtual void renderOverlay() = 0;
113};
114
116{
117public:
119 dtNavMesh* navMesh = nullptr;
121 dtCrowd* crowd = nullptr;
123
124 unsigned char navMeshDrawFlags;
125
126 float cellSize;
140
142 bool filterLedgeSpans = true;
144
145 SampleTool* tool = nullptr;
147
149
150 dtNavMesh* loadAll(const char* path);
151 void saveAll(const char* path, const dtNavMesh* mesh);
152
153 Sample();
154 virtual ~Sample();
155 Sample(const Sample&) = delete;
156 Sample(const Sample&&) = delete;
157 Sample& operator=(const Sample&) = delete;
158 Sample& operator=(const Sample&&) = delete;
159
160 void setTool(SampleTool* tool);
161
162 virtual void drawSettingsUI();
163 virtual void drawToolsUI();
164 virtual void drawDebugUI();
165
166 virtual void onClick(const float* rayStartPos, const float* rayHitPos, bool shift);
167 virtual void onToggle();
168 virtual void singleStep();
169 virtual void render();
170 virtual void renderOverlay();
171 virtual void onMeshChanged(InputGeom* geom);
172 virtual bool build();
173 virtual void update(float dt);
174 virtual void collectSettings(struct BuildSettings& settings);
175
176 void updateToolStates(float dt) const;
177 void initToolStates(Sample* sample) const;
178 void resetToolStates() const;
179 void renderToolStates() const;
180 void renderOverlayToolStates() const;
181
182 void resetCommonSettings();
184};
const char * toolNames[]
Definition Sample.cpp:29
SamplePolyAreas
These are just sample areas to use consistent values across the samples.
Definition Sample.h:53
@ SAMPLE_POLYAREA_WATER
Definition Sample.h:55
@ SAMPLE_POLYAREA_DOOR
Definition Sample.h:57
@ SAMPLE_POLYAREA_GRASS
Definition Sample.h:58
@ SAMPLE_POLYAREA_JUMP
Definition Sample.h:59
@ SAMPLE_POLYAREA_ROAD
Definition Sample.h:56
@ SAMPLE_POLYAREA_GROUND
Definition Sample.h:54
SamplePolyFlags
Definition Sample.h:62
@ SAMPLE_POLYFLAGS_SWIM
Definition Sample.h:64
@ SAMPLE_POLYFLAGS_JUMP
Definition Sample.h:66
@ SAMPLE_POLYFLAGS_DISABLED
Definition Sample.h:67
@ SAMPLE_POLYFLAGS_WALK
Definition Sample.h:63
@ SAMPLE_POLYFLAGS_DOOR
Definition Sample.h:65
@ SAMPLE_POLYFLAGS_ALL
Definition Sample.h:68
SampleToolType
Tool types.
Definition Sample.h:33
SamplePartitionType
Definition Sample.h:72
Recast build context.
Definition SampleInterfaces.h:34
OpenGL debug draw implementation.
Definition SampleInterfaces.h:61
Definition InputGeom.h:96
Definition Sample.h:79
unsigned int areaToCol(unsigned int area) override
Compute a color for given area.
Definition Sample.cpp:63
Definition Sample.h:116
bool filterLowHangingObstacles
Definition Sample.h:141
Sample(const Sample &)=delete
void setTool(SampleTool *tool)
Definition Sample.cpp:110
float agentMaxSlope
Definition Sample.h:131
Sample & operator=(const Sample &)=delete
float detailSampleDist
Definition Sample.h:137
virtual void onToggle()
Definition Sample.cpp:283
SampleTool * tool
Definition Sample.h:145
virtual void renderOverlay()
Definition Sample.cpp:156
void updateToolStates(float dt) const
Definition Sample.cpp:313
virtual void onMeshChanged(InputGeom *geom)
Definition Sample.cpp:158
float regionMergeSize
Definition Sample.h:133
void resetCommonSettings()
Definition Sample.cpp:197
bool filterWalkableLowHeightSpans
Definition Sample.h:143
dtNavMesh * loadAll(const char *path)
Definition Sample.cpp:368
void resetToolStates() const
Definition Sample.cpp:335
Sample()
Definition Sample.cpp:91
SamplePartitionType partitionType
Definition Sample.h:139
virtual void update(float dt)
Definition Sample.cpp:304
InputGeom * inputGeometry
Definition Sample.h:118
float agentMaxClimb
Definition Sample.h:130
void saveAll(const char *path, const dtNavMesh *mesh)
Definition Sample.cpp:446
float cellHeight
Definition Sample.h:127
float cellSize
Definition Sample.h:126
dtCrowd * crowd
Definition Sample.h:121
void initToolStates(Sample *sample) const
Definition Sample.cpp:324
void renderToolStates() const
Definition Sample.cpp:346
Sample(const Sample &&)=delete
virtual void drawToolsUI()
Definition Sample.cpp:122
virtual bool build()
Definition Sample.cpp:299
int vertsPerPoly
Definition Sample.h:136
float agentRadius
Definition Sample.h:129
float detailSampleMaxError
Definition Sample.h:138
Sample & operator=(const Sample &&)=delete
void drawCommonSettingsUI()
Definition Sample.cpp:215
dtNavMesh * navMesh
Definition Sample.h:119
virtual void singleStep()
Definition Sample.cpp:291
float edgeMaxLen
Definition Sample.h:134
virtual void collectSettings(struct BuildSettings &settings)
Definition Sample.cpp:180
bool filterLedgeSpans
Definition Sample.h:142
virtual void drawSettingsUI()
Definition Sample.cpp:120
dtNavMeshQuery * navQuery
Definition Sample.h:120
float regionMinSize
Definition Sample.h:132
virtual void render()
Definition Sample.cpp:126
float agentHeight
Definition Sample.h:128
float edgeMaxError
Definition Sample.h:135
virtual void onClick(const float *rayStartPos, const float *rayHitPos, bool shift)
Definition Sample.cpp:275
void renderOverlayToolStates() const
Definition Sample.cpp:357
SampleDebugDraw debugDraw
Definition Sample.h:122
virtual ~Sample()
Definition Sample.cpp:98
virtual void drawDebugUI()
Definition Sample.cpp:124
SampleToolState * toolStates[static_cast< size_t >(SampleToolType::MAX_TOOLS)]
Definition Sample.h:146
BuildContext * buildContext
Definition Sample.h:148
unsigned char navMeshDrawFlags
Definition Sample.h:124
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:336
Definition InputGeom.h:41
Definition Sample.h:104
virtual ~SampleToolState()=default
virtual void init(Sample *sample)=0
virtual void update(float dt)=0
virtual void reset()=0
virtual void render()=0
virtual void renderOverlay()=0
Definition Sample.h:85
virtual void onClick(const float *rayStartPos, const float *rayHitPos, bool shift)=0
virtual void singleStep()=0
virtual void update(float dt)=0
virtual void onToggle()=0
virtual void drawOverlayUI()=0
virtual ~SampleTool()=default
virtual void init(Sample *sample)=0
virtual void drawMenuUI()=0
virtual void reset()=0
virtual void render()=0
virtual SampleToolType type()=0