123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- #pragma once
- #include <Mathematics/TIQuery.h>
- #include <Mathematics/Hypersphere.h>
- #include <Mathematics/Sector2.h>
- namespace WwiseGTE
- {
- template <typename Real>
- class TIQuery<Real, Circle2<Real>, Sector2<Real>>
- {
- public:
- struct Result
- {
- bool intersect;
- };
- Result operator()(Circle2<Real> const& disk, Sector2<Real> const& sector)
- {
- Result result;
-
- Vector2<Real> CmV = disk.center - sector.vertex;
- Real sqrLengthCmV = Dot(CmV, CmV);
- Real lengthCmV = std::sqrt(sqrLengthCmV);
- if (lengthCmV > disk.radius + sector.radius)
- {
-
- result.intersect = false;
- return result;
- }
-
-
-
- Vector2<Real> U = sector.vertex - (disk.radius / sector.sinAngle) * sector.direction;
- Vector2<Real> CmU = disk.center - U;
- Real lengthCmU = Length(CmU);
- if (Dot(sector.direction, CmU) < lengthCmU * sector.cosAngle)
- {
-
-
- result.intersect = false;
- return result;
- }
-
-
- Real dotDirCmV = Dot(sector.direction, CmV);
- if (-dotDirCmV >= lengthCmV * sector.sinAngle)
- {
-
-
- if (lengthCmV <= disk.radius)
- {
-
-
- result.intersect = true;
- }
- else
- {
-
- result.intersect = false;
- }
- return result;
- }
-
-
-
-
-
-
-
- Vector2<Real> U0
- {
- +sector.cosAngle * sector.direction[0] + sector.sinAngle * sector.direction[1],
- -sector.sinAngle * sector.direction[0] + sector.cosAngle * sector.direction[1]
- };
- Real dp0 = Dot(U0, CmV);
- Real discr0 = disk.radius * disk.radius + dp0 * dp0 - sqrLengthCmV;
- if (discr0 >= (Real)0)
- {
-
-
-
-
- Real tmin = dp0 - std::sqrt(discr0);
- if (sector.radius >= tmin)
- {
-
- result.intersect = true;
- return result;
- }
- else
- {
-
-
-
-
-
- if (dotDirCmV <= lengthCmV * sector.cosAngle)
- {
-
- result.intersect = false;
- return result;
- }
- }
- }
-
-
-
- Vector2<Real> U1
- {
- +sector.cosAngle * sector.direction[0] - sector.sinAngle * sector.direction[1],
- +sector.sinAngle * sector.direction[0] + sector.cosAngle * sector.direction[1]
- };
- Real dp1 = Dot(U1, CmV);
- Real discr1 = disk.radius * disk.radius + dp1 * dp1 - sqrLengthCmV;
- if (discr1 >= (Real)0)
- {
-
-
-
-
- Real tmin = dp1 - std::sqrt(discr1);
- if (sector.radius >= tmin)
- {
- result.intersect = true;
- return result;
- }
- else
- {
-
-
-
-
-
- if (dotDirCmV <= lengthCmV * sector.cosAngle)
- {
-
- result.intersect = false;
- return result;
- }
- }
- }
-
-
- result.intersect = true;
- return result;
- }
- };
- }
|