1 #ifndef BLOBS_WORLD_BODY_HPP_
2 #define BLOBS_WORLD_BODY_HPP_
5 #include "../graphics/glm.hpp"
28 Body(const Body &) = delete;
29 Body &operator =(const Body &) = delete;
31 Body(Body &&) = delete;
32 Body &operator =(Body &&) = delete;
35 bool HasSimulation() const noexcept { return sim; }
36 const Simulation &GetSimulation() const noexcept { return *sim; }
37 void SetSimulation(Simulation &) noexcept;
39 bool HasParent() const { return parent; }
40 Body &Parent() { return *parent; }
41 const Body &Parent() const { return *parent; }
42 void SetParent(Body &);
45 const std::vector<Body *> &Children() const noexcept { return children; }
47 double Mass() const noexcept { return mass; }
48 void Mass(double m) noexcept { mass = m; }
50 double Radius() const noexcept { return radius; }
51 void Radius(double r) noexcept { radius = r; }
53 Orbit &GetOrbit() noexcept { return orbit; }
54 const Orbit &GetOrbit() const noexcept { return orbit; }
56 const glm::dvec2 &SurfaceTilt() const noexcept { return surface_tilt; }
57 void SurfaceTilt(const glm::dvec2 &t) noexcept { surface_tilt = t; }
59 const glm::dvec2 &AxialTilt() const noexcept { return axis_tilt; }
60 void AxialTilt(const glm::dvec2 &t) noexcept { axis_tilt = t; }
62 double Rotation() const noexcept { return rotation; }
63 void Rotation(double r) noexcept { rotation = r; }
65 double AngularMomentum() const noexcept { return angular; }
66 void AngularMomentum(double m) noexcept { angular = m; }
68 double Inertia() const noexcept;
70 double GravitationalParameter() const noexcept;
71 double OrbitalPeriod() const noexcept;
72 double RotationalPeriod() const noexcept;
74 const glm::dmat4 &LocalTransform() const noexcept { return local; }
75 const glm::dmat4 &InverseTransform() const noexcept { return inverse_local; }
77 const glm::dmat4 &ToParent() const noexcept { return inverse_orbital; }
78 const glm::dmat4 &FromParent() const noexcept { return orbital; }
80 glm::dmat4 ToUniverse() const noexcept;
81 glm::dmat4 FromUniverse() const noexcept;
83 virtual void Draw(app::Assets &, graphics::Viewport &) { }
85 void Cache() noexcept;
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; }
93 void AddChild(Body &);
94 void RemoveChild(Body &);
99 std::vector<Body *> children;
103 glm::dvec2 surface_tilt;
104 glm::dvec2 axis_tilt;
109 glm::dmat4 inverse_orbital;
111 glm::dmat4 inverse_local;
113 std::vector<Creature *> creatures;