123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221 |
- #pragma once
- #include <Mathematics/IntrLine2Line2.h>
- #include <Mathematics/Ray.h>
- namespace WwiseGTE
- {
- template <typename Real>
- class TIQuery<Real, Ray2<Real>, Ray2<Real>>
- {
- public:
- struct Result
- {
- bool intersect;
-
-
-
-
-
- int numIntersections;
- };
- Result operator()(Ray2<Real> const& ray0, Ray2<Real> const& ray1)
- {
- Result result;
- FIQuery<Real, Line2<Real>, Line2<Real>> llQuery;
- Line2<Real> line0(ray0.origin, ray0.direction);
- Line2<Real> line1(ray1.origin, ray1.direction);
- auto llResult = llQuery(line0, line1);
- if (llResult.numIntersections == 1)
- {
-
- if (llResult.line0Parameter[0] >= (Real)0
- && llResult.line1Parameter[0] >= (Real)0)
- {
- result.intersect = true;
- result.numIntersections = 1;
- }
- else
- {
- result.intersect = false;
- result.numIntersections = 0;
- }
- }
- else if (llResult.numIntersections == std::numeric_limits<int>::max())
- {
- if (Dot(ray0.direction, ray1.direction) > (Real)0)
- {
-
-
- result.intersect = true;
- result.numIntersections = std::numeric_limits<int>::max();
- }
- else
- {
-
-
-
-
- Vector2<Real> diff = ray1.origin - ray0.origin;
- Real t = Dot(ray0.direction, diff);
- if (t > (Real)0)
- {
- result.intersect = true;
- result.numIntersections = 2;
- }
- else if (t < (Real)0)
- {
- result.intersect = false;
- result.numIntersections = 0;
- }
- else
- {
- result.intersect = true;
- result.numIntersections = 1;
- }
- }
- }
- else
- {
- result.intersect = false;
- result.numIntersections = 0;
- }
- return result;
- }
- };
- template <typename Real>
- class FIQuery<Real, Ray2<Real>, Ray2<Real>>
- {
- public:
- struct Result
- {
- bool intersect;
-
-
-
-
-
- int numIntersections;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Real ray0Parameter[2], ray1Parameter[2];
- Vector2<Real> point[2];
- };
- Result operator()(Ray2<Real> const& ray0, Ray2<Real> const& ray1)
- {
- Result result;
- FIQuery<Real, Line2<Real>, Line2<Real>> llQuery;
- Line2<Real> line0(ray0.origin, ray0.direction);
- Line2<Real> line1(ray1.origin, ray1.direction);
- auto llResult = llQuery(line0, line1);
- if (llResult.numIntersections == 1)
- {
-
- if (llResult.line0Parameter[0] >= (Real)0
- && llResult.line1Parameter[0] >= (Real)0)
- {
- result.intersect = true;
- result.numIntersections = 1;
- result.ray0Parameter[0] = llResult.line0Parameter[0];
- result.ray1Parameter[0] = llResult.line1Parameter[0];
- result.point[0] = llResult.point;
- }
- else
- {
- result.intersect = false;
- result.numIntersections = 0;
- }
- }
- else if (llResult.numIntersections == std::numeric_limits<int>::max())
- {
-
-
- Real maxReal = std::numeric_limits<Real>::max();
- Vector2<Real> diff = ray1.origin - ray0.origin;
- Real t = Dot(ray0.direction, diff);
- if (Dot(ray0.direction, ray1.direction) > (Real)0)
- {
-
-
- result.intersect = true;
- result.numIntersections = std::numeric_limits<int>::max();
- if (t >= (Real)0)
- {
- result.ray0Parameter[0] = t;
- result.ray0Parameter[1] = maxReal;
- result.ray1Parameter[0] = (Real)0;
- result.ray1Parameter[1] = maxReal;
- result.point[0] = ray1.origin;
- }
- else
- {
- result.ray0Parameter[0] = (Real)0;
- result.ray0Parameter[1] = maxReal;
- result.ray1Parameter[0] = -t;
- result.ray1Parameter[1] = maxReal;
- result.point[0] = ray0.origin;
- }
- }
- else
- {
-
-
-
-
- if (t >= (Real)0)
- {
- result.intersect = true;
- result.numIntersections = 2;
- result.ray0Parameter[0] = (Real)0;
- result.ray0Parameter[1] = t;
- result.ray1Parameter[0] = (Real)0;
- result.ray1Parameter[1] = t;
- result.point[0] = ray0.origin;
- result.point[1] = ray1.origin;
- }
- else
- {
- result.intersect = false;
- result.numIntersections = 0;
- }
- }
- }
- else
- {
- result.intersect = false;
- result.numIntersections = 0;
- }
- return result;
- }
- };
- }
|