123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- #pragma once
- #include <Mathematics/Vector3.h>
- namespace WwiseGTE
- {
- template <typename Real>
- class Frustum3
- {
- public:
-
-
-
-
- Frustum3()
- :
- origin(Vector3<Real>::Zero()),
- dVector(Vector3<Real>::Unit(2)),
- uVector(Vector3<Real>::Unit(1)),
- rVector(Vector3<Real>::Unit(0)),
- dMin((Real)1),
- dMax((Real)2),
- uBound((Real)1),
- rBound((Real)1)
- {
- Update();
- }
- Frustum3(Vector3<Real> const& inOrigin, Vector3<Real> const& inDVector,
- Vector3<Real> const& inUVector, Vector3<Real> const& inRVector,
- Real inDMin, Real inDMax, Real inUBound, Real inRBound)
- :
- origin(inOrigin),
- dVector(inDVector),
- uVector(inUVector),
- rVector(inRVector),
- dMin(inDMin),
- dMax(inDMax),
- uBound(inUBound),
- rBound(inRBound)
- {
- Update();
- }
-
-
-
-
- void Update()
- {
- mDRatio = dMax / dMin;
- mMTwoUF = (Real)-2 * uBound * dMax;
- mMTwoRF = (Real)-2 * rBound * dMax;
- }
- inline Real GetDRatio() const
- {
- return mDRatio;
- }
- inline Real GetMTwoUF() const
- {
- return mMTwoUF;
- }
- inline Real GetMTwoRF() const
- {
- return mMTwoRF;
- }
- void ComputeVertices(std::array<Vector3<Real>, 8>& vertex) const
- {
- Vector3<Real> dScaled = dMin * dVector;
- Vector3<Real> uScaled = uBound * uVector;
- Vector3<Real> rScaled = rBound * rVector;
- vertex[0] = dScaled - uScaled - rScaled;
- vertex[1] = dScaled - uScaled + rScaled;
- vertex[2] = dScaled + uScaled + rScaled;
- vertex[3] = dScaled + uScaled - rScaled;
- for (int i = 0, ip = 4; i < 4; ++i, ++ip)
- {
- vertex[ip] = origin + mDRatio * vertex[i];
- vertex[i] += origin;
- }
- }
- Vector3<Real> origin, dVector, uVector, rVector;
- Real dMin, dMax, uBound, rBound;
- public:
-
- bool operator==(Frustum3 const& frustum) const
- {
- return origin == frustum.origin
- && dVector == frustum.dVector
- && uVector == frustum.uVector
- && rVector == frustum.rVector
- && dMin == frustum.dMin
- && dMax == frustum.dMax
- && uBound == frustum.uBound
- && rBound == frustum.rBound;
- }
- bool operator!=(Frustum3 const& frustum) const
- {
- return !operator==(frustum);
- }
- bool operator< (Frustum3 const& frustum) const
- {
- if (origin < frustum.origin)
- {
- return true;
- }
- if (origin > frustum.origin)
- {
- return false;
- }
- if (dVector < frustum.dVector)
- {
- return true;
- }
- if (dVector > frustum.dVector)
- {
- return false;
- }
- if (uVector < frustum.uVector)
- {
- return true;
- }
- if (uVector > frustum.uVector)
- {
- return false;
- }
- if (rVector < frustum.rVector)
- {
- return true;
- }
- if (rVector > frustum.rVector)
- {
- return false;
- }
- if (dMin < frustum.dMin)
- {
- return true;
- }
- if (dMin > frustum.dMin)
- {
- return false;
- }
- if (dMax < frustum.dMax)
- {
- return true;
- }
- if (dMax > frustum.dMax)
- {
- return false;
- }
- if (uBound < frustum.uBound)
- {
- return true;
- }
- if (uBound > frustum.uBound)
- {
- return false;
- }
- return rBound < frustum.rBound;
- }
- bool operator<=(Frustum3 const& frustum) const
- {
- return !frustum.operator<(*this);
- }
- bool operator> (Frustum3 const& frustum) const
- {
- return frustum.operator<(*this);
- }
- bool operator>=(Frustum3 const& frustum) const
- {
- return !operator<(frustum);
- }
- protected:
-
- Real mDRatio, mMTwoUF, mMTwoRF;
- };
- }
|