NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
m_vec.hpp
1#pragma once
2#include <lib/nw4r/math/vec.hpp>
3#include <lib/rvl/mtx/vec.h>
4#include <game/mLib/m_angle.hpp>
5#include <lib/egg/math.hpp>
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 nw4r::math::VEC3 {
101public:
102
103 /// @brief Constructs an empty vector.
105
106 /// @brief Constructs a vector from a float array.
107 mVec3_c(const f32 *p) { x = p[0]; y = p[1]; z = p[2]; }
108
109 /// @brief Constructs a vector from three floating point values.
110 mVec3_c(f32 fx, f32 fy, f32 fz) { x = fx; y = fy; z = fz; }
111
112 /// @brief Constructs a new vector from an existing vector from the MTX library.
113 mVec3_c(const Vec &v) { x = v.x; y = v.y; z = v.z; }
114
115 /// @brief Constructs a new vector from an existing vector from the nw4r::math library.
116 mVec3_c(const nw4r::math::VEC3 &v) { x = v.x; y = v.y; z = v.z; }
117
118 /// @brief Float cast operator.
119 operator f32*() { return &x; }
120
121 /// @brief Const float cast operator.
122 operator const f32*() const { return &x; }
123
124 /// @brief Vec cast operator.
125 operator Vec*() { return (Vec*)&x; }
126
127 /// @brief Const Vec cast operator.
128 operator const Vec*() const { return (const Vec*)&x; }
129
130 /// @brief nw4r::math::VEC3 cast operator.
131 operator nw4r::math::VEC3*() { return (nw4r::math::VEC3*)&x; }
132
133 /// @brief Const nw4r::math::VEC3 cast operator.
134 operator const nw4r::math::VEC3*() const { return (const nw4r::math::VEC3*)&x; }
135
136 /// @brief Augmented addition operator.
137 mVec3_c &operator+=(const mVec3_c &v) { x += v.x; y += v.y; z += v.z; return *this; }
138
139 /// @brief Augmented subtraction operator.
140 mVec3_c &operator-=(const mVec3_c &v) { x -= v.x; y -= v.y; z -= v.z; return *this; }
141
142 /// @brief Augmented scalar product operator.
143 mVec3_c &operator*=(f32 f) { x *= f; y *= f; z *= f; return *this; }
144
145 /// @brief Augmented scalar division operator.
146 mVec3_c &operator/=(f32 f) { return operator*=(1.0f / f); }
147
148 /// @brief Positive operator.
149 mVec3_c operator+() const { return *this; }
150
151 /// @brief Negative operator.
152 mVec3_c operator-() const { return mVec3_c(-x, -y, -z); }
153
154 /// @brief Addition operator.
155 mVec3_c operator+(const mVec3_c &v) const { return mVec3_c(x + v.x, y + v.y, z + v.z); }
156
157 /// @brief Subtraction operator.
158 mVec3_c operator-(const mVec3_c &v) const { return mVec3_c(x - v.x, y - v.y, z - v.z); }
159
160 /// @brief Scalar product operator.
161 mVec3_c operator*(f32 f) const { return mVec3_c(f * x, f * y, f * z); }
162
163 /// @brief Scalar division operator.
164 mVec3_c operator/(f32 f) const { f32 r = 1.0f / f; return operator*(r); }
165
166 /// @brief Equality operator.
167 bool operator==(const mVec3_c &v) const { return x == v.x && y == v.y && z == v.z; }
168
169 /// @brief Inequality operator.
170 bool operator!=(const mVec3_c &v) const { return x != v.x || y != v.y || z != v.z; }
171
172 /// @brief Normalizes the vector.
173 /// @return The vector's magnitude.
174 float normalize();
175
176 /// @brief Normalizes the vector.
177 /// @return If the operation was successful.
178 bool normalizeRS();
179
180 void rotX(mAng angle); ///< Rotates the vector on the X axis by the given angle.
181 void rotY(mAng angle); ///< Rotates the vector on the Y axis by the given angle.
182
183 static mVec3_c Zero; ///< The null vector.
184 static mVec3_c Ex; ///< The unit vector for the X axis.
185 static mVec3_c Ey; ///< The unit vector for the Y axis.
186 static mVec3_c Ez; ///< The unit vector for the Z axis.
187};
A two-dimensional floating point vector.
Definition math.hpp:26
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
mVec3_c operator/(f32 f) const
Scalar division operator.
Definition m_vec.hpp:164
static mVec3_c Ex
The unit vector for the X axis.
Definition m_vec.hpp:184
static mVec3_c Ey
The unit vector for the Y axis.
Definition m_vec.hpp:185
mVec3_c(const nw4r::math::VEC3 &v)
Constructs a new vector from an existing vector from the nw4r::math library.
Definition m_vec.hpp:116
mVec3_c & operator-=(const mVec3_c &v)
Augmented subtraction operator.
Definition m_vec.hpp:140
mVec3_c operator*(f32 f) const
Scalar product operator.
Definition m_vec.hpp:161
mVec3_c & operator+=(const mVec3_c &v)
Augmented addition operator.
Definition m_vec.hpp:137
bool normalizeRS()
Normalizes the vector.
Definition m_vec.cpp:27
mVec3_c operator-() const
Negative operator.
Definition m_vec.hpp:152
mVec3_c operator-(const mVec3_c &v) const
Subtraction operator.
Definition m_vec.hpp:158
mVec3_c(f32 fx, f32 fy, f32 fz)
Constructs a vector from three floating point values.
Definition m_vec.hpp:110
mVec3_c(const f32 *p)
Constructs a vector from a float array.
Definition m_vec.hpp:107
float normalize()
Normalizes the vector.
Definition m_vec.cpp:18
bool operator==(const mVec3_c &v) const
Equality operator.
Definition m_vec.hpp:167
mVec3_c & operator*=(f32 f)
Augmented scalar product operator.
Definition m_vec.hpp:143
mVec3_c operator+() const
Positive operator.
Definition m_vec.hpp:149
void rotX(mAng angle)
Rotates the vector on the X axis by the given angle.
Definition m_vec.cpp:37
void rotY(mAng angle)
Rotates the vector on the Y axis by the given angle.
Definition m_vec.cpp:46
static mVec3_c Zero
The null vector.
Definition m_vec.hpp:183
mVec3_c & operator/=(f32 f)
Augmented scalar division operator.
Definition m_vec.hpp:146
bool operator!=(const mVec3_c &v) const
Inequality operator.
Definition m_vec.hpp:170
mVec3_c(const Vec &v)
Constructs a new vector from an existing vector from the MTX library.
Definition m_vec.hpp:113
mVec3_c operator+(const mVec3_c &v) const
Addition operator.
Definition m_vec.hpp:155
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:186
A two-dimensional floating point vector.
Definition vec.h:13
A three-dimensional floating point vector.
Definition vec.h:18
A one-dimensional short angle vector.
Definition m_angle.hpp:8
A three-dimensional floating point vector.
Definition vec.hpp:22