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 &SurfaceTilt() const noexcept { return surface_tilt; }
65 void SurfaceTilt(const glm::dvec2 &t) noexcept { surface_tilt = t; }
67 const glm::dvec2 &AxialTilt() const noexcept { return axis_tilt; }
68 void AxialTilt(const glm::dvec2 &t) noexcept { axis_tilt = t; }
70 double Rotation() const noexcept { return rotation; }
71 void Rotation(double r) noexcept { rotation = r; }
73 double AngularMomentum() const noexcept { return angular; }
74 void AngularMomentum(double m) noexcept { angular = m; }
76 double Inertia() const noexcept;
78 double GravitationalParameter() const noexcept;
79 double OrbitalPeriod() const noexcept;
80 double RotationalPeriod() const noexcept;
81 /// day length relative to parent, not neccessarily a sun
82 /// gives absolute value in seconds
83 /// returns sidereal day for parent-less bodies
84 double DayLength() const noexcept;
85 double SphereOfInfluence() const noexcept;
87 math::Sphere CollisionBounds() const noexcept { return math::Sphere{ glm::dvec3(0.0), Radius() }; }
88 const glm::dmat4 &CollisionTransform() const noexcept { return local; }
90 const glm::dmat4 &LocalTransform() const noexcept { return local; }
91 const glm::dmat4 &InverseTransform() const noexcept { return inverse_local; }
93 const glm::dmat4 &ToParent() const noexcept { return inverse_orbital; }
94 const glm::dmat4 &FromParent() const noexcept { return orbital; }
96 glm::dmat4 ToUniverse() const noexcept;
97 glm::dmat4 FromUniverse() const noexcept;
99 virtual void Draw(app::Assets &, graphics::Viewport &) { }
101 void Tick(double dt);
102 void Cache() noexcept;
103 void CheckCollision() noexcept;
105 void AddCreature(creature::Creature *);
106 void RemoveCreature(creature::Creature *);
107 std::vector<creature::Creature *> &Creatures() noexcept { return creatures; }
108 const std::vector<creature::Creature *> &Creatures() const noexcept { return creatures; }
110 void Atmosphere(int a) noexcept { atmosphere = a; }
111 int Atmosphere() const noexcept { return atmosphere; }
112 bool HasAtmosphere() const noexcept { return atmosphere >= 0; }
115 void AddChild(Body &);
116 void RemoveChild(Body &);
121 std::vector<Body *> children;
126 glm::dvec2 surface_tilt;
127 glm::dvec2 axis_tilt;
132 glm::dmat4 inverse_orbital;
134 glm::dmat4 inverse_local;
136 std::vector<creature::Creature *> creatures;