123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- #pragma once
- #include <Mathematics/FIQuery.h>
- #include <Mathematics/TIQuery.h>
- #include <Mathematics/Line.h>
- #include <Mathematics/DistPoint3Plane3.h>
- namespace WwiseGTE
- {
- template <typename Real>
- class TIQuery<Real, Line3<Real>, Plane3<Real>>
- {
- public:
- struct Result
- {
- bool intersect;
- };
- Result operator()(Line3<Real> const& line, Plane3<Real> const& plane)
- {
- Result result;
- Real DdN = Dot(line.direction, plane.normal);
- if (DdN != (Real)0)
- {
-
-
- result.intersect = true;
- }
- else
- {
-
- DCPQuery<Real, Vector3<Real>, Plane3<Real>> vpQuery;
- result.intersect = (vpQuery(line.origin, plane).distance == (Real)0);
- }
- return result;
- }
- };
- template <typename Real>
- class FIQuery<Real, Line3<Real>, Plane3<Real>>
- {
- public:
- struct Result
- {
- Result()
- :
- intersect(false),
- parameter((Real)0),
- point{ (Real)0, (Real)0, (Real)0 }
- {
- }
- bool intersect;
-
-
-
-
-
- int numIntersections;
- Real parameter;
- Vector3<Real> point;
- };
- Result operator()(Line3<Real> const& line, Plane3<Real> 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<Real> const& lineOrigin,
- Vector3<Real> const& lineDirection, Plane3<Real> const& plane,
- Result& result)
- {
- Real DdN = Dot(lineDirection, plane.normal);
- DCPQuery<Real, Vector3<Real>, Plane3<Real>> vpQuery;
- auto vpResult = vpQuery(lineOrigin, plane);
- if (DdN != (Real)0)
- {
-
-
- result.intersect = true;
- result.numIntersections = 1;
- result.parameter = -vpResult.signedDistance / DdN;
- }
- else
- {
-
-
- if (vpResult.distance == (Real)0)
- {
-
-
- result.intersect = true;
- result.numIntersections = std::numeric_limits<int>::max();
- result.parameter = (Real)0;
- }
- else
- {
-
- result.intersect = false;
- result.numIntersections = 0;
- }
- }
- }
- };
- }
|