| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 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 |
|
| 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 |
|
| 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 |