123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- #pragma once
- #include <Mathematics/Vector3.h>
- namespace WwiseGTE
- {
- template <typename Real>
- class Torus3
- {
- public:
-
-
-
- Torus3()
- :
- center(Vector3<Real>::Zero()),
- direction0(Vector3<Real>::Unit(0)),
- direction1(Vector3<Real>::Unit(1)),
- normal(Vector3<Real>::Unit(2)),
- radius0((Real)2),
- radius1((Real)1)
- {
- }
- Torus3(Vector3<Real> const& inCenter, Vector3<Real> const& inDirection0,
- Vector3<Real> const& inDirection1, Vector3<Real> const& inNormal,
- Real inRadius0, Real inRadius1)
- :
- center(inCenter),
- direction0(inDirection0),
- direction1(inDirection1),
- normal(inNormal),
- radius0(inRadius0),
- radius1(inRadius1)
- {
- }
-
-
-
-
-
-
-
-
- void Evaluate(Real u, Real v, unsigned int maxOrder, Vector3<Real>* jet) const
- {
-
- Real csu = std::cos(u);
- Real snu = std::sin(u);
- Real csv = std::cos(v);
- Real snv = std::sin(v);
- Real r1csv = radius1 * csv;
- Real r1snv = radius1 * snv;
- Real r0pr1csv = radius0 + r1csv;
- Vector3<Real> combo0 = csu * direction0 + snu * direction1;
- Vector3<Real> r0pr1csvcombo0 = r0pr1csv * combo0;
- Vector3<Real> r1snvnormal = r1snv * normal;
- jet[0] = center + r0pr1csvcombo0 + r1snvnormal;
- if (maxOrder >= 1)
- {
-
- Vector3<Real> combo1 = -snu * direction0 + csu * direction1;
- jet[1] = r0pr1csv * combo1;
- jet[2] = -r1snv * combo0 + r1csv * normal;
- if (maxOrder == 2)
- {
-
- jet[3] = -r0pr1csvcombo0;
- jet[4] = -r1snv * combo1;
- jet[5] = -r1csv * combo0 - r1snvnormal;
- }
- }
- }
-
- void GetParameters(Vector3<Real> const& X, Real& u, Real& v) const
- {
- Vector3<Real> delta = X - center;
-
- Real dot0 = Dot(direction0, delta);
-
- Real dot1 = Dot(direction1, delta);
-
- Real dot2 = Dot(normal, delta);
-
- Real r1csv = std::sqrt(dot0 * dot0 + dot1 * dot1) - radius0;
- u = std::atan2(dot1, dot0);
- v = std::atan2(dot2, r1csv);
- }
- Vector3<Real> center, direction0, direction1, normal;
- Real radius0, radius1;
- public:
-
- bool operator==(Torus3 const& torus) const
- {
- return center == torus.center
- && direction0 == torus.direction0
- && direction1 == torus.direction1
- && normal == torus.normal
- && radius0 == torus.radius0
- && radius1 == torus.radius1;
- }
- bool operator!=(Torus3 const& torus) const
- {
- return !operator==(torus);
- }
- bool operator< (Torus3 const& torus) const
- {
- if (center < torus.center)
- {
- return true;
- }
- if (center > torus.center)
- {
- return false;
- }
- if (direction0 < torus.direction0)
- {
- return true;
- }
- if (direction0 > torus.direction0)
- {
- return false;
- }
- if (direction1 < torus.direction1)
- {
- return true;
- }
- if (direction1 > torus.direction1)
- {
- return false;
- }
- if (normal < torus.normal)
- {
- return true;
- }
- if (normal > torus.normal)
- {
- return false;
- }
- if (radius0 < torus.radius0)
- {
- return true;
- }
- if (radius0 > torus.radius0)
- {
- return false;
- }
- return radius1 < torus.radius1;
- }
- bool operator<=(Torus3 const& torus) const
- {
- return !torus.operator<(*this);
- }
- bool operator> (Torus3 const& torus) const
- {
- return torus.operator<(*this);
- }
- bool operator>=(Torus3 const& torus) const
- {
- return !operator<(torus);
- }
- };
- }
|