1 #ifndef BLANK_WORLD_ENTITYCONTROLLER_HPP_
2 #define BLANK_WORLD_ENTITYCONTROLLER_HPP_
4 #include "EntityState.hpp"
13 struct EntityController {
15 virtual ~EntityController();
17 virtual void Update(Entity &, float dt) = 0;
19 virtual glm::vec3 ControlForce(const Entity &, const EntityState &) const = 0;
22 /// try to add as much of add to out so it doesn't exceed max
23 /// returns true if it's maxed out
24 static bool MaxOutForce(
29 /// give a force that makes state come to a halt over 1/n seconds
30 static inline glm::vec3 Halt(
31 const EntityState &state,
34 return state.velocity * -n;
36 /// give a force that makes state's velocity converge with given
37 /// target velocity over 1/n seconds
38 static inline glm::vec3 TargetVelocity(
39 const glm::vec3 &target,
40 const EntityState &state,
43 return (target - state.velocity) * n;
45 /// give a force that makes state go after target with an attempted
46 /// acceleration over 1/n seconds and a speed of s
47 static inline glm::vec3 Seek(
48 const EntityState &state,
49 const EntityState &target,
53 return TargetVelocity(normalize(target.Diff(state)) * s, state, n);
56 static inline glm::vec3 Flee(
57 const EntityState &state,
58 const EntityState &target,
62 return TargetVelocity(normalize(state.Diff(target)) * s, state, n);