BsRadian.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. #include "BsPrerequisitesUtil.h"
  3. #include "BsDegree.h"
  4. namespace BansheeEngine
  5. {
  6. /** @addtogroup Math
  7. * @{
  8. */
  9. /**
  10. * Wrapper class which indicates a given angle value is in radians.
  11. *
  12. * @note
  13. * Radian values are interchangeable with Degree values, and conversions will be done automatically between them.
  14. */
  15. class BS_UTILITY_EXPORT Radian
  16. {
  17. public:
  18. explicit Radian(float r = 0.0f) : mRad(r) {}
  19. Radian(const Degree& d);
  20. Radian& operator= (const float& f) { mRad = f; return *this; }
  21. Radian& operator= (const Radian& r) { mRad = r.mRad; return *this; }
  22. Radian& operator= (const Degree& d);
  23. /** Returns the value of the angle in degrees. */
  24. float valueDegrees() const;
  25. /** Returns the value of the angle in radians. */
  26. float valueRadians() const { return mRad; }
  27. /** Wraps the angle in [0, 2 * PI) range. */
  28. Radian wrap();
  29. const Radian& operator+ () const { return *this; }
  30. Radian operator+ (const Radian& r) const { return Radian (mRad + r.mRad); }
  31. Radian operator+ (const Degree& d) const;
  32. Radian& operator+= (const Radian& r) { mRad += r.mRad; return *this; }
  33. Radian& operator+= (const Degree& d);
  34. Radian operator- () const { return Radian(-mRad); }
  35. Radian operator- (const Radian& r) const { return Radian (mRad - r.mRad); }
  36. Radian operator- (const Degree& d) const;
  37. Radian& operator-= (const Radian& r) { mRad -= r.mRad; return *this; }
  38. Radian& operator-= (const Degree& d);
  39. Radian operator* (float f) const { return Radian (mRad * f); }
  40. Radian operator* (const Radian& f) const { return Radian (mRad * f.mRad); }
  41. Radian& operator*= (float f) { mRad *= f; return *this; }
  42. Radian operator/ (float f) const { return Radian (mRad / f); }
  43. Radian& operator/= (float f) { mRad /= f; return *this; }
  44. friend Radian operator* (float lhs, const Radian& rhs) { return Radian(lhs * rhs.mRad); }
  45. friend Radian operator/ (float lhs, const Radian& rhs) { return Radian(lhs / rhs.mRad); }
  46. friend Radian operator+ (Radian& lhs, float rhs) { return Radian(lhs.mRad + rhs); }
  47. friend Radian operator+ (float lhs, const Radian& rhs) { return Radian(lhs + rhs.mRad); }
  48. friend Radian operator- (const Radian& lhs, float rhs) { return Radian(lhs.mRad - rhs); }
  49. friend Radian operator- (const float lhs, const Radian& rhs) { return Radian(lhs - rhs.mRad); }
  50. bool operator< (const Radian& r) const { return mRad < r.mRad; }
  51. bool operator<= (const Radian& r) const { return mRad <= r.mRad; }
  52. bool operator== (const Radian& r) const { return mRad == r.mRad; }
  53. bool operator!= (const Radian& r) const { return mRad != r.mRad; }
  54. bool operator>= (const Radian& r) const { return mRad >= r.mRad; }
  55. bool operator> (const Radian& r) const { return mRad > r.mRad; }
  56. private:
  57. float mRad;
  58. };
  59. /** @} */
  60. /** @cond SPECIALIZATIONS */
  61. BS_ALLOW_MEMCPY_SERIALIZATION(Radian);
  62. /** @endcond */
  63. }