// 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 #include namespace WwiseGTE { template class DCPQuery, OrientedBox3> { public: struct Result { Real distance, sqrDistance; Real segmentParameter; Vector3 closestPoint[2]; }; Result operator()(Segment3 const& segment, OrientedBox3 const& box) { Result result; Vector3 segCenter, segDirection; Real segExtent; segment.GetCenteredForm(segCenter, segDirection, segExtent); Line3 line(segCenter, segDirection); DCPQuery, OrientedBox3> lbQuery; auto lbResult = lbQuery(line, box); if (lbResult.lineParameter >= -segExtent) { if (lbResult.lineParameter <= segExtent) { result.sqrDistance = lbResult.sqrDistance; result.distance = lbResult.distance; result.segmentParameter = lbResult.lineParameter; result.closestPoint[0] = lbResult.closestPoint[0]; result.closestPoint[1] = lbResult.closestPoint[1]; } else { DCPQuery, OrientedBox3> pbQuery; Vector3 point = segCenter + segExtent * segDirection; auto pbResult = pbQuery(point, box); result.sqrDistance = pbResult.sqrDistance; result.distance = pbResult.distance; result.segmentParameter = segExtent; result.closestPoint[0] = point; result.closestPoint[1] = pbResult.boxClosest; } } else { DCPQuery, OrientedBox3> pbQuery; Vector3 point = segCenter - segExtent * segDirection; auto pbResult = pbQuery(point, box); result.sqrDistance = pbResult.sqrDistance; result.distance = pbResult.distance; result.segmentParameter = segExtent; result.closestPoint[0] = point; result.closestPoint[1] = pbResult.boxClosest; } return result; } }; }