// David Eberly, Geometric Tools, Redmond WA 98052 // Copyright (c) 1998-2020 // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt // Version: 4.0.2019.08.13 #pragma once #include #include namespace WwiseGTE { template class DCPQuery, Ray> { public: struct Result { Real distance, sqrDistance; Real rayParameter; // t in [0,+infinity) Vector rayClosest; // origin + t * direction }; Result operator()(Vector const& point, Ray const& ray) { Result result; Vector diff = point - ray.origin; result.rayParameter = Dot(ray.direction, diff); if (result.rayParameter > (Real)0) { result.rayClosest = ray.origin + result.rayParameter * ray.direction; } else { result.rayClosest = ray.origin; } diff = point - result.rayClosest; result.sqrDistance = Dot(diff, diff); result.distance = std::sqrt(result.sqrDistance); return result; } }; // Template aliases for convenience. template using DCPPointRay = DCPQuery, Ray>; template using DCPPoint2Ray2 = DCPPointRay<2, Real>; template using DCPPoint3Ray3 = DCPPointRay<3, Real>; }