]> git.localhorst.tv Git - blobs.git/blob - src/world/Body.hpp
df68984915bdf8e22b375280c7df6a10f073a449
[blobs.git] / src / world / Body.hpp
1 #ifndef BLOBS_WORLD_BODY_HPP_
2 #define BLOBS_WORLD_BODY_HPP_
3
4 #include "Orbit.hpp"
5 #include "../math/glm.hpp"
6
7 #include <vector>
8
9
10 namespace blobs {
11 namespace app {
12         class Assets;
13 }
14 namespace creature {
15         class Creature;
16 }
17 namespace graphics {
18         class Viewport;
19 }
20 namespace world {
21
22 class Simulation;
23
24 class Body {
25
26 public:
27         Body();
28         ~Body();
29
30         Body(const Body &) = delete;
31         Body &operator =(const Body &) = delete;
32
33         Body(Body &&) = delete;
34         Body &operator =(Body &&) = delete;
35
36 public:
37         bool HasSimulation() const noexcept { return sim; }
38         const Simulation &GetSimulation() const noexcept { return *sim; }
39         void SetSimulation(Simulation &) noexcept;
40
41         bool HasParent() const { return parent; }
42         Body &Parent() { return *parent; }
43         const Body &Parent() const { return *parent; }
44         void SetParent(Body &);
45         void UnsetParent();
46
47         const std::vector<Body *> &Children() const noexcept { return children; }
48
49         double Mass() const noexcept { return mass; }
50         void Mass(double m) noexcept { mass = m; }
51
52         double Radius() const noexcept { return radius; }
53         void Radius(double r) noexcept { radius = r; }
54
55         Orbit &GetOrbit() noexcept { return orbit; }
56         const Orbit &GetOrbit() const noexcept { return orbit; }
57
58         const glm::dvec2 &SurfaceTilt() const noexcept { return surface_tilt; }
59         void SurfaceTilt(const glm::dvec2 &t) noexcept { surface_tilt = t; }
60
61         const glm::dvec2 &AxialTilt() const noexcept { return axis_tilt; }
62         void AxialTilt(const glm::dvec2 &t) noexcept { axis_tilt = t; }
63
64         double Rotation() const noexcept { return rotation; }
65         void Rotation(double r) noexcept { rotation = r; }
66
67         double AngularMomentum() const noexcept { return angular; }
68         void AngularMomentum(double m) noexcept { angular = m; }
69
70         double Inertia() const noexcept;
71
72         double GravitationalParameter() const noexcept;
73         double OrbitalPeriod() const noexcept;
74         double RotationalPeriod() const noexcept;
75
76         const glm::dmat4 &LocalTransform() const noexcept { return local; }
77         const glm::dmat4 &InverseTransform() const noexcept { return inverse_local; }
78
79         const glm::dmat4 &ToParent() const noexcept { return inverse_orbital; }
80         const glm::dmat4 &FromParent() const noexcept { return orbital; }
81
82         glm::dmat4 ToUniverse() const noexcept;
83         glm::dmat4 FromUniverse() const noexcept;
84
85         virtual void Draw(app::Assets &, graphics::Viewport &) { }
86
87         void Tick(double dt);
88         void Cache() noexcept;
89
90         // body takes over ownership of given pointer
91         void AddCreature(creature::Creature *);
92         void RemoveCreature(creature::Creature *);
93         std::vector<creature::Creature *> &Creatures() noexcept { return creatures; }
94         const std::vector<creature::Creature *> &Creatures() const noexcept { return creatures; }
95
96         void Atmosphere(int a) noexcept { atmosphere = a; }
97         int Atmosphere() const noexcept { return atmosphere; }
98         bool HasAtmosphere() const noexcept { return atmosphere >= 0; }
99
100 private:
101         void AddChild(Body &);
102         void RemoveChild(Body &);
103
104 private:
105         Simulation *sim;
106         Body *parent;
107         std::vector<Body *> children;
108         double mass;
109         double radius;
110         Orbit orbit;
111         glm::dvec2 surface_tilt;
112         glm::dvec2 axis_tilt;
113         double rotation;
114         double angular;
115
116         glm::dmat4 orbital;
117         glm::dmat4 inverse_orbital;
118         glm::dmat4 local;
119         glm::dmat4 inverse_local;
120
121         std::vector<creature::Creature *> creatures;
122         int atmosphere;
123
124 };
125
126 }
127 }
128
129 #endif