]> git.localhorst.tv Git - blank.git/blobdiff - src/world/world.cpp
some annotations
[blank.git] / src / world / world.cpp
index dfcf7217f99372d1ea4ada491d55ffa409ec2336..d2b05d66850e96923704bfd262335af5cc464832 100644 (file)
@@ -605,8 +605,8 @@ void World::Update(Entity &entity, float dt) {
 
        EntityDerivative f;
        constexpr float sixth = 1.0f / 6.0f;
-       f.position = sixth * ((a.position + 2.0f * (b.position + c.position)) + d.position);
-       f.velocity = sixth * ((a.velocity + 2.0f * (b.velocity + c.velocity)) + d.velocity);
+       f.position = sixth * (a.position + 2.0f * (b.position + c.position) + d.position);
+       f.velocity = sixth * (a.velocity + 2.0f * (b.velocity + c.velocity) + d.velocity);
 
        state.pos.block += f.position * dt;
        state.velocity += f.velocity * dt;
@@ -725,7 +725,22 @@ glm::vec3 World::Gravity(
        const Entity &entity,
        const EntityState &state
 ) {
-       return glm::vec3(0.0f);
+       glm::vec3 force(0.0f);
+       ExactLocation::Coarse begin(state.pos.chunk - 1);
+       ExactLocation::Coarse end(state.pos.chunk + 2);
+
+       for (ExactLocation::Coarse pos(begin); pos.z < end.z; ++pos.z) {
+               for (pos.y = begin.y; pos.y < end.y; ++pos.y) {
+                       for (pos.x = begin.x; pos.x < end.x; ++pos.x) {
+                               Chunk *chunk = chunks.Get(pos);
+                               if (chunk) {
+                                       force += chunk->GravityAt(state.pos);
+                               }
+                       }
+               }
+       }
+
+       return force;
 }
 
 World::EntityHandle World::RemoveEntity(EntityHandle &eh) {