From 695e3db5f9b24ad46d236a28f9896dc9e5a619f6 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Tue, 6 Feb 2018 16:47:21 +0500 Subject: Simplified raycast --- src/World.cpp | 93 ++++++++++------------------------------------------------- 1 file changed, 15 insertions(+), 78 deletions(-) (limited to 'src/World.cpp') diff --git a/src/World.cpp b/src/World.cpp index e4c2a1b..4678964 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -135,86 +135,23 @@ const Section &World::GetSection(Vector sectionPos) { } } -Vector World::Raycast(glm::vec3 position, glm::vec3 direction, float &distance) { - auto triangle_intersection = [&] (const glm::vec3 &v0, const glm::vec3 &v1, const glm::vec3 &v2) -> bool { - glm::vec3 e1 = v1 - v0; - glm::vec3 e2 = v2 - v0; - - glm::vec3 pvec = glm::cross(direction, e2); - - float det = glm::dot(e1, pvec); - if (det < 1e-8 && det > -1e-8) { - return 0; - } - - float inv_det = 1 / det; - glm::vec3 tvec = position - v0; - float u = dot(tvec, pvec) * inv_det; - if (u < 0 || u > 1) { - return 0; - } - - glm::vec3 qvec = cross(tvec, e1); - float v = dot(direction, qvec) * inv_det; - if (v < 0 || u + v > 1) { - return 0; - } - return dot(e2, qvec) * inv_det; - }; - - float minDistance = 1000000; - Vector minBlock; - - for (int y = position.y-5; y