X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=src%2Fphysics%2Fray.hpp;h=22d19c435244a6473ab8c89150e3be25b00d220c;hb=0146c7b7f02ef5d74116546489aee85383bb4969;hp=355af50992a1341ff390a8f654d551639876a05b;hpb=2e761a60d1717297b7e308ef1b66e2a81319fdff;p=tacos.git diff --git a/src/physics/ray.hpp b/src/physics/ray.hpp index 355af50..22d19c4 100644 --- a/src/physics/ray.hpp +++ b/src/physics/ray.hpp @@ -1,6 +1,7 @@ #ifndef TACOS_PHYSICS_RAY_HPP_ #define TACOS_PHYSICS_RAY_HPP_ +#include #include @@ -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::epsilon() + ? std::numeric_limits::infinity() + : 1.0f / direction.x, + std::fabs(direction.y) < std::numeric_limits::epsilon() + ? std::numeric_limits::infinity() + : 1.0f / direction.y, + std::fabs(direction.z) < std::numeric_limits::epsilon() + ? std::numeric_limits::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