Atoms Crowd  7.0.0
MeshAvoidanceModule.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 <AtomsUtils/Mesh.h>
12 #include <AtomsCore/Metadata/Vector3Metadata.h>
13 #include <Atoms/HeightField.h>
14 #include <unordered_map>
15 
17 {
18  VisionDistanceData(double v,
19  unsigned int s,
20  unsigned int e) :
21  value(v),
22  start(s),
23  end(e)
24  {}
25  double value;
26  unsigned int start;
27  unsigned int end;
28 
29  inline unsigned int span() const { return end - start; }
30 
31 
32 };
33 
34 
35 namespace AtomsModules
36 {
37 
39  {
40  public:
41 
43  {
44  AtomsPtr<Atoms::HeightField> heightField;
45  AtomsUtils::Mesh *mesh;
46  AtomsCore::Matrix* meshMatrixSpace;
47  AtomsCore::Matrix* meshMatrixSpaceInv;
48  AtomsCore::Vector3* upVec;
49  AtomsCore::Vector3* localDirVec;
50  AtomsCore::Vector3* pelvisPosition;
51  AtomsCore::Vector3 targetPosition;
52  AtomsCore::Rand48* randomGenerator;
53  size_t agentId;
54  double sightAngle;
55  double agentSize;
56  double distanceTmp;
57  double maxTurn;
58  double weightTmp;
59  int seed;
60  bool hasContextSteering;
61  bool behave3d;
62  };
63 
64  struct DebugData
65  {
67  AtomsCore::Vector3 target;
68  double radius;
69  bool targetEnabled;
70  };
71 
73 
75 
76  void agentsCreated(const std::vector<Atoms::Agent*>& agents, Atoms::AgentGroup* agentGroup = nullptr);
77 
78  void initSimulation(Atoms::AgentGroup* agentGroup = nullptr);
79 
80  void initFrame(const std::vector<Atoms::Agent*>& agents, Atoms::AgentGroup* agentGroup = nullptr);
81 
82  void preDraw(Atoms::DrawContext* context, const std::vector<Atoms::Agent*>& agents, Atoms::AgentGroup* agentGroup = nullptr);
83 
84  void draw(Atoms::DrawContext* context, const std::vector<Atoms::Agent*>& agents, Atoms::AgentGroup* agentGroup = nullptr);
85 
86  static Atoms::BehaviourModule* creator(const std::string& parameter);
87 
88  bool intersect(AtomsUtils::Mesh& mesh,
89  AtomsPtr<Atoms::HeightField>& heightField,
90  AtomsCore::Matrix& meshMatrixSpace,
91  AtomsCore::Matrix& meshMatrixSpaceInv,
92  AtomsCore::Vector3& position,
93  AtomsCore::Vector3& dirVec,
94  double& distance);
95 
96  bool findNewDirection(FindNewDirArgs& args);
97 
98  private:
99  std::unordered_map<std::string, double> m_agentTypeSize;
100 
101  AtomsUtils::Mesh m_mesh;
102 
103  bool m_activeDraw;
104 
105  double m_distance;
106 
107  std::vector<DebugData> m_debugData;
108  };
109 }
Agent group.
Definition: AgentGroup.h:36
Behaviour module.
Definition: BehaviourModule.h:32
Definition: DrawContext.h:17
Definition: MeshAvoidanceModule.h:39
void initSimulation(Atoms::AgentGroup *agentGroup=nullptr)
Init simulation.
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.
void draw(Atoms::DrawContext *context, const std::vector< Atoms::Agent * > &agents, Atoms::AgentGroup *agentGroup=nullptr)
Draw.
void agentsCreated(const std::vector< Atoms::Agent * > &agents, Atoms::AgentGroup *agentGroup=nullptr)
Agents Created.
Mesh class.
Definition: Mesh.h:30
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57
AtomsMath::Matrix Matrix
Matrix class.
Definition: AtomsMath.h:63
Definition: MeshAvoidanceModule.h:65
Definition: MeshAvoidanceModule.h:43
Definition: MeshAvoidanceModule.h:17