1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
/**
* c_angle.cpp
*
*/
#include "SSystem/SComponent/c_angle.h"
extern f32 cM_atan2f(f32, f32);
const cSAngle cSAngle::_0(static_cast<s16>(0));
const cSAngle cSAngle::_1(static_cast<s16>(0xb6));
const cSAngle cSAngle::_90(static_cast<s16>(0x4000));
const cSAngle cSAngle::_180(static_cast<s16>(-0x8000));
const cSAngle cSAngle::_270(static_cast<s16>(-0x4000));
#ifdef __MWERKS__
cSAngle::cSAngle(const cSAngle& angle) {
Val(angle);
}
#endif
cSAngle::cSAngle(s16 angle) {
Val(angle);
}
cSAngle::cSAngle(f32 angle) {
Val(angle);
}
void cSAngle::Val(const cSAngle& other) {
mAngle = other.mAngle;
}
void cSAngle::Val(s16 val) {
mAngle = val;
}
void cSAngle::Val(f32 degree) {
mAngle = cAngle::Degree_to_SAngle(degree);
}
f32 cSAngle::Degree() const {
return cAngle::SAngle_to_Degree(mAngle);
}
f32 cSAngle::Radian() const {
return cAngle::SAngle_to_Radian(mAngle);
}
f32 cSAngle::Norm() const {
return cAngle::SAngle_to_Normal(mAngle);
}
s16 cSAngle::Abs() const {
return mAngle >= 0 ? mAngle : -mAngle;
}
s16 cSAngle::Inv() const {
return mAngle - 0x8000;
}
f32 cSAngle::Sin() const {
return sin(Radian());
}
f32 cSAngle::Cos() const {
return cos(Radian());
}
cSAngle cSAngle::operator-() const {
return cSAngle(static_cast<s16>(-mAngle));
}
cSAngle cSAngle::operator+(const cSAngle& other) const {
return cSAngle(static_cast<s16>(mAngle + other.mAngle));
}
cSAngle cSAngle::operator-(const cSAngle& other) const {
return cSAngle(static_cast<s16>(mAngle - other.mAngle));
}
void cSAngle::operator+=(const cSAngle& other) {
mAngle += other.mAngle;
}
void cSAngle::operator-=(const cSAngle& other) {
mAngle -= other.mAngle;
}
cSAngle cSAngle::operator+(s16 other) const {
return cSAngle(static_cast<s16>(mAngle + other));
}
cSAngle cSAngle::operator-(s16 other) const {
return cSAngle(static_cast<s16>(mAngle - other));
}
void cSAngle::operator+=(s16 other) {
mAngle += other;
}
cSAngle cSAngle::operator*(f32 f1) const {
return cSAngle(static_cast<s16>(mAngle * f1));
}
void cSAngle::operator*=(f32 f1) {
mAngle *= f1;
}
cSAngle operator+(s16 other, const cSAngle& angle) {
return cSAngle(static_cast<s16>(other + angle.Val()));
}
cSAngle operator-(s16 other, const cSAngle& angle) {
return cSAngle(static_cast<s16>(other - angle.Val()));
}
cDegree::cDegree(f32 f) {
Val(f);
}
cDegree& cDegree::Formal() {
mDegree = cAngle::Adjust<f32>(mDegree, -180.0f, 180.0f);
return *this;
}
void cDegree::Val(f32 f) {
mDegree = f;
Formal();
}
f32 cDegree::Radian() const {
return cAngle::Degree_to_Radian(mDegree);
}
f32 cDegree::Sin() const {
return sin(Radian());
}
f32 cDegree::Cos() const {
return cos(Radian());
}
f32 cDegree::Tan() const {
return tan(Radian());
}
cSPolar::cSPolar(const cXyz& xyz) {
Val(xyz);
}
cSPolar& cSPolar::Formal() {
if (mRadial < 0.0f) {
mRadial = -mRadial;
cSAngle tmp(static_cast<s16>(-0x8000));
mAngle1.Val(tmp - mAngle1);
mAngle2.Val(mAngle2.Inv());
}
if (mAngle1.Val() < 0 && mAngle1.Val() != -0x8000) {
mAngle1.Val(-mAngle1);
mAngle2.Val(mAngle2.Inv());
}
return *this;
}
void cSPolar::Val(f32 f, s16 s1, s16 s2) {
mRadial = f;
mAngle1 = cSAngle(s1);
mAngle2 = cSAngle(s2);
Formal();
}
inline double square(f32 f) {
return f * f;
}
void cSPolar::Val(const cXyz& xyz) {
f32 x, y, z, tmp4;
x = xyz.x;
y = xyz.y;
z = xyz.z;
double tmp = square(z) + square(x);
double tmp2 = square(y) + tmp;
tmp4 = (tmp > 0.0) ? (f32)sqrt(tmp) : 0.0f;
mRadial = (tmp2 > 0.0) ? (f32)sqrt(tmp2) : 0.0f;
mAngle1.Val(cAngle::Radian_to_SAngle(cM_atan2f(tmp4, y)));
mAngle2.Val(cAngle::Radian_to_SAngle(cM_atan2f(x, z)));
Formal();
}
cXyz cSPolar::Xyz() const {
f32 ang1Cos;
f32 ang2Cos;
f32 ang1Sin = mRadial * (f32)sin(mAngle1.Radian());
ang2Cos = (f32)cos(mAngle2.Radian());
ang1Cos = mRadial * (f32)cos(mAngle1.Radian());
f32 ang2Sin = sin(mAngle2.Radian());
return cXyz(ang1Sin * ang2Sin, ang1Cos, ang1Sin * ang2Cos);
}
void cSPolar::Globe(cSGlobe* globe) const {
globe->Val(mRadial, 0x4000 - mAngle1.Val(), mAngle2.Val());
}
#ifdef __MWERKS__
cSGlobe::cSGlobe(const cSGlobe& other) {
Val(other);
}
#endif
cSGlobe::cSGlobe(f32 f, s16 s1, s16 s2) {
Val(f, s1, s2);
}
cSGlobe::cSGlobe(f32 f, const cSAngle& a1, const cSAngle& a2) {
Val(f, a1, a2);
}
cSGlobe::cSGlobe(const cXyz& xyz) {
Val(xyz);
}
cSGlobe& cSGlobe::Formal() {
if (mRadius < 0.0f) {
mRadius = -mRadius;
mInclination = -mInclination;
mAzimuth.Val(mAzimuth.Inv());
}
if (mInclination.Val() < -0x4000 || 0x4000 < mInclination.Val()) {
mInclination = cSAngle((s16)-0x8000) - mInclination;
mAzimuth.Val(mAzimuth.Inv());
}
return *this;
}
void cSGlobe::Val(const cSGlobe& other) {
mRadius = other.mRadius;
mInclination = other.mInclination;
mAzimuth = other.mAzimuth;
Formal();
}
void cSGlobe::Val(f32 f, s16 s1, s16 s2) {
mRadius = f;
mInclination = cSAngle(s1);
mAzimuth = cSAngle(s2);
Formal();
}
void cSGlobe::Val(f32 f, const cSAngle& a1, const cSAngle& a2) {
mRadius = f;
mInclination = cSAngle(a1.Val());
mAzimuth = cSAngle(a2.Val());
Formal();
}
void cSGlobe::Val(const cXyz& xyz) {
cSPolar csp(xyz);
csp.Globe(this);
Formal();
}
cXyz cSGlobe::Xyz() const {
cSPolar csp;
Polar(&csp);
return csp.Xyz();
}
void cSGlobe::Polar(cSPolar* csp) const {
csp->Val(mRadius, 0x4000 - mInclination.Val(), mAzimuth.Val());
}
cXyz cSGlobe::Norm() const {
cSGlobe glob(1.0f, mInclination, mAzimuth);
return glob.Xyz();
}
cSGlobe& cSGlobe::Invert() {
mRadius = -mRadius;
return Formal();
}
|