X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FBody.hpp;h=5f82be232b4dc3e78029fd27338b122ab4a41421;hb=98770f59a02c76f02de0a46ed36d9cfd52f5071b;hp=e3fd8ded17d2684befa5436fa76891b2c6ab3099;hpb=be413456f57da06e918ae7bf4c4f35e5198ff7ce;p=blobs.git diff --git a/src/world/Body.hpp b/src/world/Body.hpp index e3fd8de..5f82be2 100644 --- a/src/world/Body.hpp +++ b/src/world/Body.hpp @@ -1,6 +1,9 @@ #ifndef BLOBS_WORLD_BODY_HPP_ #define BLOBS_WORLD_BODY_HPP_ +#include "Orbit.hpp" +#include "../graphics/glm.hpp" + #include @@ -13,6 +16,8 @@ namespace graphics { } namespace world { +class Simulation; + class Body { public: @@ -26,23 +31,78 @@ public: Body &operator =(Body &&) = delete; public: + bool HasSimulation() const noexcept { return sim; } + const Simulation &GetSimulation() const noexcept { return *sim; } + void SetSimulation(Simulation &) noexcept; + bool HasParent() const { return parent; } Body &Parent() { return *parent; } const Body &Parent() const { return *parent; } void SetParent(Body &); void UnsetParent(); + const std::vector &Children() const noexcept { return children; } + + double Mass() const noexcept { return mass; } + void Mass(double m) noexcept { mass = m; } + + double Radius() const noexcept { return radius; } + void Radius(double r) noexcept { radius = r; } + + Orbit &GetOrbit() noexcept { return orbit; } + const Orbit &GetOrbit() const noexcept { return orbit; } + + const glm::dvec2 &SurfaceTilt() const noexcept { return surface_tilt; } + void SurfaceTilt(const glm::dvec2 &t) noexcept { surface_tilt = t; } + + const glm::dvec2 &AxialTilt() const noexcept { return axis_tilt; } + void AxialTilt(const glm::dvec2 &t) noexcept { axis_tilt = t; } + + double Rotation() const noexcept { return rotation; } + void Rotation(double r) noexcept { rotation = r; } + + double AngularMomentum() const noexcept { return angular; } + void AngularMomentum(double m) noexcept { angular = m; } + + double Inertia() const noexcept; + + double GravitationalParameter() const noexcept; + double OrbitalPeriod() const noexcept; + double RotationalPeriod() const noexcept; + + const glm::dmat4 &LocalTransform() const noexcept { return local; } + const glm::dmat4 &InverseTransform() const noexcept { return inverse_local; } + + const glm::dmat4 &ToParent() const noexcept { return inverse_orbital; } + const glm::dmat4 &FromParent() const noexcept { return orbital; } + + glm::dmat4 ToUniverse() const noexcept; + glm::dmat4 FromUniverse() const noexcept; + virtual void Draw(app::Assets &, graphics::Viewport &) { } + void Cache() noexcept; + private: void AddChild(Body &); void RemoveChild(Body &); private: + Simulation *sim; Body *parent; std::vector children; double mass; double radius; + Orbit orbit; + glm::dvec2 surface_tilt; + glm::dvec2 axis_tilt; + double rotation; + double angular; + + glm::dmat4 orbital; + glm::dmat4 inverse_orbital; + glm::dmat4 local; + glm::dmat4 inverse_local; };