// 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, AlignedBox> { public: struct Result { Real distance, sqrDistance; // To compute a single closest point on each box, use // Vector closest0 = // (closestPoints[0].min + closestPoints[0].max)/2; // Vector closest1 = // (closestPoints[1].min + closestPoints[1].max)/2; AlignedBox closestPoints[2]; }; Result operator()(AlignedBox const& box0, AlignedBox const& box1) { Result result; result.sqrDistance = (Real)0; for (int i = 0; i < N; ++i) { if (box0.min[i] >= box1.max[i]) { Real delta = box0.min[i] - box1.min[i]; result.sqrDistance += delta * delta; result.closestPoints[0].min[i] = box0.min[i]; result.closestPoints[0].max[i] = box0.min[i]; result.closestPoints[1].min[i] = box1.max[i]; result.closestPoints[1].max[i] = box1.max[i]; } else if (box1.min[i] >= box0.max[i]) { Real delta = box1.min[i] - box0.max[i]; result.sqrDistance += delta * delta; result.closestPoints[0].min[i] = box0.max[i]; result.closestPoints[0].max[i] = box0.max[i]; result.closestPoints[1].min[i] = box1.min[i]; result.closestPoints[1].max[i] = box1.min[i]; } else { std::array intr0 = { box0.min[i], box0.max[i] }; std::array intr1 = { box1.min[i], box1.max[i] }; FIQuery, std::array> query; auto iiResult = query(intr0, intr1); for (int j = 0; j < 2; ++j) { result.closestPoints[j].min[i] = iiResult.overlap[0]; result.closestPoints[j].max[i] = iiResult.overlap[1]; } } } result.distance = std::sqrt(result.sqrDistance); return result; } }; }