X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2Fworld.cpp;h=525222f284b77c9c6bc57cd3a40df77849be5fd8;hb=1c385fe716fda927843cdbb83805bc467f517f92;hp=02c142ac5af08f52ecd42114bc8b6019d556bcad;hpb=ffda75aa10f772b706c2466e96a2250c89f05120;p=blobs.git diff --git a/src/world/world.cpp b/src/world/world.cpp index 02c142a..525222f 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -115,6 +115,24 @@ 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); + } else { + return std::numeric_limits::infinity(); + } +} + glm::dmat4 Body::ToUniverse() const noexcept { glm::dmat4 m(1.0); const Body *b = this; @@ -184,13 +202,13 @@ void Body::CheckCollision() noexcept { collisions.clear(); auto end = Creatures().end(); for (auto i = Creatures().begin(); i != end; ++i) { - math::AABB i_box((*i)->CollisionBox()); + math::AABB i_box((*i)->CollisionBounds()); glm::dmat4 i_mat((*i)->CollisionTransform()); for (auto j = (i + 1); j != end; ++j) { glm::dvec3 diff((*i)->GetSituation().Position() - (*j)->GetSituation().Position()); double max_dist = ((*i)->Size() + (*j)->Size()) * 1.74; if (glm::length2(diff) > max_dist * max_dist) continue; - math::AABB j_box((*j)->CollisionBox()); + math::AABB j_box((*j)->CollisionBounds()); glm::dmat4 j_mat((*j)->CollisionTransform()); glm::dvec3 normal; double depth; @@ -200,11 +218,12 @@ void Body::CheckCollision() noexcept { } } for (auto &c : collisions) { + c.A().OnCollide(c.B()); + c.B().OnCollide(c.A()); c.A().GetSituation().Move(c.Normal() * (c.Depth() * -0.5)); c.B().GetSituation().Move(c.Normal() * (c.Depth() * 0.5)); c.A().GetSituation().Accelerate(c.Normal() * -glm::dot(c.Normal(), c.AVel())); c.B().GetSituation().Accelerate(c.Normal() * -glm::dot(c.Normal(), c.BVel())); - // TODO: notify participants so they can be annoyed } } @@ -686,7 +705,9 @@ void GenerateTest(const Set &tiles, Planet &p) noexcept { Sun::Sun() -: Body() { +: Body() +, color(1.0) +, luminosity(1.0) { } Sun::~Sun() {