6 bool TriangleIntersection(
13 glm::vec3 edge1(p1 - p0);
14 glm::vec3 edge2(p2 - p0);
16 glm::vec3 h(glm::cross(ray.direction, edge2));
17 float a = glm::dot(edge1, h);
19 if (std::fabs(a) < std::numeric_limits<float>::epsilon()) {
24 glm::vec3 s(ray.origin - p0);
25 float u = f * glm::dot(s, h);
27 if (u < 0.0f || u > 1.0f) {
31 glm::vec3 q(glm::cross(s, edge1));
32 float v = f * glm::dot(ray.direction, q);
34 if (v < 0.0f || u + v > 1.0f) {
38 float t = f * glm::dot(edge2, q);
39 point = ray.origin + (t * ray.direction);
40 return t > std::numeric_limits<float>::epsilon();