BsDegree.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "Prerequisites/BsPlatformDefines.h"
  5. #include "Prerequisites/BsRTTIPrerequisites.h"
  6. namespace bs
  7. {
  8. class Radian;
  9. /** @addtogroup Math
  10. * @{
  11. */
  12. /**
  13. * Wrapper class which indicates a given angle value is in degrees.
  14. *
  15. * @note
  16. * Degree values are interchangeable with Radian values, and conversions will be done automatically between them.
  17. */
  18. class BS_UTILITY_EXPORT Degree
  19. {
  20. public:
  21. explicit Degree(float d = 0.0f) : mDeg(d) {}
  22. Degree(const Radian& r);
  23. Degree& operator= (const float& f) { mDeg = f; return *this; }
  24. Degree& operator= (const Degree& d) { mDeg = d.mDeg; return *this; }
  25. Degree& operator= (const Radian& r);
  26. /** Returns the value of the angle in degrees. */
  27. float valueDegrees() const { return mDeg; }
  28. /** Returns the value of the angle in radians. */
  29. float valueRadians() const;
  30. /** Wraps the angle in [0, 360) range */
  31. Degree wrap();
  32. const Degree& operator+ () const { return *this; }
  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- () const { return Degree(-mDeg); }
  38. Degree operator- (const Degree& d) const { return Degree (mDeg - d.mDeg); }
  39. Degree operator- (const Radian& r) const;
  40. Degree& operator-= (const Degree& d) { mDeg -= d.mDeg; return *this; }
  41. Degree& operator-= (const Radian& r);
  42. Degree operator* (float f) const { return Degree (mDeg * f); }
  43. Degree operator* (const Degree& f) const { return Degree (mDeg * f.mDeg); }
  44. Degree& operator*= (float f) { mDeg *= f; return *this; }
  45. Degree operator/ (float f) const { return Degree (mDeg / f); }
  46. Degree& operator/= (float f) { mDeg /= f; return *this; }
  47. friend Degree operator* (float lhs, const Degree& rhs) { return Degree(lhs * rhs.mDeg); }
  48. friend Degree operator/ (float lhs, const Degree& rhs) { return Degree(lhs / rhs.mDeg); }
  49. friend Degree operator+ (Degree& lhs, float rhs) { return Degree(lhs.mDeg + rhs); }
  50. friend Degree operator+ (float lhs, const Degree& rhs) { return Degree(lhs + rhs.mDeg); }
  51. friend Degree operator- (const Degree& lhs, float rhs) { return Degree(lhs.mDeg - rhs); }
  52. friend Degree operator- (const float lhs, const Degree& rhs) { return Degree(lhs - rhs.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. bool operator!= (const Degree& d) const { return mDeg != d.mDeg; }
  57. bool operator>= (const Degree& d) const { return mDeg >= d.mDeg; }
  58. bool operator> (const Degree& d) const { return mDeg > d.mDeg; }
  59. private:
  60. float mDeg;
  61. };
  62. /** @} */
  63. /** @cond SPECIALIZATIONS */
  64. BS_ALLOW_MEMCPY_SERIALIZATION(Degree);
  65. /** @endcond */
  66. }