123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- #pragma once
- #include <Mathematics/Logger.h>
- #include <Mathematics/Math.h>
- #include <Mathematics/Ray.h>
- namespace WwiseGTE
- {
- template <int N, typename Real>
- class Cone
- {
- public:
-
-
-
-
-
-
- Cone()
- {
- ray.origin.MakeZero();
- ray.direction.MakeUnit(N - 1);
- SetAngle((Real)GTE_C_QUARTER_PI);
- MakeInfiniteCone();
- }
-
-
-
-
- Cone(Ray<N, Real> const& inRay, Real const& inAngle)
- :
- ray(inRay)
- {
- SetAngle(inAngle);
- MakeInfiniteCone();
- }
-
-
-
-
- Cone(Ray<N, Real> const& inRay, Real const& inAngle, Real const& inMinHeight)
- :
- ray(inRay)
- {
- SetAngle(inAngle);
- MakeInfiniteTruncatedCone(inMinHeight);
- }
-
-
-
-
- Cone(Ray<N, Real> const& inRay, Real inAngle, Real inMinHeight, Real inMaxHeight)
- :
- ray(inRay)
- {
- SetAngle(inAngle);
- MakeConeFrustum(inMinHeight, inMaxHeight);
- }
-
-
-
- void SetAngle(Real const& inAngle)
- {
- LogAssert((Real)0 < inAngle && inAngle < (Real)GTE_C_HALF_PI, "Invalid angle.");
- angle = inAngle;
- cosAngle = std::cos(angle);
- sinAngle = std::sin(angle);
- tanAngle = std::tan(angle);
- cosAngleSqr = cosAngle * cosAngle;
- sinAngleSqr = sinAngle * sinAngle;
- invSinAngle = (Real)1 / sinAngle;
- }
-
-
-
- void MakeInfiniteCone()
- {
- mMinHeight = (Real)0;
- mMaxHeight = (Real)-1;
- }
- void MakeInfiniteTruncatedCone(Real const& inMinHeight)
- {
- LogAssert(inMinHeight >= (Real)0, "Invalid minimum height.");
- mMinHeight = inMinHeight;
- mMaxHeight = (Real)-1;
- }
- void MakeFiniteCone(Real const& inMaxHeight)
- {
- LogAssert(inMaxHeight > (Real)0, "Invalid maximum height.");
- mMinHeight = (Real)0;
- mMaxHeight = inMaxHeight;
- }
- void MakeConeFrustum(Real const& inMinHeight, Real const& inMaxHeight)
- {
- LogAssert(inMinHeight >= (Real)0 && inMaxHeight > inMinHeight,
- "Invalid minimum or maximum height.");
- mMinHeight = inMinHeight;
- mMaxHeight = inMaxHeight;
- }
-
-
-
-
- inline Real GetMinHeight() const
- {
- return mMinHeight;
- }
- inline Real GetMaxHeight() const
- {
- return mMaxHeight;
- }
- inline bool HeightInRange(Real const& h) const
- {
- return mMinHeight <= h && (mMaxHeight != (Real)-1 ? h <= mMaxHeight : true);
- }
- inline bool HeightLessThanMin(Real const& h) const
- {
- return h < mMinHeight;
- }
- inline bool HeightGreaterThanMax(Real const& h) const
- {
- return (mMaxHeight != (Real)-1 ? h > mMaxHeight : false);
- }
- inline bool IsFinite() const
- {
- return mMaxHeight != (Real)-1;
- }
- inline bool IsInfinite() const
- {
- return mMaxHeight == (Real)-1;
- }
-
- Ray<N, Real> ray;
-
-
-
-
- Real angle;
- Real cosAngle, sinAngle, tanAngle;
- Real cosAngleSqr, sinAngleSqr, invSinAngle;
- private:
-
-
-
-
- Real mMinHeight, mMaxHeight;
- public:
-
-
- bool operator==(Cone const& cone) const
- {
- return ray == cone.ray
- && angle == cone.angle
- && mMinHeight == cone.mMinHeight
- && mMaxHeight == cone.mMaxHeight;
- }
- bool operator!=(Cone const& cone) const
- {
- return !operator==(cone);
- }
- bool operator< (Cone const& cone) const
- {
- if (ray < cone.ray)
- {
- return true;
- }
- if (ray > cone.ray)
- {
- return false;
- }
- if (angle < cone.angle)
- {
- return true;
- }
- if (angle > cone.angle)
- {
- return false;
- }
- if (mMinHeight < cone.mMinHeight)
- {
- return true;
- }
- if (mMinHeight > cone.mMinHeight)
- {
- return false;
- }
- return mMaxHeight < cone.mMaxHeight;
- }
- bool operator<=(Cone const& cone) const
- {
- return !cone.operator<(*this);
- }
- bool operator> (Cone const& cone) const
- {
- return cone.operator<(*this);
- }
- bool operator>=(Cone const& cone) const
- {
- return !operator<(cone);
- }
- };
-
- template <typename Real>
- using Cone3 = Cone<3, Real>;
- }
|