]> git.localhorst.tv Git - tacos.git/blob - src/physics/ray.hpp
ray/floor intersection experiments
[tacos.git] / src / physics / ray.hpp
1 #ifndef TACOS_PHYSICS_RAY_HPP_
2 #define TACOS_PHYSICS_RAY_HPP_
3
4 #include <limits>
5 #include <glm/glm.hpp>
6
7
8 namespace tacos {
9
10 struct Ray {
11
12         glm::vec3 origin;
13         glm::vec3 direction;
14
15         glm::vec3 InverseDirection() const noexcept {
16                 return glm::vec3(
17                         std::fabs(direction.x) < std::numeric_limits<float>::epsilon()
18                                 ? std::numeric_limits<float>::infinity()
19                                 : 1.0f / direction.x,
20                         std::fabs(direction.y) < std::numeric_limits<float>::epsilon()
21                                 ? std::numeric_limits<float>::infinity()
22                                 : 1.0f / direction.y,
23                         std::fabs(direction.z) < std::numeric_limits<float>::epsilon()
24                                 ? std::numeric_limits<float>::infinity()
25                                 : 1.0f / direction.z);
26         }
27
28 };
29
30 /// check whether given ray intersects with the triangle with vertices p0, p1, and p2
31 /// point of intersection is writte to point if the result is positive
32 bool TriangleIntersection(
33         const Ray &ray,
34         const glm::vec3 &p0,
35         const glm::vec3 &p1,
36         const glm::vec3 &p2,
37         glm::vec3 &point) noexcept;
38
39 }
40
41 #endif