From: Daniel Karbach Date: Fri, 15 Dec 2017 17:40:54 +0000 (+0100) Subject: real days X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=1c385fe716fda927843cdbb83805bc467f517f92;p=blobs.git real days --- 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);