BsDegree.h 2.6 KB

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