NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
m_angle.hpp
1#pragma once
2#include <types.h>
3#include <game/sLib/s_math.hpp>
5#include <lib/rvl/mtx/vec.h>
6
7extern "C" {
8 int abs(int);
9}
10
11/// @brief A one-dimensional short angle vector.
12/// @ingroup mlib
13struct mAng {
14
15 /// @brief Constructs an empty vector.
16 mAng() {}
17
18 /// @brief Constructs a vector from a short value.
19 mAng(s16 x) : mAngle(x) {}
20
21 operator s16() { return mAngle; }
22
23 bool chase(short target, short step) {
24 return sLib::chase(&mAngle, target, step);
25 }
26
27 mAng abs() const {
28 return mAng(::abs(mAngle));
29 }
30
31 /// @brief Augmented addition operator.
32 mAng &operator+=(const mAng &v) { mAngle += v.mAngle; return *this; }
33
34 /// @brief Augmented subtraction operator.
35 mAng &operator-=(const mAng &v) { mAngle -= v.mAngle; return *this; }
36
37 /// @brief Positive operator.
38 mAng operator+() const { return *this; }
39
40 /// @brief Negative operator.
41 mAng operator-() const { return mAng(-mAngle); }
42
43 /// @brief Addition operator.
44 mAng operator+(const mAng &v) const { return mAng(mAngle + v.mAngle); }
45
46 /// @brief Subtraction operator.
47 mAng operator-(const mAng &v) const { return mAng(mAngle - v.mAngle); }
48
49 /// @brief Equality operator.
50 bool operator==(const mAng &v) const { return mAngle == v.mAngle; }
51
52 /// @brief Inequality operator.
53 bool operator!=(const mAng &v) const { return mAngle != v.mAngle; }
54
55 /// @brief Computes the sine of the angle.
56 float sin() const { return nw4r::math::SinS(mAngle); }
57
58 /// @brief Computes the cosine of the angle.
59 float cos() const { return nw4r::math::CosS(mAngle); }
60
61 s16 mAngle; ///< The rotation.
62};
63
64/// @brief A three-dimensional short angle vector.
65/// @ingroup mlib
66class mAng3_c {
67public:
68
69 /// @brief Constructs an empty vector.
71
72 /// @brief Constructs a vector from a short array.
73 mAng3_c(const s16 *p) { x = p[0]; y = p[1]; z = p[2]; }
74
75 /// @brief Constructs a vector from three short values.
76 mAng3_c(s16 fx, s16 fy, s16 fz) { x = fx; y = fy; z = fz; }
77
78 static mAng3_c onlyY(s16 fy) {
79 mAng3_c tmp;
80 tmp.y = fy; tmp.x = tmp.z = mAng(0);
81 return tmp;
82 }
83
84 /// @brief Constructs a vector from three mAng values.
85 mAng3_c(mAng fx, mAng fy, mAng fz) : x(fx), y(fy), z(fz) {}
86
87 /// @brief Constructs a new vector from an existing vector from the MTX library.
88 mAng3_c(const S16Vec &v) { x = v.x; y = v.y; z = v.z; }
89
90 /// @brief Copy constructor.
91 mAng3_c(const mAng3_c &v) : x(v.x), y(v.y), z(v.z) {}
92
93 mAng3_c *operator=(const mAng3_c &v) {
94 x = v.x;
95 y = v.y;
96 z = v.z;
97 return this;
98 }
99
100 /// @brief Augmented addition operator.
101 mAng3_c &operator+=(const mAng3_c &v) { x += v.x; y += v.y; z += v.z; return *this; }
102
103 /// @brief Augmented subtraction operator.
104 mAng3_c &operator-=(const mAng3_c &v) { x -= v.x; y -= v.y; z -= v.z; return *this; }
105
106 /// @brief Positive operator.
107 mAng3_c operator+() const { return *this; }
108
109 /// @brief Negative operator.
110 mAng3_c operator-() const { return mAng3_c(-x, -y, -z); }
111
112 /// @brief Addition operator.
113 mAng3_c operator+(const mAng3_c &v) const { return mAng3_c(x + v.x, y + v.y, z + v.z); }
114
115 /// @brief Subtraction operator.
116 mAng3_c operator-(const mAng3_c &v) const { return mAng3_c(x - v.x, y - v.y, z - v.z); }
117
118 /// @brief Equality operator.
119 bool operator==(const mAng3_c &v) const { return x == v.x && y == v.y && z == v.z; }
120
121 /// @brief Inequality operator.
122 bool operator!=(const mAng3_c &v) const { return x != v.x || y != v.y || z != v.z; }
123
124 mAng x; ///< The rotation on the X axis.
125 mAng y; ///< The rotation on the Y axis.
126 mAng z; ///< The rotation on the Z axis.
127
128 static mAng3_c Zero; ///< The null rotation vector.
129 static mAng3_c Ex; ///< The unit rotation vector for the X axis.
130 static mAng3_c Ey; ///< The unit rotation vector for the Y axis.
131 static mAng3_c Ez; ///< The unit rotation vector for the Z axis.
132};
A three-dimensional short angle vector.
Definition m_angle.hpp:66
mAng3_c()
Constructs an empty vector.
Definition m_angle.hpp:70
mAng3_c operator+(const mAng3_c &v) const
Addition operator.
Definition m_angle.hpp:113
mAng3_c operator+() const
Positive operator.
Definition m_angle.hpp:107
static mAng3_c Ez
The unit rotation vector for the Z axis.
Definition m_angle.hpp:131
mAng3_c & operator-=(const mAng3_c &v)
Augmented subtraction operator.
Definition m_angle.hpp:104
static mAng3_c Ey
The unit rotation vector for the Y axis.
Definition m_angle.hpp:130
mAng3_c operator-(const mAng3_c &v) const
Subtraction operator.
Definition m_angle.hpp:116
mAng3_c(const mAng3_c &v)
Copy constructor.
Definition m_angle.hpp:91
mAng y
The rotation on the Y axis.
Definition m_angle.hpp:125
mAng3_c & operator+=(const mAng3_c &v)
Augmented addition operator.
Definition m_angle.hpp:101
mAng z
The rotation on the Z axis.
Definition m_angle.hpp:126
static mAng3_c Zero
The null rotation vector.
Definition m_angle.hpp:128
bool operator!=(const mAng3_c &v) const
Inequality operator.
Definition m_angle.hpp:122
mAng3_c(s16 fx, s16 fy, s16 fz)
Constructs a vector from three short values.
Definition m_angle.hpp:76
static mAng3_c Ex
The unit rotation vector for the X axis.
Definition m_angle.hpp:129
mAng3_c operator-() const
Negative operator.
Definition m_angle.hpp:110
mAng x
The rotation on the X axis.
Definition m_angle.hpp:124
bool operator==(const mAng3_c &v) const
Equality operator.
Definition m_angle.hpp:119
mAng3_c(mAng fx, mAng fy, mAng fz)
Constructs a vector from three mAng values.
Definition m_angle.hpp:85
mAng3_c(const s16 *p)
Constructs a vector from a short array.
Definition m_angle.hpp:73
mAng3_c(const S16Vec &v)
Constructs a new vector from an existing vector from the MTX library.
Definition m_angle.hpp:88
float CosS(short ang)
Computes the cosine value.
float SinS(short ang)
Computes the sine value.
A three-dimensional short vector.
Definition vec.h:23
A one-dimensional short angle vector.
Definition m_angle.hpp:13
bool operator==(const mAng &v) const
Equality operator.
Definition m_angle.hpp:50
mAng & operator+=(const mAng &v)
Augmented addition operator.
Definition m_angle.hpp:32
mAng()
Constructs an empty vector.
Definition m_angle.hpp:16
mAng operator-() const
Negative operator.
Definition m_angle.hpp:41
float cos() const
Computes the cosine of the angle.
Definition m_angle.hpp:59
float sin() const
Computes the sine of the angle.
Definition m_angle.hpp:56
s16 mAngle
The rotation.
Definition m_angle.hpp:61
mAng & operator-=(const mAng &v)
Augmented subtraction operator.
Definition m_angle.hpp:35
mAng(s16 x)
Constructs a vector from a short value.
Definition m_angle.hpp:19
mAng operator-(const mAng &v) const
Subtraction operator.
Definition m_angle.hpp:47
mAng operator+() const
Positive operator.
Definition m_angle.hpp:38
bool operator!=(const mAng &v) const
Inequality operator.
Definition m_angle.hpp:53
mAng operator+(const mAng &v) const
Addition operator.
Definition m_angle.hpp:44