// 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 // The queries consider the cylinder to be a solid. namespace WwiseGTE { template class FIQuery, Cylinder3> : public FIQuery, Cylinder3> { public: struct Result : public FIQuery, Cylinder3>::Result { // No additional information to compute. }; Result operator()(Segment3 const& segment, Cylinder3 const& cylinder) { Vector3 segOrigin, segDirection; Real segExtent; segment.GetCenteredForm(segOrigin, segDirection, segExtent); Result result; DoQuery(segOrigin, segDirection, segExtent, cylinder, result); for (int i = 0; i < result.numIntersections; ++i) { result.point[i] = segOrigin + result.parameter[i] * segDirection; } return result; } protected: void DoQuery(Vector3 const& segOrigin, Vector3 const& segDirection, Real segExtent, Cylinder3 const& cylinder, Result& result) { FIQuery, Cylinder3>::DoQuery(segOrigin, segDirection, cylinder, result); if (result.intersect) { // The line containing the segment intersects the cylinder; // the t-interval is [t0,t1]. The segment intersects the // cylinder as long as [t0,t1] overlaps the segment t-interval // [-segExtent,+segExtent]. std::array segInterval = { -segExtent, segExtent }; FIQuery, std::array> iiQuery; auto iiResult = iiQuery(result.parameter, segInterval); if (iiResult.intersect) { result.numIntersections = iiResult.numIntersections; result.parameter = iiResult.overlap; } else { result.intersect = false; result.numIntersections = 0; } } } }; }