+ if (cand.dist > coll.depth) continue;
+ WorldCollision cur_coll;
+ if (cand.chunk->Intersection(ray, M * cand.chunk->Transform(reference), cur_coll)) {
+ if (cur_coll.depth < coll.depth) {
+ coll = cur_coll;
+ }
+ }
+ }
+
+ return coll.chunk;
+}
+
+bool World::Intersection(
+ const Ray &ray,
+ const glm::mat4 &M,
+ const Entity &reference,
+ EntityCollision &coll
+) {
+ coll.entity = nullptr;
+ coll.depth = std::numeric_limits<float>::infinity();
+ for (Entity &cur_entity : entities) {
+ if (&cur_entity == &reference) {
+ continue;
+ }