]> git.localhorst.tv Git - blobs.git/blobdiff - src/world/world.cpp
slightly better physics
[blobs.git] / src / world / world.cpp
index 9cd1e02df56a7f185a299f3337248cfbb22f417e..d7e293a5509d2d456c88cbca5b09daa44fdb49ba 100644 (file)
@@ -208,7 +208,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 +233,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)