]> git.localhorst.tv Git - blank.git/blobdiff - src/world/chunk.cpp
collect collisions for each entity
[blank.git] / src / world / chunk.cpp
index c114526ba46cdace3204acb226189cb0af671d27..2c5e7ec4ebad297570c5ef71fd2799822e5e30cc 100644 (file)
@@ -3,8 +3,10 @@
 #include "ChunkLoader.hpp"
 
 #include "Generator.hpp"
+#include "WorldCollision.hpp"
 
 #include <algorithm>
+#include <iostream>
 #include <limits>
 #include <queue>
 
@@ -481,6 +483,36 @@ bool Chunk::Intersection(
        }
 }
 
+bool Chunk::Intersection(
+       const AABB &box,
+       const glm::mat4 &Mbox,
+       const glm::mat4 &Mchunk,
+       std::vector<WorldCollision> &col
+) const noexcept {
+       bool any = false;
+       float penetration;
+       glm::vec3 normal;
+
+       if (!blank::Intersection(box, Mbox, Bounds(), Mchunk, penetration, normal)) {
+               return false;
+       }
+       for (int idx = 0, z = 0; z < depth; ++z) {
+               for (int y = 0; y < height; ++y) {
+                       for (int x = 0; x < width; ++x, ++idx) {
+                               const BlockType &type = Type(idx);
+                               if (!type.visible) {
+                                       continue;
+                               }
+                               if (type.shape->Intersects(Mchunk * ToTransform(Pos(x, y, z), idx), box, Mbox, penetration, normal)) {
+                                       col.emplace_back(this, idx, penetration, normal);
+                                       any = true;
+                               }
+                       }
+               }
+       }
+       return any;
+}
+
 
 namespace {