]> git.localhorst.tv Git - tacos.git/blobdiff - src/physics/ray.hpp
ray/floor intersection experiments
[tacos.git] / src / physics / ray.hpp
index 355af50992a1341ff390a8f654d551639876a05b..22d19c435244a6473ab8c89150e3be25b00d220c 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef TACOS_PHYSICS_RAY_HPP_
 #define TACOS_PHYSICS_RAY_HPP_
 
+#include <limits>
 #include <glm/glm.hpp>
 
 
@@ -11,8 +12,30 @@ struct Ray {
        glm::vec3 origin;
        glm::vec3 direction;
 
+       glm::vec3 InverseDirection() const noexcept {
+               return glm::vec3(
+                       std::fabs(direction.x) < std::numeric_limits<float>::epsilon()
+                               ? std::numeric_limits<float>::infinity()
+                               : 1.0f / direction.x,
+                       std::fabs(direction.y) < std::numeric_limits<float>::epsilon()
+                               ? std::numeric_limits<float>::infinity()
+                               : 1.0f / direction.y,
+                       std::fabs(direction.z) < std::numeric_limits<float>::epsilon()
+                               ? std::numeric_limits<float>::infinity()
+                               : 1.0f / direction.z);
+       }
+
 };
 
+/// check whether given ray intersects with the triangle with vertices p0, p1, and p2
+/// point of intersection is writte to point if the result is positive
+bool TriangleIntersection(
+       const Ray &ray,
+       const glm::vec3 &p0,
+       const glm::vec3 &p1,
+       const glm::vec3 &p2,
+       glm::vec3 &point) noexcept;
+
 }
 
 #endif