From 14a7c56abd5362b066e4bde806418a9e4bd716a9 Mon Sep 17 00:00:00 2001 From: Tom Cumming Date: Tue, 7 Jan 2014 10:54:00 +0000 Subject: [PATCH] Ray plane intersection function --- glm/gtx/intersect.hpp | 9 +++++++++ glm/gtx/intersect.inl | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+) 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 (