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