X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2Fworld.cpp;h=1758c5e431ea4ebfb862dde58b4290408b5dd0e5;hb=cead4f0686af352cdbac1f2c2df9b6a21ad9faec;hp=682eb9bb3763b8019da31fd206cb4a5bb483aeed;hpb=0e061ce526fe46dd3e894223e5d646eb2e30f826;p=blobs.git diff --git a/src/world/world.cpp b/src/world/world.cpp index 682eb9b..1758c5e 100644 --- a/src/world/world.cpp +++ b/src/world/world.cpp @@ -115,6 +115,14 @@ double Body::RotationalPeriod() const noexcept { } } +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 +192,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 +208,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 } } @@ -476,18 +485,18 @@ void Planet::BuildVAO(const Set &ts) { for (int index = 0, surface = 0; surface < 6; ++surface) { for (int y = 0; y < sidelength; ++y) { for (int x = 0; x < sidelength; ++x, ++index) { - glm::vec3 pos[5]; - pos[0][(surface + 0) % 3] = x + 0 - offset; - pos[0][(surface + 1) % 3] = y + 0 - offset; + glm::vec3 pos[4]; + pos[0][(surface + 0) % 3] = float(x + 0) - offset; + pos[0][(surface + 1) % 3] = float(y + 0) - offset; pos[0][(surface + 2) % 3] = offset; - pos[1][(surface + 0) % 3] = x + 0 - offset; - pos[1][(surface + 1) % 3] = y + 1 - offset; + pos[1][(surface + 0) % 3] = float(x + 0) - offset; + pos[1][(surface + 1) % 3] = float(y + 1) - offset; pos[1][(surface + 2) % 3] = offset; - pos[2][(surface + 0) % 3] = x + 1 - offset; - pos[2][(surface + 1) % 3] = y + 0 - offset; + pos[2][(surface + 0) % 3] = float(x + 1) - offset; + pos[2][(surface + 1) % 3] = float(y + 0) - offset; pos[2][(surface + 2) % 3] = offset; - pos[3][(surface + 0) % 3] = x + 1 - offset; - pos[3][(surface + 1) % 3] = y + 1 - offset; + pos[3][(surface + 0) % 3] = float(x + 1) - offset; + pos[3][(surface + 1) % 3] = float(y + 1) - offset; pos[3][(surface + 2) % 3] = offset; float tex = ts[TileAt(surface, x, y).type].texture; @@ -686,7 +695,9 @@ void GenerateTest(const Set &tiles, Planet &p) noexcept { Sun::Sun() -: Body() { +: Body() +, color(1.0) +, luminosity(1.0) { } Sun::~Sun() {