|
8 | 8 | #include "nw4r/math/math_triangular.h" |
9 | 9 | #include "s/s_Math.h" |
10 | 10 |
|
11 | | -struct mAng { |
| 11 | +class mAng { |
| 12 | +public: |
12 | 13 | mAng() {} |
13 | 14 | mAng(s16 s) : mVal(s) {} |
14 | 15 | mAng(const mAng &other) : mVal(other.mVal) {} |
15 | 16 |
|
16 | | - mAng &operator=(const s32 &val) { |
| 17 | +public: |
| 18 | + void set(s16 val) { |
17 | 19 | mVal = val; |
18 | | - return *this; |
19 | | - } |
20 | | - |
21 | | - void setF(const f32 &f) { |
22 | | - mVal = f; |
23 | 20 | } |
24 | 21 |
|
25 | | - static mAng atan2s(f32 a, f32 b) { |
26 | | - return mAng(cM::atan2s(a, b)); |
27 | | - } |
28 | | - static mAng fromVec(const mVec3_c &other) { |
29 | | - return mAng(cM::atan2s(other.x, other.z)); |
| 22 | +public: |
| 23 | + s16 *ref() { |
| 24 | + return &mVal; |
30 | 25 | } |
31 | 26 |
|
32 | 27 | operator s16() const { |
33 | 28 | return mVal; |
34 | 29 | } |
35 | 30 |
|
36 | | - void set(s16 val) { |
37 | | - mVal = val; |
38 | | - } |
39 | | - |
40 | | - s16 *ref() { |
41 | | - return &mVal; |
42 | | - } |
43 | | - |
44 | 31 | mAng operator-() { |
45 | 32 | return mAng(-mVal); |
46 | 33 | } |
47 | 34 |
|
48 | | - mAng &operator+=(const mAng &other) { |
49 | | - mVal += other.mVal; |
| 35 | + template <typename T> |
| 36 | + mAng &operator+=(const T &other) { |
| 37 | + mVal += s16(other); |
50 | 38 | return *this; |
51 | 39 | } |
52 | | - mAng &operator-=(const mAng &other) { |
53 | | - mVal -= other.mVal; |
| 40 | + template <typename T> |
| 41 | + mAng &operator-=(const T &other) { |
| 42 | + mVal -= s16(other); |
54 | 43 | return *this; |
55 | 44 | } |
56 | | - mAng &operator*=(const s32 &other) { |
| 45 | + template <typename T> |
| 46 | + mAng &operator*=(const T &other) { |
57 | 47 | mVal *= other; |
58 | 48 | return *this; |
59 | 49 | } |
60 | | - mAng &operator*=(const f32 &other) { |
61 | | - mVal *= other; |
| 50 | + template <typename T> |
| 51 | + mAng &operator=(const T &other) { |
| 52 | + mVal = other; |
62 | 53 | return *this; |
63 | 54 | } |
64 | 55 |
|
65 | | - s32 absDiff(const mAng &other) const { |
66 | | - return sLib::absDiff(mVal, other.mVal); |
67 | | - } |
68 | | - |
| 56 | +public: |
69 | 57 | static s32 abs(const mAng b) { |
70 | 58 | return labs(b); |
71 | 59 | } |
72 | | - |
73 | | - s32 step(s16 target, s32 steps, s16 max, s16 min); |
74 | | - |
| 60 | + s32 abs() const { |
| 61 | + return abs(*this); |
| 62 | + } |
| 63 | + s32 absDiff(const mAng &other) const { |
| 64 | + return sLib::absDiff(mVal, other.mVal); |
| 65 | + } |
75 | 66 | f32 sin() const { |
76 | 67 | return nw4r::math::SinIdx(*this); |
77 | 68 | } |
78 | | - |
79 | 69 | f32 cos() const { |
80 | 70 | return nw4r::math::CosIdx(*this); |
81 | 71 | } |
82 | | - |
83 | | - f32 degree() const { |
84 | | - return (360.0f / 65536.0f) * mVal; |
| 72 | + static mAng atan2s(f32 a, f32 b) { |
| 73 | + return mAng(cM::atan2s(a, b)); |
85 | 74 | } |
86 | 75 |
|
| 76 | +public: |
| 77 | + s32 step(s16 target, s32 steps, s16 max, s16 min); |
| 78 | + |
| 79 | +public: |
| 80 | + static mAng fromVec(const mVec3_c &other) { |
| 81 | + return mAng(cM::atan2s(other.x, other.z)); |
| 82 | + } |
87 | 83 | static s16 fromDeg(f32 deg) { |
88 | 84 | return deg * sDegToAng; |
89 | 85 | } |
90 | | - f32 degree2() const { |
91 | | - return mVal * sAngToDeg; |
| 86 | + static mAng fromRad(f32 rad) { |
| 87 | + return rad * sRadToAng; |
92 | 88 | } |
93 | 89 |
|
| 90 | + f32 degree() const { |
| 91 | + return (360.0f / 65536.0f) * mVal; |
| 92 | + } |
94 | 93 | f32 radian() const { |
95 | 94 | return ((2.f * M_PI) / 65536.0f) * mVal; |
96 | 95 | } |
97 | 96 |
|
98 | | - f32 radian2() const { |
| 97 | + f32 degree_c() const { |
| 98 | + return mVal * sAngToDeg; |
| 99 | + } |
| 100 | + f32 radian_c() const { |
99 | 101 | return mVal * sAngToRad; |
100 | 102 | } |
101 | 103 |
|
102 | | - static mAng fromRad(f32 rad) { |
103 | | - return rad * sRadToAng; |
| 104 | +public: |
| 105 | + static s16 d2s(f32 deg) { |
| 106 | + return deg * (65536.0f / 360.0f); |
104 | 107 | } |
105 | | - |
106 | | - static f32 ang2deg_c(f32 ang) { |
| 108 | + static f32 s2d(s16 angle) { |
| 109 | + return (360.0f / 65536.0f) * angle; |
| 110 | + } |
| 111 | + static f32 s2d_c(f32 ang) { |
107 | 112 | return ang * sAngToDeg; |
108 | 113 | } |
109 | | - |
110 | | - static f32 rad2deg_c(f32 rad) { |
111 | | - return rad * sRadToDeg; |
| 114 | + static f32 d2s_c(f32 ang) { |
| 115 | + return ang * sDegToAng; |
112 | 116 | } |
113 | 117 |
|
114 | | - static f32 rad2deg(f32 rad) { |
115 | | - return rad * (360.f / (2.f * M_PI)); |
| 118 | + static f32 s2r(s16 angle) { |
| 119 | + return ((2.f * M_PI) / 65536.0f) * angle; |
116 | 120 | } |
117 | | - static f32 deg2rad(f32 deg) { |
118 | | - return deg * ((2.f * M_PI) / 360.f); |
| 121 | + static s16 r2s(f32 rad) { |
| 122 | + return rad * (65536.0f / (2.f * M_PI)); |
119 | 123 | } |
120 | | - static s16 deg2short(f32 deg) { |
121 | | - return deg * (65536.0f / 360.0f); |
| 124 | + static f32 s2r_c(f32 ang) { |
| 125 | + return ang * sAngToRad; |
122 | 126 | } |
123 | | - static f32 short2deg(s16 angle) { |
124 | | - return (360.0f / 65536.0f) * angle; |
| 127 | + static f32 r2s_c(f32 ang) { |
| 128 | + return ang * sRadToAng; |
125 | 129 | } |
126 | | - static f32 short2rad(s16 angle) { |
127 | | - return ((2.f * M_PI) / 65536.0f) * angle; |
| 130 | + |
| 131 | + static f32 d2r(f32 deg) { |
| 132 | + return deg * ((2.f * M_PI) / 360.f); |
128 | 133 | } |
129 | | - static f32 short2norm(s16 angle) { |
130 | | - return 3.0517578E-5f * angle; |
| 134 | + static f32 r2d(f32 rad) { |
| 135 | + return rad * (360.f / (2.f * M_PI)); |
131 | 136 | } |
132 | | - static s16 rad2short(f32 rad) { |
133 | | - return rad * (65536.0f / (2.f * M_PI)); |
| 137 | + static f32 d2r_c(f32 deg) { |
| 138 | + return deg * sDegToRad; |
| 139 | + } |
| 140 | + static f32 r2d_c(f32 rad) { |
| 141 | + return rad * sRadToDeg; |
134 | 142 | } |
135 | 143 |
|
136 | | - static f32 deg2rad_c(f32 deg) { |
137 | | - return deg * sDegToRad; |
| 144 | + static f32 s2n(s16 angle) { |
| 145 | + return 3.0517578E-5f * angle; |
138 | 146 | } |
139 | 147 |
|
140 | 148 | s16 mVal; |
141 | 149 |
|
142 | | - static const mAng Zero() { |
143 | | - return 0; |
144 | | - } |
145 | | - |
146 | 150 | private: |
147 | 151 | static const f32 sHalfCircleDeg; |
148 | 152 | static const f32 sAngToDeg; |
@@ -197,16 +201,6 @@ class mAng3_c { |
197 | 201 | set(0, 0, 0); |
198 | 202 | } |
199 | 203 |
|
200 | | - // TODO - This is the only way I could get the regswap to be fixed.. |
201 | | - // Found with the pattern mAng3_c.y += cM::rndFX() |
202 | | - void addY(f32 val) { |
203 | | - y.mVal += (s16)val; |
204 | | - } |
205 | | - |
206 | | - void addX(const s32 &fx) { |
207 | | - x += fx; |
208 | | - } |
209 | | - |
210 | 204 | mAng x, y, z; |
211 | 205 |
|
212 | 206 | static mAng3_c Zero; |
|
0 commit comments