Debian Codegraph @

RecastDemo/Include/CrowdTool.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 CROWDTOOL_H
20 #define CROWDTOOL_H
21
22 #include "Sample.h"
23 #include "DetourNavMesh.h"
24 #include "DetourObstacleAvoidance.h"
25 #include "ValueHistory.h"
26 #include "DetourCrowd.h"
27
28 // Tool to create crowds.
29
30 struct CrowdToolParams
31 {
32 bool m_expandSelectedDebugDraw;
33 bool m_showCorners;
34 bool m_showCollisionSegments;
35 bool m_showPath;
36 bool m_showVO;
37 bool m_showOpt;
38 bool m_showNeis;
39
40 bool m_expandDebugDraw;
41 bool m_showLabels;
42 bool m_showGrid;
43 bool m_showNodes;
44 bool m_showPerfGraph;
45 bool m_showDetailAll;
46
47 bool m_expandOptions;
48 bool m_anticipateTurns;
49 bool m_optimizeVis;
50 bool m_optimizeTopo;
51 bool m_obstacleAvoidance;
52 float m_obstacleAvoidanceType;
53 bool m_separation;
54 float m_separationWeight;
55 };
56
57 class CrowdToolState : public SampleToolState
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;
67 dtObstacleAvoidanceDebugData* m_vod;
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:
86 CrowdToolState();
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.
110 CrowdToolState(const CrowdToolState&);
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