1 #ifndef BLOBS_WORLD_BODY_HPP_
2 #define BLOBS_WORLD_BODY_HPP_
5 #include "../math/geometry.hpp"
6 #include "../math/glm.hpp"
32 Body(const Body &) = delete;
33 Body &operator =(const Body &) = delete;
35 Body(Body &&) = delete;
36 Body &operator =(Body &&) = delete;
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;
44 bool HasParent() const { return parent; }
45 Body &Parent() { return *parent; }
46 const Body &Parent() const { return *parent; }
47 void SetParent(Body &);
50 const std::vector<Body *> &Children() const noexcept { return children; }
52 const std::string &Name() const noexcept { return name; }
53 void Name(const std::string &n) noexcept { name = n; }
55 double Mass() const noexcept { return mass; }
56 void Mass(double m) noexcept { mass = m; }
58 double Radius() const noexcept { return radius; }
59 void Radius(double r) noexcept { radius = r; }
61 Orbit &GetOrbit() noexcept { return orbit; }
62 const Orbit &GetOrbit() const noexcept { return orbit; }
64 const glm::dvec2 &AxialTilt() const noexcept { return axis_tilt; }
65 void AxialTilt(const glm::dvec2 &t) noexcept { axis_tilt = t; }
67 double Rotation() const noexcept { return rotation; }
68 void Rotation(double r) noexcept { rotation = r; }
70 double AngularMomentum() const noexcept { return angular; }
71 void AngularMomentum(double m) noexcept { angular = m; }
73 double Inertia() const noexcept;
75 double GravitationalParameter() const noexcept;
76 double OrbitalPeriod() const noexcept;
77 double RotationalPeriod() const noexcept;
78 /// day length relative to parent, not neccessarily a sun
79 /// gives absolute value in seconds
80 /// returns sidereal day for parent-less bodies
81 double DayLength() const noexcept;
82 double SphereOfInfluence() const noexcept;
84 math::Sphere CollisionBounds() const noexcept { return math::Sphere{ glm::dvec3(0.0), Radius() }; }
85 const glm::dmat4 &CollisionTransform() const noexcept { return local; }
87 const glm::dmat4 &LocalTransform() const noexcept { return local; }
88 const glm::dmat4 &InverseTransform() const noexcept { return inverse_local; }
90 const glm::dmat4 &ToParent() const noexcept { return inverse_orbital; }
91 const glm::dmat4 &FromParent() const noexcept { return orbital; }
93 glm::dmat4 ToUniverse() const noexcept;
94 glm::dmat4 FromUniverse() const noexcept;
96 virtual void Draw(app::Assets &, graphics::Viewport &) { }
99 void Cache() noexcept;
100 void CheckCollision() noexcept;
102 void AddCreature(creature::Creature *);
103 void RemoveCreature(creature::Creature *);
104 std::vector<creature::Creature *> &Creatures() noexcept { return creatures; }
105 const std::vector<creature::Creature *> &Creatures() const noexcept { return creatures; }
107 void Atmosphere(int a) noexcept { atmosphere = a; }
108 int Atmosphere() const noexcept { return atmosphere; }
109 bool HasAtmosphere() const noexcept { return atmosphere >= 0; }
112 void AddChild(Body &);
113 void RemoveChild(Body &);
118 std::vector<Body *> children;
123 glm::dvec2 axis_tilt;
128 glm::dmat4 inverse_orbital;
130 glm::dmat4 inverse_local;
132 std::vector<creature::Creature *> creatures;