]> git.localhorst.tv Git - blobs.git/blobdiff - src/world/sim.cpp
more orbits and stuff
[blobs.git] / src / world / sim.cpp
index abf2829498f20356115a128801279bf5c53eb10e..46454fd2952197311b72db9bfeace430a44bebdc 100644 (file)
@@ -7,16 +7,27 @@ namespace blobs {
 namespace world {
 
 Simulation::Simulation(Body &r)
-: root(r) {
-       r.SetSimulation(*this);
+: root(r)
+, all_bodies()
+, time(0.0) {
+       AddBody(r);
 }
 
 Simulation::~Simulation() {
 }
 
 
+void Simulation::AddBody(Body &b) {
+       b.SetSimulation(*this);
+       all_bodies.push_back(&b);
+}
+
 void Simulation::Tick() {
-       time += 0.01666666666666666666666666666666;
+       constexpr double dt = 0.01666666666666666666666666666666;
+       time += dt;
+       for (auto body : all_bodies) {
+               body->Rotation(body->Rotation() + dt * body->AngularMomentum() / body->Inertia());
+       }
 }
 
 }