]> git.localhorst.tv Git - blank.git/blob - src/world/EntityController.hpp
3bfc10bb47b5a4118a587a7a3d8fe1908f78fb20
[blank.git] / src / world / EntityController.hpp
1 #ifndef BLANK_WORLD_ENTITYCONTROLLER_HPP_
2 #define BLANK_WORLD_ENTITYCONTROLLER_HPP_
3
4 #include "EntityState.hpp"
5
6 #include <glm/glm.hpp>
7
8
9 namespace blank {
10
11 class Entity;
12
13 struct EntityController {
14
15         virtual ~EntityController();
16
17         virtual void Update(Entity &, float dt) = 0;
18
19         virtual glm::vec3 ControlForce(const Entity &, const EntityState &) const = 0;
20
21
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(
25                 glm::vec3 &out,
26                 const glm::vec3 &add,
27                 float max
28         ) noexcept;
29         /// give a force that makes state's velocity converge with given target velocity
30         /// over 1/n seconds
31         static inline glm::vec3 TargetVelocity(
32                 const glm::vec3 &target,
33                 const EntityState &state,
34                 float n
35         ) noexcept {
36                 return (target - state.velocity) * n;
37         }
38         /// give a force that makes state come to a halt over 1/n seconds
39         static inline glm::vec3 Halt(
40                 const EntityState &state,
41                 float n
42         ) noexcept {
43                 return state.velocity * -n;
44         }
45
46 };
47
48 }
49
50 #endif