SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
TargetFlee.h
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include "Steering.h"
7 
8 namespace ai {
9 namespace movement {
10 
14 class TargetFlee: public ISteering {
15 protected:
16  glm::vec3 _target;
17 public:
18  STEERING_FACTORY(TargetFlee)
19 
20  explicit TargetFlee(const std::string& parameters) :
21  ISteering() {
22  _target = parse(parameters);
23  }
24 
25  inline bool isValid () const {
26  return !isInfinite(_target);
27  }
28 
29  virtual MoveVector execute (const AIPtr& ai, float speed) const override {
30  if (!isValid()) {
31  return MoveVector(_target, 0.0f);
32  }
33  const glm::vec3& v = glm::normalize(ai->getCharacter()->getPosition() - _target);
34  const float orientation = angle(v);
35  const MoveVector d(v * speed, orientation);
36  return d;
37  }
38 };
39 
40 
41 }
42 }
Definition: MoveVector.h:10
Flees from a particular target.
Definition: TargetFlee.h:14
virtual MoveVector execute(const AIPtr &ai, float speed) const override
Calculates the MoveVector.
Definition: TargetFlee.h:29
Defines some basic movement algorithms like Wandering, Seeking and Fleeing.
Steering interface.
Definition: Steering.h:47