X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2Fsim.cpp;h=8b4c2140c2ba96b672c9dd08ac7987223b52c9f9;hb=ed2711d42a7815657bf0653c25b8b9be8b7f1368;hp=abf2829498f20356115a128801279bf5c53eb10e;hpb=0453d6da05d4b29d953f00857d743310d9344ce0;p=blobs.git diff --git a/src/world/sim.cpp b/src/world/sim.cpp index abf2829..8b4c214 100644 --- a/src/world/sim.cpp +++ b/src/world/sim.cpp @@ -1,22 +1,48 @@ #include "Simulation.hpp" #include "Body.hpp" +#include "Planet.hpp" +#include "Sun.hpp" namespace blobs { namespace world { Simulation::Simulation(Body &r) -: root(r) { - r.SetSimulation(*this); +: root(r) +, bodies() +, planets() +, suns() +, time(0.0) { + AddBody(r); } Simulation::~Simulation() { } +void Simulation::AddBody(Body &b) { + b.SetSimulation(*this); + bodies.insert(&b); +} + +void Simulation::AddPlanet(Planet &p) { + AddBody(p); + planets.insert(&p); +} + +void Simulation::AddSun(Sun &s) { + AddBody(s); + suns.insert(&s); +} + void Simulation::Tick() { - time += 0.01666666666666666666666666666666; + constexpr double dt = 0.01666666666666666666666666666666; + time += dt; + for (auto body : bodies) { + body->Rotation(body->Rotation() + dt * body->AngularMomentum() / body->Inertia()); + body->Cache(); + } } }