]> git.localhorst.tv Git - blobs.git/blob - src/creature/Situation.hpp
face direction
[blobs.git] / src / creature / Situation.hpp
1 #ifndef BLOBS_CREATURE_SITUATION_HPP_
2 #define BLOBS_CREATURE_SITUATION_HPP_
3
4 #include "../math/glm.hpp"
5
6
7 namespace blobs {
8 namespace world {
9         class Planet;
10         class Tile;
11         class TileType;
12 }
13 namespace creature {
14
15 class Situation {
16
17 public:
18         struct State {
19                 // position
20                 glm::dvec3 pos;
21                 // velocity
22                 glm::dvec3 vel;
23                 // face direction, normalized
24                 glm::dvec3 dir;
25                 State(
26                         const glm::dvec3 &pos = glm::dvec3(0.0),
27                         const glm::dvec3 &vel = glm::dvec3(0.0),
28                         const glm::dvec3 &dir = glm::dvec3(0.0, 0.0, -1.0))
29                 : pos(pos), vel(vel), dir(dir) { }
30         };
31         struct Derivative {
32                 // velocity
33                 glm::dvec3 vel;
34                 // acceleration
35                 glm::dvec3 acc;
36                 // orientation adjust
37                 glm::dvec3 turn;
38                 Derivative(
39                         const glm::dvec3 &vel = glm::dvec3(0.0),
40                         const glm::dvec3 &acc = glm::dvec3(0.0),
41                         const glm::dvec3 &turn = glm::dvec3(0.0))
42                 : vel(vel), acc(acc), turn(turn) { }
43         };
44
45 public:
46         Situation();
47         ~Situation();
48
49         Situation(const Situation &) = delete;
50         Situation &operator =(const Situation &) = delete;
51
52         Situation(Situation &&) = delete;
53         Situation &operator =(Situation &&) = delete;
54
55 public:
56         bool OnPlanet() const noexcept;
57         world::Planet &GetPlanet() const noexcept { return *planet; }
58         bool OnSurface() const noexcept;
59         int Surface() const noexcept { return surface; }
60         const glm::dvec3 &Position() const noexcept { return state.pos; }
61         bool OnTile() const noexcept;
62         glm::ivec2 SurfacePosition() const noexcept;
63         world::Tile &GetTile() const noexcept;
64         const world::TileType &GetTileType() const noexcept;
65
66         void SetState(const State &s) noexcept { state = s; }
67         const State &GetState() const noexcept { return state; }
68
69         const glm::dvec3 &Velocity() const noexcept { return state.vel; }
70         bool Moving() const noexcept { return glm::length2(state.vel) < 0.00000001; }
71         void Move(const glm::dvec3 &dp) noexcept;
72
73         const glm::dvec3 &Heading() const noexcept { return state.dir; }
74
75         void SetPlanetSurface(world::Planet &, int srf, const glm::dvec3 &pos) noexcept;
76
77 public:
78         world::Planet *planet;
79         State state;
80         int surface;
81         enum {
82                 LOST,
83                 PLANET_SURFACE,
84         } type;
85
86 };
87
88 }
89 }
90
91 #endif