BsDegree.h 2.9 KB

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