Atoms Crowd  7.0.0
AgentAvoidanceModule.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 #include <Atoms/BehaviourModule.h>
11 #include <Atoms/Avoidance/RVO2.h>
12 #include <AtomsUtils/KdTreePoint.h>
13 #include <AtomsUtils/NavigationMesh/NavMesh.h>
14 #include <functional>
15 
16 
17 namespace AtomsModules
18 {
20  {
21  public:
22 
24  {
25  AtomsCore::Vector3 origDir;
26  AtomsCore::Vector3 newDir;
27  AtomsCore::Vector3 preMaxTurnAngleDir;
28  AtomsCore::Vector3 rotAxis;
29  double weight;
30  int target;
31  bool processed;
32  };
33 
34  struct DebugData
35  {
36  std::vector<AtomsCore::Vector3> obstacleNeighborsPos;
37  std::vector<AtomsCore::Vector3> neighborsPos;
39  std::vector<int> neighborsIds;
40  double radius;
41  bool valid;
42  };
43 
45 
47 
48  void initSimulation(Atoms::AgentGroup* agentGroup = nullptr);
49 
50  void initFrame(const std::vector<Atoms::Agent*>& agents, Atoms::AgentGroup* agentGroup = nullptr);
51 
52  void endFrame(const std::vector<Atoms::Agent*>& agents, Atoms::AgentGroup* agentGroup = nullptr);
53 
54  void preDraw(Atoms::DrawContext* context, const std::vector<Atoms::Agent*>& agents, Atoms::AgentGroup* agentGroup = nullptr);
55 
56  void draw(Atoms::DrawContext* context, const std::vector<Atoms::Agent*>& agents, Atoms::AgentGroup* agentGroup = nullptr);
57 
58  static Atoms::BehaviourModule* creator(const std::string& parameter);
59 #ifdef ATOMS_UNREAL
60  void registerTreeLoaderCallback(std::function<AtomsPtr<Atoms::RVO2::KdTreeObstacle>()>& callback)
61  {
62  m_obstacleTreeloaderCallback = callback;
63  }
64 #endif
65 
66  private:
67 
68  static size_t addObstacle(const std::vector<AtomsMath::Vector3f>& vertices, std::vector<Atoms::RVO2::Obstacle*>& obstacles);
69 
70  static size_t addObstacleEdge(const AtomsMath::Vector3f& a, const AtomsMath::Vector3f& b, std::vector<Atoms::RVO2::Obstacle*>& obstacles);
71 
72  std::vector<DebugData> m_debugData;
73 #ifndef ATOMS_UNREAL
74  Atoms::RVO2::KdTreeObstacle m_obstaclesTree;
75 
76  std::vector<Atoms::RVO2::Obstacle*> m_obstacles;
77 #else
78  AtomsPtr<Atoms::RVO2::KdTreeObstacle> m_obstaclesTree;
79 
80  std::vector<Atoms::RVO2::Obstacle*> m_obstacles;
81 
82  std::function<AtomsPtr<Atoms::RVO2::KdTreeObstacle>()> m_obstacleTreeloaderCallback;
83 #endif
84  Atoms::RVO2::KdTreeObstacle m_dynObstaclesTree;
85 
86  std::vector<Atoms::RVO2::Obstacle*> m_dynObstacles;
87 
88  std::vector<std::vector<AtomsMath::Vector2f>> m_dynObstaclesConvexPoly;
89 
90  float m_sceneScale;
91 
92  int m_method;
93 
94  bool m_activeDraw;
95 
96  };
97 }
Agent group.
Definition: AgentGroup.h:36
Behaviour module.
Definition: BehaviourModule.h:32
Definition: DrawContext.h:17
Definition: RVO2.h:83
Definition: AgentAvoidanceModule.h:20
void initSimulation(Atoms::AgentGroup *agentGroup=nullptr)
Init simulation.
void endFrame(const std::vector< Atoms::Agent * > &agents, Atoms::AgentGroup *agentGroup=nullptr)
End frame.
void draw(Atoms::DrawContext *context, const std::vector< Atoms::Agent * > &agents, Atoms::AgentGroup *agentGroup=nullptr)
Draw.
void preDraw(Atoms::DrawContext *context, const std::vector< Atoms::Agent * > &agents, Atoms::AgentGroup *agentGroup=nullptr)
Pre draw.
void initFrame(const std::vector< Atoms::Agent * > &agents, Atoms::AgentGroup *agentGroup=nullptr)
Init frame.
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57
Definition: AgentAvoidanceModule.h:24
Definition: AgentAvoidanceModule.h:35