// 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 TIQuery, Plane3> { public: struct Result { bool intersect; }; Result operator()(Line3 const& line, Plane3 const& plane) { Result result; Real DdN = Dot(line.direction, plane.normal); if (DdN != (Real)0) { // The line is not parallel to the plane, so they must // intersect. result.intersect = true; } else { // The line and plane are parallel. DCPQuery, Plane3> vpQuery; result.intersect = (vpQuery(line.origin, plane).distance == (Real)0); } return result; } }; template class FIQuery, Plane3> { public: struct Result { Result() : intersect(false), parameter((Real)0), point{ (Real)0, (Real)0, (Real)0 } { } bool intersect; // The number of intersections is 0 (no intersection), 1 (linear // component and plane intersect in a point), or // std::numeric_limits::max() (linear component is on the // plane). If the linear component is on the plane, 'point' // component's origin and 'parameter' is zero. int numIntersections; Real parameter; Vector3 point; }; Result operator()(Line3 const& line, Plane3 const& plane) { Result result; DoQuery(line.origin, line.direction, plane, result); if (result.intersect) { result.point = line.origin + result.parameter * line.direction; } return result; } protected: void DoQuery(Vector3 const& lineOrigin, Vector3 const& lineDirection, Plane3 const& plane, Result& result) { Real DdN = Dot(lineDirection, plane.normal); DCPQuery, Plane3> vpQuery; auto vpResult = vpQuery(lineOrigin, plane); if (DdN != (Real)0) { // The line is not parallel to the plane, so they must // intersect. result.intersect = true; result.numIntersections = 1; result.parameter = -vpResult.signedDistance / DdN; } else { // The line and plane are parallel. Determine whether the // line is on the plane. if (vpResult.distance == (Real)0) { // The line is coincident with the plane, so choose t = 0 // for the parameter. result.intersect = true; result.numIntersections = std::numeric_limits::max(); result.parameter = (Real)0; } else { // The line is not on the plane. result.intersect = false; result.numIntersections = 0; } } } }; }