]> git.localhorst.tv Git - blobs.git/blob - src/world/Body.hpp
half-assed implementation of "other" body rendering
[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 "../graphics/glm.hpp"
6
7 #include <vector>
8
9
10 namespace blobs {
11 namespace app {
12         class Assets;
13 }
14 namespace graphics {
15         class Viewport;
16 }
17 namespace world {
18
19 class Simulation;
20
21 class Body {
22
23 public:
24         Body();
25         ~Body();
26
27         Body(const Body &) = delete;
28         Body &operator =(const Body &) = delete;
29
30         Body(Body &&) = delete;
31         Body &operator =(Body &&) = delete;
32
33 public:
34         bool HasSimulation() const noexcept { return sim; }
35         const Simulation &GetSimulation() const noexcept { return *sim; }
36         void SetSimulation(Simulation &) noexcept;
37
38         bool HasParent() const { return parent; }
39         Body &Parent() { return *parent; }
40         const Body &Parent() const { return *parent; }
41         void SetParent(Body &);
42         void UnsetParent();
43
44         const std::vector<Body *> &Children() const noexcept { return children; }
45
46         double Mass() const noexcept { return mass; }
47         void Mass(double m) noexcept { mass = m; }
48
49         double Radius() const noexcept { return radius; }
50         void Radius(double r) noexcept { radius = r; }
51
52         Orbit &GetOrbit() noexcept { return orbit; }
53         const Orbit &GetOrbit() const noexcept { return orbit; }
54
55         const glm::dvec2 &SurfaceTilt() const noexcept { return surface_tilt; }
56         void SurfaceTilt(const glm::dvec2 &t) noexcept { surface_tilt = t; }
57
58         const glm::dvec2 &AxialTilt() const noexcept { return axis_tilt; }
59         void AxialTilt(const glm::dvec2 &t) noexcept { axis_tilt = t; }
60
61         double Rotation() const noexcept { return rotation; }
62         void Rotation(double r) noexcept { rotation = r; }
63
64         double AngularMomentum() const noexcept { return angular; }
65         void AngularMomentum(double m) noexcept { angular = m; }
66
67         double Inertia() const noexcept;
68
69         double GravitationalParameter() const noexcept;
70         double OrbitalPeriod() const noexcept;
71         double RotationalPeriod() const noexcept;
72
73         const glm::dmat4 &LocalTransform() const noexcept { return local; }
74         const glm::dmat4 &InverseTransform() const noexcept { return inverse_local; }
75
76         const glm::dmat4 &ToParent() const noexcept { return inverse_orbital; }
77         const glm::dmat4 &FromParent() const noexcept { return orbital; }
78
79         glm::dmat4 ToUniverse() const noexcept;
80         glm::dmat4 FromUniverse() const noexcept;
81
82         virtual void Draw(app::Assets &, graphics::Viewport &) { }
83
84         void Cache() noexcept;
85
86 private:
87         void AddChild(Body &);
88         void RemoveChild(Body &);
89
90 private:
91         Simulation *sim;
92         Body *parent;
93         std::vector<Body *> children;
94         double mass;
95         double radius;
96         Orbit orbit;
97         glm::dvec2 surface_tilt;
98         glm::dvec2 axis_tilt;
99         double rotation;
100         double angular;
101
102         glm::dmat4 orbital;
103         glm::dmat4 inverse_orbital;
104         glm::dmat4 local;
105         glm::dmat4 inverse_local;
106
107 };
108
109 }
110 }
111
112 #endif