SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
TargetSeek.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 TargetSeek: public ISteering {
15 protected:
16  glm::vec3 _target;
17 public:
18  STEERING_FACTORY(TargetSeek)
19 
20  explicit TargetSeek(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(_target - ai->getCharacter()->getPosition());
34  const float orientation = angle(v);
35  const MoveVector d(v * speed, orientation);
36  return d;
37  }
38 };
39 
40 }
41 }
Definition: MoveVector.h:10
virtual MoveVector execute(const AIPtr &ai, float speed) const override
Calculates the MoveVector.
Definition: TargetSeek.h:29
Defines some basic movement algorithms like Wandering, Seeking and Fleeing.
Steering interface.
Definition: Steering.h:47
Seeks a particular target.
Definition: TargetSeek.h:14