X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FWorld.cpp;fp=src%2Fworld%2FWorld.cpp;h=2c0d164d5b4acb8f09bc4eba77b8a83faf881967;hb=b0c2d423138dfb4849c679b3fb93e4336dcf5845;hp=1e372e753d8c82257fb7bcd34fe6295c11e70e78;hpb=f417749fb09718cde2faad77e8430cf175c68374;p=blank.git diff --git a/src/world/World.cpp b/src/world/World.cpp index 1e372e7..2c0d164 100644 --- a/src/world/World.cpp +++ b/src/world/World.cpp @@ -95,6 +95,35 @@ bool World::Intersection( return chunk; } +bool World::Intersection( + const Ray &ray, + const glm::mat4 &M, + Entity *&entity, + float &dist, + glm::vec3 &normal +) { + entity = nullptr; + dist = std::numeric_limits::infinity(); + for (Entity &cur_entity : entities) { + // TODO: better check for skipping self (because the check might not be for the player) + if (&cur_entity == player) { + continue; + } + float cur_dist; + glm::vec3 cur_normal; + if (blank::Intersection(ray, cur_entity.Bounds(), M * cur_entity.Transform(player->ChunkCoords()), &cur_dist, &cur_normal)) { + // TODO: fine grained check goes here? maybe? + if (cur_dist < dist) { + entity = &cur_entity; + dist = cur_dist; + normal = cur_normal; + } + } + } + + return entity; +} + bool World::Intersection(const Entity &e, std::vector &col) { AABB box = e.Bounds(); glm::mat4 M = e.Transform(player->ChunkCoords());