// 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 #include namespace WwiseGTE { template class DCPQuery, Triangle3> { public: struct Result { Real distance, sqrDistance; Real segmentParameter, triangleParameter[3]; Vector3 closestPoint[2]; }; Result operator()(Segment3 const& segment, Triangle3 const& triangle) { Result result; Vector3 segCenter, segDirection; Real segExtent; segment.GetCenteredForm(segCenter, segDirection, segExtent); Line3 line(segCenter, segDirection); DCPQuery, Triangle3> ltQuery; auto ltResult = ltQuery(line, triangle); if (ltResult.lineParameter >= -segExtent) { if (ltResult.lineParameter <= segExtent) { result.distance = ltResult.distance; result.sqrDistance = ltResult.sqrDistance; result.segmentParameter = ltResult.lineParameter; result.triangleParameter[0] = ltResult.triangleParameter[0]; result.triangleParameter[1] = ltResult.triangleParameter[1]; result.triangleParameter[2] = ltResult.triangleParameter[2]; result.closestPoint[0] = ltResult.closestPoint[0]; result.closestPoint[1] = ltResult.closestPoint[1]; } else { DCPQuery, Triangle3> ptQuery; Vector3 point = segCenter + segExtent * segDirection; auto ptResult = ptQuery(point, triangle); result.sqrDistance = ptResult.sqrDistance; result.distance = ptResult.distance; result.segmentParameter = segExtent; result.closestPoint[0] = point; result.closestPoint[1] = ptResult.closest; } } else { DCPQuery, Triangle3> ptQuery; Vector3 point = segCenter - segExtent * segDirection; auto ptResult = ptQuery(point, triangle); result.sqrDistance = ptResult.sqrDistance; result.distance = ptResult.distance; result.segmentParameter = segExtent; result.closestPoint[0] = point; result.closestPoint[1] = ptResult.closest; } return result; } }; }