Steeriously  0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Pages
FlockingComponent.hpp
1 #ifndef FlockingComponent_HPP
2 #define FlockingComponent_HPP
3 
4 #include <steeriously/Agent.hpp>
5 #include <steeriously/SphereObstacle.hpp>
6 #include <steeriously/Wall.hpp>
7 
8 namespace steer
9 {
17  {
18  public:
20  virtual ~FlockingComponent();
21 
22  void setParams(steer::BehaviorParameters* params) { m_params = params; };
23  steer::BehaviorParameters* getParams() { return m_params; };
24 
25  void Update(float dt);
26 
31  float getRotation() { return m_rotation; };
32 
33  void setNeighbors(std::vector<FlockingComponent*>* n) { m_neighbors = n; };
34  std::vector<FlockingComponent*>* getNeighbors() { return m_neighbors; };
35 
36  void setObstacles(std::vector<SphereObstacle*>* o) { m_obstacles = o; };
37  std::vector<SphereObstacle*>* getObstacles() { return m_obstacles; };
38 
39  void setWalls(std::vector<Wall*>* w) { m_walls = w; };
40  std::vector<Wall*>* getWalls() { return m_walls; };
41 
42  //pure virtual - must implement see Agent.hpp
43  virtual bool on(steer::behaviorType behavior) override { return (m_iFlags & behavior) == behavior; };
44 
45  void alignmentOn() { m_iFlags |= steer::behaviorType::alignment; };
46  void separationOn() { m_iFlags |= steer::behaviorType::separation; };
47  void cohesionOn() { m_iFlags |= steer::behaviorType::cohesion; };
48  void seekOn() { m_iFlags |= steer::behaviorType::seek; };
49  void wanderOn() { m_iFlags |= steer::behaviorType::wander; };
50  void wallAvoidanceOn() { m_iFlags |= steer::behaviorType::wallAvoidance; };
51  void obstacleAvoidanceOn() { m_iFlags |= steer::behaviorType::obstacleAvoidance; };
52 
53  void cohesionOff() { if (on(steer::behaviorType::cohesion)) m_iFlags ^= steer::behaviorType::cohesion; };
54  void separationOff() { if (on(steer::behaviorType::separation)) m_iFlags ^= steer::behaviorType::separation; };
55  void alignmentOff() { if (on(steer::behaviorType::alignment)) m_iFlags ^= steer::behaviorType::alignment; };
56  void seekOff() { if (on(steer::behaviorType::seek)) m_iFlags ^= steer::behaviorType::seek; };
57  void wanderOff() { if (on(steer::behaviorType::wander)) m_iFlags ^= steer::behaviorType::wander; };
58  void wallAvoidanceOff() { if (on(steer::behaviorType::wallAvoidance)) m_iFlags ^= steer::behaviorType::wallAvoidance; };
59  void obstacleAvoidanceOff() { if (on(steer::behaviorType::obstacleAvoidance)) m_iFlags ^= steer::behaviorType::obstacleAvoidance; };
60 
61  bool isCohesionOn() { return on(steer::behaviorType::cohesion); };
62  bool isSeparationOn() { return on(steer::behaviorType::separation); };
63  bool isAlignmentOn() { return on(steer::behaviorType::alignment); };
64  bool isSeekOn() { return on(steer::behaviorType::seek); };
65  bool isWanderOn() { return on(steer::behaviorType::wander); };
66  bool isWallAvoidanceOn() { return on(steer::behaviorType::wallAvoidance); };
67  bool isObstacleAvoidanceOn() { return on(steer::behaviorType::obstacleAvoidance); };
68  bool isFlockingOn() { return isCohesionOn() && isAlignmentOn() && isSeparationOn() && isSeekOn() && isWanderOn() && isWallAvoidanceOn() && isObstacleAvoidanceOn(); };
69 
70  void flockingOn()
71  {
72  cohesionOn();
73  alignmentOn();
74  separationOn();
75  seekOn();
76  wanderOn();
77  wallAvoidanceOn();
78  obstacleAvoidanceOn();
79  };
80 
81  void flockingOff()
82  {
83  cohesionOff();
84  alignmentOff();
85  separationOff();
86  seekOff();
87  wanderOff();
88  wallAvoidanceOff();
89  obstacleAvoidanceOff();
90  }
91 
92  bool targetAcquired();
93 
94  //pure virtual - must implement see Agent.hpp
95  virtual Vector2 Calculate() override;
96 
97  //optional virtual
98  virtual Vector2 calculateWeightedSum() override;
99 
100  private:
101  float m_weightSeek;
102  float m_weightWander;
103  float m_weightAlignment;
104  float m_weightSeparation;
105  float m_weightCohesion;
106  float m_weightObstacleAvoidance;
107  float m_weightWallAvoidance;
108  Uint32 m_iFlags;
109  float m_rotation;
110  std::vector<FlockingComponent*>* m_neighbors;
111  std::vector<SphereObstacle*>* m_obstacles;
112  std::vector<Wall*>* m_walls;
113  steer::BehaviorParameters* m_params;
114  };
115 }
116 
117 #endif // FlockingComponent_HPP