]> git.localhorst.tv Git - blobs.git/blobdiff - src/world/world.cpp
track a few things
[blobs.git] / src / world / world.cpp
index 9cd1e02df56a7f185a299f3337248cfbb22f417e..b80be094129011d029098b23b5986753e61d5f2d 100644 (file)
@@ -58,9 +58,6 @@ Body::Body()
 }
 
 Body::~Body() {
-       for (creature::Creature *c : creatures) {
-               delete c;
-       }
 }
 
 void Body::SetSimulation(Simulation &s) noexcept {
@@ -156,7 +153,7 @@ void Body::Tick(double dt) {
        // first remove creatures so they don't collide
        for (auto c = Creatures().begin(); c != Creatures().end();) {
                if ((*c)->Removable()) {
-                       delete *c;
+                       (*c)->Removed();
                        c = Creatures().erase(c);
                } else {
                        ++c;
@@ -208,7 +205,8 @@ void Body::CheckCollision() noexcept {
        for (auto &c : collisions) {
                c.A().GetSituation().Move(c.Normal() * (c.Depth() * -0.5));
                c.B().GetSituation().Move(c.Normal() * (c.Depth() * 0.5));
-               // TODO: adjust velocities as well
+               c.A().GetSituation().Accelerate(c.Normal() * -dot(c.Normal(), c.AVel()));
+               c.B().GetSituation().Accelerate(c.Normal() * -dot(c.Normal(), c.BVel()));
                // TODO: notify participants so they can be annoyed
        }
 }
@@ -232,10 +230,18 @@ const glm::dvec3 &CreatureCreatureCollision::APos() const noexcept {
        return a->GetSituation().Position();
 }
 
+const glm::dvec3 &CreatureCreatureCollision::AVel() const noexcept {
+       return a->GetSituation().Velocity();
+}
+
 const glm::dvec3 &CreatureCreatureCollision::BPos() const noexcept {
        return b->GetSituation().Position();
 }
 
+const glm::dvec3 &CreatureCreatureCollision::BVel() const noexcept {
+       return b->GetSituation().Velocity();
+}
+
 
 Orbit::Orbit()
 : sma(1.0)