123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #pragma once
- #include <Mathematics/Vector2.h>
- namespace WwiseGTE
- {
- template <typename Real>
- class Sector2
- {
- public:
-
-
-
- Sector2()
- :
- vertex(Vector2<Real>::Zero()),
- radius((Real)1),
- direction(Vector2<Real>::Unit(0)),
- angle((Real)GTE_C_PI),
- cosAngle((Real)-1),
- sinAngle((Real)0)
- {
- }
- Sector2(Vector2<Real> const& inVertex, Real inRadius,
- Vector2<Real> const& inDirection, Real inAngle)
- :
- vertex(inVertex),
- radius(inRadius),
- direction(inDirection)
- {
- SetAngle(inAngle);
- }
-
- void SetAngle(Real inAngle)
- {
- angle = inAngle;
- cosAngle = std::cos(angle);
- sinAngle = std::sin(angle);
- }
-
- bool Contains(Vector2<Real> const& p) const
- {
- Vector2<Real> diff = p - vertex;
- Real length = Length(diff);
- return length <= radius && Dot(direction, diff) >= length * cosAngle;
- }
-
-
-
-
- Vector2<Real> vertex;
- Real radius;
- Vector2<Real> direction;
- Real angle, cosAngle, sinAngle;
- public:
-
- bool operator==(Sector2 const& sector) const
- {
- return vertex == sector.vertex && radius == sector.radius
- && direction == sector.direction && angle == sector.angle;
- }
- bool operator!=(Sector2 const& sector) const
- {
- return !operator==(sector);
- }
- bool operator< (Sector2 const& sector) const
- {
- if (vertex < sector.vertex)
- {
- return true;
- }
- if (vertex > sector.vertex)
- {
- return false;
- }
- if (radius < sector.radius)
- {
- return true;
- }
- if (radius > sector.radius)
- {
- return false;
- }
- if (direction < sector.direction)
- {
- return true;
- }
- if (direction > sector.direction)
- {
- return false;
- }
- return angle < sector.angle;
- }
- bool operator<=(Sector2 const& sector) const
- {
- return !sector.operator<(*this);
- }
- bool operator> (Sector2 const& sector) const
- {
- return sector.operator<(*this);
- }
- bool operator>=(Sector2 const& sector) const
- {
- return !operator<(sector);
- }
- };
- }
|