diff --git a/glm/gtx/intersect.hpp b/glm/gtx/intersect.hpp index cfc4e50c..d066a760 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 9b7a7772..b919828c 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 (