diff --git a/glm/gtx/intersect.hpp b/glm/gtx/intersect.hpp index 1ffa872e..3a48bfe1 100644 --- a/glm/gtx/intersect.hpp +++ b/glm/gtx/intersect.hpp @@ -52,6 +52,15 @@ namespace glm /// @addtogroup gtx_intersect /// @{ + //! Compute the intersection of a ray and a triangle. + //! Ray direction and plane normal must be unit length. + //! From GLM_GTX_intersect extension. + template + bool intersectRayPlane( + genType const & orig, genType const & dir, + genType const & planeOrig, genType const & planeNormal, + typename genType::value_type & intersectionDistance); + //! Compute the intersection of a ray and a triangle. //! From GLM_GTX_intersect extension. template diff --git a/glm/gtx/intersect.inl b/glm/gtx/intersect.inl index cc074d63..0c1cc935 100644 --- a/glm/gtx/intersect.inl +++ b/glm/gtx/intersect.inl @@ -13,6 +13,26 @@ namespace glm { + template + GLM_FUNC_QUALIFIER bool intersectRayPlane + ( + genType const & orig, genType const & dir, + genType const & planeOrig, genType const & planeNormal, + typename genType::value_type & intersectionDistance + ) + { + typename genType::value_type d = glm::dot(dir, planeNormal); + typename genType::value_type Epsilon = std::numeric_limits::epsilon(); + + if(d < Epsilon) + { + intersectionDistance = glm::dot(planeOrig - orig, planeNormal) / d; + return true; + } + + return false; + } + template GLM_FUNC_QUALIFIER bool intersectRayTriangle (