BsDegree.h 3.1 KB

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