forked from zeldaret/ss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathm_vec.h
More file actions
334 lines (277 loc) · 7.36 KB
/
m_vec.h
File metadata and controls
334 lines (277 loc) · 7.36 KB
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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#ifndef M_VEC_H
#define M_VEC_H
#include "c/c_math.h"
#include "common.h"
#include "egg/math/eggMath.h"
#include "egg/math/eggVector.h"
#include "nw4r/math/math_arithmetic.h"
#include "nw4r/math/math_types.h"
#include "nw4r/types_nw4r.h"
#include "rvl/MTX/vec.h"
class mAng;
class mAng3_c;
class mVec3_c : public EGG::Vector3f {
public:
/// @brief Constructs an empty vector.
mVec3_c() {}
~mVec3_c() {}
/// @brief Constructs a vector from a float array.
mVec3_c(const f32 *p) {
x = p[0];
y = p[1];
z = p[2];
}
mVec3_c(const mVec3_c &other) {
set(other.x, other.y, other.z);
}
mVec3_c(f32 fx, f32 fy, f32 fz) {
set(fx, fy, fz);
}
// ?? Sometimes Works
void copyFrom(const Vec *pV) {
set(pV->x, pV->y, pV->z);
}
/// @brief Assignment operator
mVec3_c &operator=(const mVec3_c &r) {
set(r.x, r.y, r.z);
return *this;
}
/// @brief Assignment operator
mVec3_c &operator=(const EGG::Vector3f &r) {
x = r.x;
y = r.y;
z = r.z;
return *this;
}
/// @brief Assignment operator
mVec3_c &operator=(const nw4r::math::VEC3 &r) {
x = r.x;
y = r.y;
z = r.z;
return *this;
}
/// @brief Constructs a new vector from an existing vector from the MTX library.
mVec3_c(const Vec &v) {
x = v.x;
y = v.y;
z = v.z;
}
/// @brief Constructs a new vector from an existing vector from the nw4r::math library.
mVec3_c(const nw4r::math::VEC3 &v) {
set(v.x, v.y, v.z);
}
/// @brief Constructs a new vector from an existing vector from the EGG library.
mVec3_c(const EGG::Vector3f &v) {
set(v.x, v.y, v.z);
}
/// @brief Float cast operator.
operator f32 *() {
return &x;
}
/// @brief Const float cast operator.
operator const f32 *() const {
return &x;
}
/// @brief Vec cast operator.
operator Vec *() {
return (Vec *)&x;
}
/// @brief Vec cast operator.
operator Vec() const {
return *(Vec *)&x;
}
/// @brief Vector3f cast operator.
operator EGG::Vector3f *() {
return (EGG::Vector3f *)&x;
}
/// @brief Const Vec cast operator.
operator const Vec *() const {
return (const Vec *)&x;
}
/// @brief nw4r::math::VEC3 cast operator.
operator nw4r::math::VEC3 *() {
return (nw4r::math::VEC3 *)&x;
}
/// @brief Const nw4r::math::VEC3 cast operator.
operator const nw4r::math::VEC3 *() const {
return (const nw4r::math::VEC3 *)&x;
}
/// @brief Augmented subtraction operator.
mVec3_c &operator+=(const mVec3_c &v) {
x += v.x;
y += v.y;
z += v.z;
return *this;
}
/// @brief Augmented subtraction operator.
mVec3_c &operator-=(const mVec3_c &v) {
x -= v.x;
y -= v.y;
z -= v.z;
return *this;
}
/// @brief Augmented scalar product operator.
mVec3_c &operator*=(f32 f) {
x *= f;
y *= f;
z *= f;
return *this;
}
/// @brief Augmented scalar division operator.
mVec3_c &operator/=(f32 f) {
return operator*=(1.0f / f);
}
/// @brief Positive operator.
mVec3_c operator+() const {
return *this;
}
mVec3_c operator-(f32 f) const {
return mVec3_c(x - f, y - f, z - f);
}
mVec3_c operator+(f32 f) const {
return mVec3_c(x + f, y + f, z + f);
}
mVec3_c &operator-=(f32 f) {
x -= f;
y -= f;
z -= f;
return *this;
}
mVec3_c &operator+=(f32 f) {
x += f;
y += f;
z += f;
return *this;
}
/// @brief Negative operator.
mVec3_c operator-() const {
return mVec3_c(-x, -y, -z);
}
/// @brief Addition operator.
mVec3_c operator+(const mVec3_c &v) const {
return mVec3_c(x + v.x, y + v.y, z + v.z);
}
/// @brief Subtraction operator.
mVec3_c operator-(const mVec3_c &v) const {
return mVec3_c(x - v.x, y - v.y, z - v.z);
}
/// @brief Scalar product operator.
mVec3_c operator*(f32 f) const {
return mVec3_c(x * f, y * f, z * f);
}
friend mVec3_c operator*(f32 f, const mVec3_c &v) {
return mVec3_c(v.x * f, v.y * f, v.z * f);
}
/// @brief Scalar division operator.
mVec3_c operator/(f32 f) const {
f32 r = 1.0f / f;
return operator*(r);
}
/// @brief Equality operator.
bool operator==(const mVec3_c &v) const {
return x == v.x && y == v.y && z == v.z;
}
/// @brief Inequality operator.
bool operator!=(const mVec3_c &v) const {
return x != v.x || y != v.y || z != v.z;
}
f32 normalize();
bool normalizeRS();
static mVec3_c createProjectionXZ(const mAng3_c &ang, f32 scalar);
inline f32 mag() const {
return VECMag(*this);
}
f32 distance(const mVec3_c &to) const {
return EGG::Math<f32>::sqrt(PSVECSquareDistance(*this, to));
}
f32 squareDistance(const mVec3_c &to) const {
return VEC3DistSq(*this, to);
}
f32 squareMagXZ() const {
return x * x + z * z;
}
f32 squareMagXY() const {
return x * x + y * y;
}
f32 squareDistanceToXZ(const mVec3_c &other) const {
return (*this - other).squareMagXZ();
}
void rotX(const mAng &angle);
void rotY(const mAng &angle);
void rotZ(const mAng &angle);
void fromXY(const mAng &angleX, const mAng &angleY, f32);
void CopyTo(Vec *p) const {
p->x = x;
p->y = y;
p->z = z;
}
f32 inprodXZ(const mVec3_c &other) const {
return x * other.x + z * other.z;
}
f32 getSquareMag() const {
return VEC3LenSq(*this);
}
f32 absXZ() const {
return EGG::Math<f32>::sqrt(squareMagXZ());
}
f32 absXZTo(const mVec3_c &other) const {
return EGG::Math<f32>::sqrt(squareDistanceToXZ(other));
}
s16 atan2sX_Z() const {
return cM::atan2s(x, z);
}
s16 atan2snY_XZ() const {
return cM::atan2s(-y, absXZ());
}
s16 atan2sY_XZ() const {
return cM::atan2s(y, absXZ());
}
f32 angle(const mVec3_c &other) const {
return EGG::Vector3f::angle(other);
}
static mVec3_c Zero;
static mVec3_c Ex;
static mVec3_c Ey;
static mVec3_c Ez;
};
class mVec2_c : public EGG::Vector2f {
public:
mVec2_c() {}
~mVec2_c() {}
/// @brief Assignment operator
mVec2_c &operator=(const mVec2_c &r) {
set(r.x, r.y);
return *this;
}
mVec2_c(const mVec2_c &other) {
set(other.x, other.y);
}
mVec2_c(const EGG::Vector2f &other) {
set(other.x, other.y);
}
mVec2_c(const nw4r::math::VEC2 &other) {
set(other.x, other.y);
}
mVec2_c(f32 fx, f32 fy) {
set(fx, fy);
}
s16 ang() const {
return cM::atan2s(x, y);
}
s16 ang2() const {
return cM::atan2s(y, x);
}
mVec2_c operator*(f32 f) const {
return mVec2_c(x * f, y * f);
}
mVec2_c operator+(const mVec2_c &v) const {
return mVec2_c(x + v.x, y + v.y);
}
mVec2_c operator-(const mVec2_c &v) const {
return mVec2_c(x - v.x, y - v.y);
}
f32 squareDistanceTo(const mVec2_c &other) const {
return (*this - other).squaredLength();
}
};
#endif