123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- #pragma once
- #include <Mathematics/Vector2.h>
- #include <Mathematics/Line.h>
- #include <Mathematics/FIQuery.h>
- #include <Mathematics/TIQuery.h>
- #include <limits>
- namespace WwiseGTE
- {
- template <typename Real>
- class TIQuery<Real, Line2<Real>, Line2<Real>>
- {
- public:
- struct Result
- {
- bool intersect;
-
-
-
- int numIntersections;
- };
- Result operator()(Line2<Real> const& line0, Line2<Real> const& line1)
- {
- Result result;
-
-
-
-
-
-
-
-
- Vector2<Real> diff = line1.origin - line0.origin;
- Real D0DotPerpD1 = DotPerp(line0.direction, line1.direction);
- if (D0DotPerpD1 != (Real)0)
- {
-
- result.intersect = true;
- result.numIntersections = 1;
- }
- else
- {
-
- Normalize(diff);
- Real diffNDotPerpD1 = DotPerp(diff, line1.direction);
- if (diffNDotPerpD1 != (Real)0)
- {
-
- result.intersect = false;
- result.numIntersections = 0;
- }
- else
- {
-
- result.intersect = true;
- result.numIntersections = std::numeric_limits<int>::max();
- }
- }
- return result;
- }
- };
- template <typename Real>
- class FIQuery<Real, Line2<Real>, Line2<Real>>
- {
- public:
- struct Result
- {
- bool intersect;
-
-
-
- int numIntersections;
-
-
-
-
-
-
-
- Real line0Parameter[2], line1Parameter[2];
- Vector2<Real> point;
- };
- Result operator()(Line2<Real> const& line0, Line2<Real> const& line1)
- {
- Result result;
-
-
-
-
-
-
-
-
- Vector2<Real> diff = line1.origin - line0.origin;
- Real D0DotPerpD1 = DotPerp(line0.direction, line1.direction);
- if (D0DotPerpD1 != (Real)0)
- {
-
- result.intersect = true;
- result.numIntersections = 1;
- Real invD0DotPerpD1 = (Real)1 / D0DotPerpD1;
- Real diffDotPerpD0 = DotPerp(diff, line0.direction);
- Real diffDotPerpD1 = DotPerp(diff, line1.direction);
- Real s0 = diffDotPerpD1 * invD0DotPerpD1;
- Real s1 = diffDotPerpD0 * invD0DotPerpD1;
- result.line0Parameter[0] = s0;
- result.line1Parameter[0] = s1;
- result.point = line0.origin + s0 * line0.direction;
- }
- else
- {
-
- Normalize(diff);
- Real diffNDotPerpD1 = DotPerp(diff, line1.direction);
- if (std::fabs(diffNDotPerpD1) != (Real)0)
- {
-
- result.intersect = false;
- result.numIntersections = 0;
- }
- else
- {
-
- result.intersect = true;
- result.numIntersections = std::numeric_limits<int>::max();
- Real maxReal = std::numeric_limits<Real>::max();
- result.line0Parameter[0] = -maxReal;
- result.line0Parameter[1] = +maxReal;
- result.line1Parameter[0] = -maxReal;
- result.line1Parameter[1] = +maxReal;
- }
- }
- return result;
- }
- };
- }
|