NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
m_vec.hpp
1#pragma once
2#include <nw4r/math.h>
3#include <game/mLib/m_angle.hpp>
4#include <lib/egg/math/eggVector.h>
6
7/// @brief A two-dimensional floating point vector.
8/// @ingroup mlib
9class mVec2_c : public EGG::Vector2f {
10public:
11
12 /// @brief Constructs an empty vector.
14
15 ~mVec2_c() {}
16
17 /// @brief Constructs a vector from a float array.
18 mVec2_c(const f32 *p) { x = p[0]; y = p[1]; }
19
20 /// @brief Constructs a vector from two floating point values.
21 mVec2_c(f32 fx, f32 fy) { set(fx, fy); }
22
23 /// @brief Copy constructor.
24 mVec2_c(const mVec2_c &v) { set(v.x, v.y); }
25
26 void set(float x, float y) {
27 this->x = x;
28 this->y = y;
29 }
30
31 /// @brief Increments the X coordinate.
32 /// @param x The value to increment by.
33 void incX(float x) { this->x += x; }
34
35 /// @brief Increments the Y coordinate.
36 /// @param y The value to increment by.
37 void incY(float y) { this->y += y; }
38
39 // mVec2_c &operator=(const mVec2_c &v) { set(v.x, v.y); return *this; }
40 mVec2_c &operator=(const mVec2_c &v) { x = v.x; y = v.y; return *this; }
41
42 /// @brief Float cast operator.
43 operator f32*() { return &x; }
44
45 /// @brief Const float cast operator.
46 operator const f32*() const { return &x; }
47
48 /// @brief Vec2 cast operator.
49 operator Vec2*() { return (Vec2*)&x; }
50
51 /// @brief Const Vec2 cast operator.
52 operator const Vec2*() const { return (const Vec2*)&x; }
53
54 /// @brief nw4r::math::VEC2 cast operator.
55 operator nw4r::math::VEC2*() { return (nw4r::math::VEC2*)&x; }
56
57 /// @brief Const nw4r::math::VEC2 cast operator.
58 operator const nw4r::math::VEC2*() const { return (const nw4r::math::VEC2*)&x; }
59
60 /// @brief Augmented addition operator.
61 mVec2_c &operator+=(const mVec2_c &v) { x += v.x; y += v.y; return *this; }
62
63 /// @brief Augmented subtraction operator.
64 mVec2_c &operator-=(const mVec2_c &v) { x -= v.x; y -= v.y; return *this; }
65
66 /// @brief Augmented scalar product operator.
67 mVec2_c &operator*=(f32 f) { x *= f; y *= f; return *this; }
68
69 /// @brief Augmented scalar division operator.
70 mVec2_c &operator/=(f32 f) { return operator*=(1.0f / f); }
71
72 /// @brief Positive operator.
73 mVec2_c operator+() const { return *this; }
74
75 /// @brief Negative operator.
76 mVec2_c operator-() const { return mVec2_c(-x, -y); }
77
78 /// @brief Addition operator.
79 mVec2_c operator+(const mVec2_c &v) const { return mVec2_c(x + v.x, y + v.y); }
80
81 /// @brief Subtraction operator.
82 mVec2_c operator-(const mVec2_c &v) const { return mVec2_c(x - v.x, y - v.y); }
83
84 /// @brief Scalar product operator.
85 mVec2_c operator*(f32 f) const { return mVec2_c(f * x, f * y); }
86
87 /// @brief Scalar division operator.
88 mVec2_c operator/(f32 f) const { f32 r = 1.0f / f; return operator*(r); }
89
90 /// @brief Equality operator.
91 bool operator==(const mVec2_c &v) const { return x == v.x && y == v.y; }
92
93 /// @brief Inequality operator.
94 bool operator!=(const mVec2_c &v) const { return x != v.x || y != v.y; }
95};
96
97/// @brief A three-dimensional floating point vector.
98/// @ingroup mlib
99/// @todo Add EGG::vector3f operators.
100class mVec3_c : public EGG::Vector3f {
101public:
102
103 /// @brief Constructs an empty vector.
105
106 ~mVec3_c() {}
107
108 /// @brief Constructs a vector from a float array.
109 mVec3_c(const f32 *p) { x = p[0]; y = p[1]; z = p[2]; }
110
111 /// @brief Constructs a vector from three floating point values.
112 mVec3_c(f32 fx, f32 fy, f32 fz) { x = fx; y = fy; z = fz; }
113
114 /// @brief Constructs a new vector from an existing vector from the MTX library.
115 mVec3_c(const Vec &v) { x = v.x; y = v.y; z = v.z; }
116
117 /// @brief Copy constructor.
118 mVec3_c(const mVec3_c &v) { set(v.x, v.y, v.z); }
119
120 /// @brief Constructs a new vector from an existing vector from the NW4R library.
121 mVec3_c(const nw4r::math::VEC3 &v) { set(v.x, v.y, v.z); }
122
123 /// @brief Copy constructor with a different Z value.
124 mVec3_c(const mVec3_c &v, float fz) { x = v.x; y = v.y; z = fz; }
125 mVec3_c(const mVec2_c &v, float fz) { x = v.x; y = v.y; z = fz; }
126
127 /// @brief Assignment operator.
128 mVec3_c &operator=(const mVec3_c &v) { x = v.x; y = v.y; z = v.z; return *this; }
129 mVec3_c &operator=(const nw4r::math::VEC3 &v) { x = v.x; y = v.y; z = v.z; return *this; }
130
131 /// @brief Float cast operator.
132 operator f32*() { return &x; }
133
134 /// @brief Const float cast operator.
135 operator const f32*() const { return &x; }
136
137 /// @brief Vec cast operator.
138 operator Vec*() { return (Vec*)&x; }
139
140 /// @brief Const Vec cast operator.
141 operator const Vec*() const { return (const Vec*)&x; }
142
143 /// @brief nw4r::math::VEC3 cast operator.
144 operator nw4r::math::VEC3*() { return (nw4r::math::VEC3*)&x; }
145
146 /// @brief Const nw4r::math::VEC3 cast operator.
147 operator const nw4r::math::VEC3*() const { return (const nw4r::math::VEC3*)&x; }
148
149 /// @brief Augmented addition operator.
150 mVec3_c &operator+=(const mVec3_c &v) { x += v.x; y += v.y; z += v.z; return *this; }
151
152 /// @brief Augmented subtraction operator.
153 mVec3_c &operator-=(const mVec3_c &v) { x -= v.x; y -= v.y; z -= v.z; return *this; }
154
155 /// @brief Augmented scalar product operator.
156 mVec3_c &operator*=(f32 f) { x *= f; y *= f; z *= f; return *this; }
157
158 /// @brief Augmented scalar division operator.
159 mVec3_c &operator/=(f32 f) { return operator*=(1.0f / f); }
160
161 /// @brief Positive operator.
162 mVec3_c operator+() const { return *this; }
163
164 /// @brief Negative operator.
165 mVec3_c operator-() const { return mVec3_c(-x, -y, -z); }
166
167 /// @brief Addition operator.
168 mVec3_c operator+(const mVec3_c &v) const { return mVec3_c(x + v.x, y + v.y, z + v.z); }
169
170 /// @brief Subtraction operator.
171 mVec3_c operator-(const mVec3_c &v) const { return mVec3_c(x - v.x, y - v.y, z - v.z); }
172
173 /// @brief Scalar product operator.
174 mVec3_c operator*(f32 f) const { return mVec3_c(f * x, f * y, f * z); }
175
176 /// @brief Scalar division operator.
177 mVec3_c operator/(f32 f) const { f32 r = 1.0f / f; return operator*(r); }
178
179 /// @brief Equality operator.
180 bool operator==(const mVec3_c &v) const { return x == v.x && y == v.y && z == v.z; }
181
182 /// @brief Inequality operator.
183 bool operator!=(const mVec3_c &v) const { return x != v.x || y != v.y || z != v.z; }
184
185 float xzLen() const {
186 return EGG::Mathf::sqrt(x * x + z * z);
187 }
188
189 short xzAng() const {
190 return cM::atan2s(x, z);
191 }
192
193 float distTo(const mVec3_c &other) const {
194 return EGG::Mathf::sqrt(PSVECSquareDistance((const Vec*) this, (const Vec*) &other));
195 }
196
197 /// @brief Normalizes the vector.
198 /// @return The vector's magnitude.
199 float normalize();
200
201 /// @brief Normalizes the vector.
202 /// @return If the operation was successful.
203 bool normalizeRS();
204
205 void rotX(mAng angle); ///< Rotates the vector on the X axis by the given angle.
206 void rotY(mAng angle); ///< Rotates the vector on the Y axis by the given angle.
207
208 static mVec3_c Zero; ///< The null vector.
209 static mVec3_c Ex; ///< The unit vector for the X axis.
210 static mVec3_c Ey; ///< The unit vector for the Y axis.
211 static mVec3_c Ez; ///< The unit vector for the Z axis.
212};
213
214/// @unofficial
215class mBoundBox {
216public:
217 mBoundBox() {}
218
219 mBoundBox(float t, float b, float l, float r) {
220 set(t, b, l, r);
221 }
222
223 mBoundBox(const mBoundBox &b) {
224 set(b.mOffset.x, b.mOffset.y, b.mSize.x, b.mSize.y);
225 }
226
227 void set(float t, float b, float l, float r) {
228 mOffset.set(t, b);
229 mSize.set(l, r);
230 }
231
232 mVec2_c withPos(const mVec3_c &pos) const {
233 mVec2_c res;
234 res.x = pos.x + mOffset.x - mSize.x;
235 res.y = pos.y + mOffset.y + mSize.y;
236 return res;
237 }
238
239 mVec2_c getSize() const {
240 return mSize;
241 }
242
243 mVec2_c mOffset, mSize;
244};
A two-dimensional floating point vector.
Definition eggVector.h:9
A three-dimensional floating point vector.
Definition eggVector.h:34
A two-dimensional floating point vector.
Definition m_vec.hpp:9
mVec2_c(const mVec2_c &v)
Copy constructor.
Definition m_vec.hpp:24
mVec2_c operator+() const
Positive operator.
Definition m_vec.hpp:73
bool operator!=(const mVec2_c &v) const
Inequality operator.
Definition m_vec.hpp:94
mVec2_c & operator+=(const mVec2_c &v)
Augmented addition operator.
Definition m_vec.hpp:61
mVec2_c operator+(const mVec2_c &v) const
Addition operator.
Definition m_vec.hpp:79
mVec2_c()
Constructs an empty vector.
Definition m_vec.hpp:13
mVec2_c & operator/=(f32 f)
Augmented scalar division operator.
Definition m_vec.hpp:70
mVec2_c operator/(f32 f) const
Scalar division operator.
Definition m_vec.hpp:88
bool operator==(const mVec2_c &v) const
Equality operator.
Definition m_vec.hpp:91
mVec2_c(const f32 *p)
Constructs a vector from a float array.
Definition m_vec.hpp:18
void incY(float y)
Increments the Y coordinate.
Definition m_vec.hpp:37
mVec2_c(f32 fx, f32 fy)
Constructs a vector from two floating point values.
Definition m_vec.hpp:21
mVec2_c & operator*=(f32 f)
Augmented scalar product operator.
Definition m_vec.hpp:67
mVec2_c operator*(f32 f) const
Scalar product operator.
Definition m_vec.hpp:85
mVec2_c & operator-=(const mVec2_c &v)
Augmented subtraction operator.
Definition m_vec.hpp:64
mVec2_c operator-(const mVec2_c &v) const
Subtraction operator.
Definition m_vec.hpp:82
mVec2_c operator-() const
Negative operator.
Definition m_vec.hpp:76
void incX(float x)
Increments the X coordinate.
Definition m_vec.hpp:33
A three-dimensional floating point vector.
Definition m_vec.hpp:100
mVec3_c operator/(f32 f) const
Scalar division operator.
Definition m_vec.hpp:177
static mVec3_c Ex
The unit vector for the X axis.
Definition m_vec.hpp:209
static mVec3_c Ey
The unit vector for the Y axis.
Definition m_vec.hpp:210
mVec3_c(const nw4r::math::VEC3 &v)
Constructs a new vector from an existing vector from the NW4R library.
Definition m_vec.hpp:121
mVec3_c & operator-=(const mVec3_c &v)
Augmented subtraction operator.
Definition m_vec.hpp:153
mVec3_c operator*(f32 f) const
Scalar product operator.
Definition m_vec.hpp:174
mVec3_c & operator+=(const mVec3_c &v)
Augmented addition operator.
Definition m_vec.hpp:150
bool normalizeRS()
Normalizes the vector.
Definition m_vec.cpp:26
mVec3_c operator-() const
Negative operator.
Definition m_vec.hpp:165
mVec3_c operator-(const mVec3_c &v) const
Subtraction operator.
Definition m_vec.hpp:171
mVec3_c(const mVec3_c &v, float fz)
Copy constructor with a different Z value.
Definition m_vec.hpp:124
mVec3_c(f32 fx, f32 fy, f32 fz)
Constructs a vector from three floating point values.
Definition m_vec.hpp:112
mVec3_c(const f32 *p)
Constructs a vector from a float array.
Definition m_vec.hpp:109
float normalize()
Normalizes the vector.
Definition m_vec.cpp:17
bool operator==(const mVec3_c &v) const
Equality operator.
Definition m_vec.hpp:180
mVec3_c & operator*=(f32 f)
Augmented scalar product operator.
Definition m_vec.hpp:156
mVec3_c operator+() const
Positive operator.
Definition m_vec.hpp:162
void rotX(mAng angle)
Rotates the vector on the X axis by the given angle.
Definition m_vec.cpp:36
void rotY(mAng angle)
Rotates the vector on the Y axis by the given angle.
Definition m_vec.cpp:45
static mVec3_c Zero
The null vector.
Definition m_vec.hpp:208
mVec3_c & operator/=(f32 f)
Augmented scalar division operator.
Definition m_vec.hpp:159
mVec3_c(const mVec3_c &v)
Copy constructor.
Definition m_vec.hpp:118
bool operator!=(const mVec3_c &v) const
Inequality operator.
Definition m_vec.hpp:183
mVec3_c & operator=(const mVec3_c &v)
Assignment operator.
Definition m_vec.hpp:128
mVec3_c(const Vec &v)
Constructs a new vector from an existing vector from the MTX library.
Definition m_vec.hpp:115
mVec3_c operator+(const mVec3_c &v) const
Addition operator.
Definition m_vec.hpp:168
mVec3_c()
Constructs an empty vector.
Definition m_vec.hpp:104
static mVec3_c Ez
The unit vector for the Z axis.
Definition m_vec.hpp:211
s16 atan2s(float sin, float cos)
Converts a sine and a cosine to an angle in units.
Definition c_math.cpp:167
Definition mtxtypes.h:11