From 1c385fe716fda927843cdbb83805bc467f517f92 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Fri, 15 Dec 2017 18:40:54 +0100 Subject: [PATCH] real days --- src/ui/ui.cpp | 2 +- src/world/Body.hpp | 4 ++++ src/world/world.cpp | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index c361df5..05fd499 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -546,7 +546,7 @@ void TimePanel::Draw(graphics::Viewport &viewport) noexcept { live->Text(NumberString(sim.LiveCreatures().size())); time->Text(TimeString(sim.Time())); if (body) { - clock->Text(TimeString(std::fmod(sim.Time(), body->RotationalPeriod()))); + clock->Text(TimeString(std::fmod(sim.Time(), body->DayLength())) + " / " + TimeString(body->DayLength())); } else { clock->Text("no reference"); } diff --git a/src/world/Body.hpp b/src/world/Body.hpp index d908065..6f85efd 100644 --- a/src/world/Body.hpp +++ b/src/world/Body.hpp @@ -78,6 +78,10 @@ public: double GravitationalParameter() const noexcept; double OrbitalPeriod() const noexcept; double RotationalPeriod() const noexcept; + /// day length relative to parent, not neccessarily a sun + /// gives absolute value in seconds + /// returns sidereal day for parent-less bodies + double DayLength() const noexcept; double SphereOfInfluence() const noexcept; math::Sphere CollisionBounds() const noexcept { return math::Sphere{ glm::dvec3(0.0), Radius() }; } diff --git a/src/world/world.cpp b/src/world/world.cpp index 1758c5e..525222f 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -115,6 +115,16 @@ double Body::RotationalPeriod() const noexcept { } } +double Body::DayLength() const noexcept { + if (!HasParent()) { + return RotationalPeriod(); + } + double year = OrbitalPeriod(); + double sidereal = RotationalPeriod(); + double grade = (angular < 0.0 ? -1.0 : 1.0) * (std::abs(axis_tilt.x) > PI * 0.5 ? -1.0 : 1.0); + return std::abs((year * sidereal) / ( year + (grade * sidereal))); +} + double Body::SphereOfInfluence() const noexcept { if (HasParent()) { return orbit.SemiMajorAxis() * std::pow(Mass() / Parent().Mass(), 2.0 / 5.0); -- 2.39.2