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 double SphereOfInfluence() const noexcept;
83 math::Sphere CollisionBounds() const noexcept { return math::Sphere{ glm::dvec3(0.0), Radius() }; }
84 const glm::dmat4 &CollisionTransform() const noexcept { return local; }
86 const glm::dmat4 &LocalTransform() const noexcept { return local; }
87 const glm::dmat4 &InverseTransform() const noexcept { return inverse_local; }
89 const glm::dmat4 &ToParent() const noexcept { return inverse_orbital; }
90 const glm::dmat4 &FromParent() const noexcept { return orbital; }
92 glm::dmat4 ToUniverse() const noexcept;
93 glm::dmat4 FromUniverse() const noexcept;
95 virtual void Draw(app::Assets &, graphics::Viewport &) { }
98 void Cache() noexcept;
99 void CheckCollision() noexcept;
101 void AddCreature(creature::Creature *);
102 void RemoveCreature(creature::Creature *);
103 std::vector<creature::Creature *> &Creatures() noexcept { return creatures; }
104 const std::vector<creature::Creature *> &Creatures() const noexcept { return creatures; }
106 void Atmosphere(int a) noexcept { atmosphere = a; }
107 int Atmosphere() const noexcept { return atmosphere; }
108 bool HasAtmosphere() const noexcept { return atmosphere >= 0; }
111 void AddChild(Body &);
112 void RemoveChild(Body &);
117 std::vector<Body *> children;
122 glm::dvec2 surface_tilt;
123 glm::dvec2 axis_tilt;
128 glm::dmat4 inverse_orbital;
130 glm::dmat4 inverse_local;
132 std::vector<creature::Creature *> creatures;