Recast Navigation
Navigation-mesh Toolset for Games
CrowdTool.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 CROWDTOOL_H
20 #define CROWDTOOL_H
21 
22 #include "Sample.h"
23 #include "DetourNavMesh.h"
25 #include "ValueHistory.h"
26 #include "DetourCrowd.h"
27 
28 // Tool to create crowds.
29 
31 {
35  bool m_showPath;
36  bool m_showVO;
37  bool m_showOpt;
38  bool m_showNeis;
39 
42  bool m_showGrid;
46 
55 };
56 
58 {
59  Sample* m_sample;
60  dtNavMesh* m_nav;
61  dtCrowd* m_crowd;
62 
63  float m_targetPos[3];
64  dtPolyRef m_targetRef;
65 
66  dtCrowdAgentDebugInfo m_agentDebug;
68 
69  static const int AGENT_MAX_TRAIL = 64;
70  static const int MAX_AGENTS = 128;
71  struct AgentTrail
72  {
73  float trail[AGENT_MAX_TRAIL*3];
74  int htrail;
75  };
76  AgentTrail m_trails[MAX_AGENTS];
77 
78  ValueHistory m_crowdTotalTime;
79  ValueHistory m_crowdSampleCount;
80 
81  CrowdToolParams m_toolParams;
82 
83  bool m_run;
84 
85 public:
87  virtual ~CrowdToolState();
88 
89  virtual void init(class Sample* sample);
90  virtual void reset();
91  virtual void handleRender();
92  virtual void handleRenderOverlay(double* proj, double* model, int* view);
93  virtual void handleUpdate(const float dt);
94 
95  inline bool isRunning() const { return m_run; }
96  inline void setRunning(const bool s) { m_run = s; }
97 
98  void addAgent(const float* pos);
99  void removeAgent(const int idx);
100  void hilightAgent(const int idx);
101  void updateAgentParams();
102  int hitTestAgents(const float* s, const float* p);
103  void setMoveTarget(const float* p, bool adjust);
104  void updateTick(const float dt);
105 
106  inline CrowdToolParams* getToolParams() { return &m_toolParams; }
107 
108 private:
109  // Explicitly disabled copy constructor and copy assignment operator.
111  CrowdToolState& operator=(const CrowdToolState&);
112 };
113 
114 
115 class CrowdTool : public SampleTool
116 {
117  Sample* m_sample;
118  CrowdToolState* m_state;
119 
120  enum ToolMode
121  {
122  TOOLMODE_CREATE,
123  TOOLMODE_MOVE_TARGET,
124  TOOLMODE_SELECT,
125  TOOLMODE_TOGGLE_POLYS
126  };
127  ToolMode m_mode;
128 
129 public:
130  CrowdTool();
131 
132  virtual int type() { return TOOL_CROWD; }
133  virtual void init(Sample* sample);
134  virtual void reset();
135  virtual void handleMenu();
136  virtual void handleClick(const float* s, const float* p, bool shift);
137  virtual void handleToggle();
138  virtual void handleStep();
139  virtual void handleUpdate(const float dt);
140  virtual void handleRender();
141  virtual void handleRenderOverlay(double* proj, double* model, int* view);
142 };
143 
144 #endif // CROWDTOOL_H
@ TOOL_CROWD
Definition: Sample.h:37
Definition: CrowdTool.h:58
virtual void init(class Sample *sample)
Definition: CrowdTool.cpp:141
void setMoveTarget(const float *p, bool adjust)
Definition: CrowdTool.cpp:704
virtual void handleRender()
Definition: CrowdTool.cpp:201
void removeAgent(const int idx)
Definition: CrowdTool.cpp:680
CrowdToolState()
Definition: CrowdTool.cpp:97
int hitTestAgents(const float *s, const float *p)
Definition: CrowdTool.cpp:760
virtual void handleUpdate(const float dt)
Definition: CrowdTool.cpp:633
virtual ~CrowdToolState()
Definition: CrowdTool.cpp:136
void updateTick(const float dt)
Definition: CrowdTool.cpp:826
void setRunning(const bool s)
Definition: CrowdTool.h:96
void updateAgentParams()
Definition: CrowdTool.cpp:788
virtual void reset()
Definition: CrowdTool.cpp:197
CrowdToolParams * getToolParams()
Definition: CrowdTool.h:106
void addAgent(const float *pos)
Definition: CrowdTool.cpp:639
virtual void handleRenderOverlay(double *proj, double *model, int *view)
Definition: CrowdTool.cpp:521
void hilightAgent(const int idx)
Definition: CrowdTool.cpp:691
bool isRunning() const
Definition: CrowdTool.h:95
Definition: CrowdTool.h:116
virtual void handleRenderOverlay(double *proj, double *model, int *view)
Definition: CrowdTool.cpp:1075
virtual void handleMenu()
Definition: CrowdTool.cpp:890
virtual void handleRender()
Definition: CrowdTool.cpp:1071
virtual int type()
Definition: CrowdTool.h:132
virtual void handleClick(const float *s, const float *p, bool shift)
Definition: CrowdTool.cpp:991
virtual void handleUpdate(const float dt)
Definition: CrowdTool.cpp:1066
CrowdTool()
Definition: CrowdTool.cpp:860
virtual void init(Sample *sample)
Definition: CrowdTool.cpp:867
virtual void handleToggle()
Definition: CrowdTool.cpp:1060
virtual void reset()
Definition: CrowdTool.cpp:886
virtual void handleStep()
Definition: CrowdTool.cpp:1050
Definition: Sample.h:100
Definition: ValueHistory.h:5
Provides local steering behaviors for a group of agents.
Definition: DetourCrowd.h:204
A navigation mesh based on tiles of convex polygons.
Definition: DetourNavMesh.h:339
Definition: DetourObstacleAvoidance.h:39
unsigned int dtPolyRef
A handle to a polygon within a navigation mesh tile.
Definition: DetourNavMesh.h:48
Definition: CrowdTool.h:31
bool m_showCollisionSegments
Definition: CrowdTool.h:34
bool m_showGrid
Definition: CrowdTool.h:42
bool m_showPerfGraph
Definition: CrowdTool.h:44
bool m_expandOptions
Definition: CrowdTool.h:47
bool m_optimizeVis
Definition: CrowdTool.h:49
bool m_expandSelectedDebugDraw
Definition: CrowdTool.h:32
bool m_showVO
Definition: CrowdTool.h:36
bool m_optimizeTopo
Definition: CrowdTool.h:50
bool m_showNodes
Definition: CrowdTool.h:43
float m_separationWeight
Definition: CrowdTool.h:54
bool m_expandDebugDraw
Definition: CrowdTool.h:40
bool m_showPath
Definition: CrowdTool.h:35
bool m_separation
Definition: CrowdTool.h:53
bool m_showCorners
Definition: CrowdTool.h:33
float m_obstacleAvoidanceType
Definition: CrowdTool.h:52
bool m_showDetailAll
Definition: CrowdTool.h:45
bool m_showNeis
Definition: CrowdTool.h:38
bool m_showOpt
Definition: CrowdTool.h:37
bool m_obstacleAvoidance
Definition: CrowdTool.h:51
bool m_anticipateTurns
Definition: CrowdTool.h:48
bool m_showLabels
Definition: CrowdTool.h:41
Definition: Sample.h:90
Definition: Sample.h:76
Definition: DetourCrowd.h:195