]> git.localhorst.tv Git - blank.git/blobdiff - src/world/world.cpp
per block type "gravity"
[blank.git] / src / world / world.cpp
index dfcf7217f99372d1ea4ada491d55ffa409ec2336..2a3d5fbc12d7c4dd447acd5c71a4d5f4b47044ca 100644 (file)
@@ -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) {