BsRadian.h 3.1 KB

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