My Project
ParaAngle.h
1 #pragma once
2 
3 namespace ParaEngine
4 {
10  class Radian
11  {
12  float mRad;
13 
14  public:
15  explicit Radian(float r = 0) : mRad(r) {}
16  Radian(const Degree& d);
17  Radian& operator = (const float& f) { mRad = f; return *this; }
18  Radian& operator = (const Radian& r) { mRad = r.mRad; return *this; }
19  Radian& operator = (const Degree& d);
20 
21  float valueDegrees() const; // see bottom of this file
22  float valueRadians() const { return mRad; }
23  float valueAngleUnits() const;
24 
25  operator float() { return mRad; }
26 
27  const Radian& operator + () const { return *this; }
28  Radian operator + (const Radian& r) const { return Radian(mRad + r.mRad); }
29  Radian operator + (const Degree& d) const;
30  Radian& operator += (const Radian& r) { mRad += r.mRad; return *this; }
31  Radian& operator += (const Degree& d);
32  Radian operator - () const { return Radian(-mRad); }
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 * (float f) const { return Radian(mRad * f); }
38  Radian operator * (const Radian& f) const { return Radian(mRad * f.mRad); }
39  Radian& operator *= (float f) { mRad *= f; return *this; }
40  Radian operator / (float f) const { return Radian(mRad / f); }
41  Radian& operator /= (float f) { mRad /= f; return *this; }
42 
43  bool operator < (const Radian& r) const { return mRad < r.mRad; }
44  bool operator <= (const Radian& r) const { return mRad <= r.mRad; }
45  bool operator == (const Radian& r) const { return mRad == r.mRad; }
46  bool operator != (const Radian& r) const { return mRad != r.mRad; }
47  bool operator >= (const Radian& r) const { return mRad >= r.mRad; }
48  bool operator >(const Radian& r) const { return mRad > r.mRad; }
49  };
50 
56  class Degree
57  {
58  float mDeg; // if you get an error here - make sure to define/typedef 'float' first
59 
60  public:
61  explicit Degree(float d = 0) : mDeg(d) {}
62  Degree(const Radian& r) : mDeg(r.valueDegrees()) {}
63  Degree& operator = (const float& f) { mDeg = f; return *this; }
64  Degree& operator = (const Degree& d) { mDeg = d.mDeg; return *this; }
65  Degree& operator = (const Radian& r) { mDeg = r.valueDegrees(); return *this; }
66 
67  float valueDegrees() const { return mDeg; }
68  float valueRadians() const; // see bottom of this file
69  float valueAngleUnits() const;
70 
71  const Degree& operator + () const { return *this; }
72  Degree operator + (const Degree& d) const { return Degree(mDeg + d.mDeg); }
73  Degree operator + (const Radian& r) const { return Degree(mDeg + r.valueDegrees()); }
74  Degree& operator += (const Degree& d) { mDeg += d.mDeg; return *this; }
75  Degree& operator += (const Radian& r) { mDeg += r.valueDegrees(); return *this; }
76  Degree operator - () const { return Degree(-mDeg); }
77  Degree operator - (const Degree& d) const { return Degree(mDeg - d.mDeg); }
78  Degree operator - (const Radian& r) const { return Degree(mDeg - r.valueDegrees()); }
79  Degree& operator -= (const Degree& d) { mDeg -= d.mDeg; return *this; }
80  Degree& operator -= (const Radian& r) { mDeg -= r.valueDegrees(); return *this; }
81  Degree operator * (float f) const { return Degree(mDeg * f); }
82  Degree operator * (const Degree& f) const { return Degree(mDeg * f.mDeg); }
83  Degree& operator *= (float f) { mDeg *= f; return *this; }
84  Degree operator / (float f) const { return Degree(mDeg / f); }
85  Degree& operator /= (float f) { mDeg /= f; return *this; }
86 
87  bool operator < (const Degree& d) const { return mDeg < d.mDeg; }
88  bool operator <= (const Degree& d) const { return mDeg <= d.mDeg; }
89  bool operator == (const Degree& d) const { return mDeg == d.mDeg; }
90  bool operator != (const Degree& d) const { return mDeg != d.mDeg; }
91  bool operator >= (const Degree& d) const { return mDeg >= d.mDeg; }
92  bool operator >(const Degree& d) const { return mDeg > d.mDeg; }
93  };
94 
101  class Angle
102  {
103  float mAngle;
104  public:
105  explicit Angle(float angle) : mAngle(angle) {}
106  operator Radian() const;
107  operator Degree() const;
108  };
109 
110  // these functions could not be defined within the class definition of class
111  // Radian because they required class Degree to be defined
112  inline Radian::Radian(const Degree& d) : mRad(d.valueRadians()) {
113  }
114  inline Radian& Radian::operator = (const Degree& d) {
115  mRad = d.valueRadians(); return *this;
116  }
117  inline Radian Radian::operator + (const Degree& d) const {
118  return Radian(mRad + d.valueRadians());
119  }
120  inline Radian& Radian::operator += (const Degree& d) {
121  mRad += d.valueRadians();
122  return *this;
123  }
124  inline Radian Radian::operator - (const Degree& d) const {
125  return Radian(mRad - d.valueRadians());
126  }
127  inline Radian& Radian::operator -= (const Degree& d) {
128  mRad -= d.valueRadians();
129  return *this;
130  }
131 }
Wrapper class which indicates a given angle value is in Radians.
Definition: ParaAngle.h:10
different physics engine has different winding order.
Definition: EventBinding.h:32
Wrapper class which indicates a given angle value is in Degrees.
Definition: ParaAngle.h:56
Wrapper class which identifies a value as the currently default angle type, as defined by Math::setAn...
Definition: ParaAngle.h:101