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