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_lib.hpp>
4#include <nw4r/math.h>
5#include <lib/MSL/arith.h>
6
7#define DEG_TO_ANGLE(x) (0x10000 * x / 360)
8#define ANGLE_360_DIV(x) (0x10000 / x)
9
10/// @brief A one-dimensional short angle vector.
11/// @ingroup mlib
12struct mAng {
13
14 /// @brief Constructs an empty vector.
15 mAng() {}
16
17 /// @brief Constructs a vector from a short value.
18 mAng(s16 x) : mAngle(x) {}
19
20 /// @brief Assignment operator from a short value.
21 mAng *operator=(s16 ang) {
22 mAngle = ang;
23 return this;
24 }
25
26 operator s16() { return mAngle; }
27
28 BOOL chase(short target, short step) {
29 return sLib::chase(&mAngle, target, step);
30 }
31
32 BOOL chaseAngle(short target, short step) {
33 return sLib::chaseAngle(&mAngle, target, step);
34 }
35
36 int abs() const {
37 return ::abs(mAngle);
38 }
39
40 /// @brief Augmented addition operator.
41 mAng &operator+=(const mAng &v) { mAngle += v.mAngle; return *this; }
42
43 /// @brief Augmented subtraction operator.
44 mAng &operator-=(const mAng &v) { mAngle -= v.mAngle; return *this; }
45
46 /// @brief Positive operator.
47 mAng operator+() const { return *this; }
48
49 /// @brief Negative operator.
50 mAng operator-() const { return mAng(-mAngle); }
51
52 /// @brief Addition operator.
53 mAng operator+(const mAng &v) const { return mAng(mAngle + v.mAngle); }
54
55 /// @brief Subtraction operator.
56 mAng operator-(const mAng &v) const { return mAng(mAngle - v.mAngle); }
57
58 /// @brief Computes the sine of the angle.
59 float sin() const { return nw4r::math::SinIdx(mAngle); }
60
61 /// @brief Computes the cosine of the angle.
62 float cos() const { return nw4r::math::CosIdx(mAngle); }
63
64 s16 mAngle; ///< The rotation.
65
66 static float AngleToDegreeCoefficient;
67 static float DegreeToAngleCoefficient;
68};
69
70/// @brief A three-dimensional short angle vector.
71/// @ingroup mlib
72class mAng3_c {
73public:
74
75 /// @brief Constructs an empty vector.
77
78 /// @brief Constructs a vector from a short array.
79 mAng3_c(const s16 *p) { x = p[0]; y = p[1]; z = p[2]; }
80
81 /// @brief Constructs a vector from three short values.
82 mAng3_c(s16 fx, s16 fy, s16 fz) { x = fx; y = fy; z = fz; }
83
84 static mAng3_c onlyY(s16 fy) {
85 mAng3_c tmp;
86 tmp.y = fy; tmp.x = tmp.z = mAng(0);
87 return tmp;
88 }
89
90 /// @brief Constructs a vector from three mAng values.
91 mAng3_c(mAng fx, mAng fy, mAng fz) : x(fx), y(fy), z(fz) {}
92
93 /// @brief Copy constructor.
94 mAng3_c(const mAng3_c &v) : x(v.x), y(v.y), z(v.z) {}
95
96 mAng3_c *operator=(const mAng3_c &v) {
97 x = v.x;
98 y = v.y;
99 z = v.z;
100 return this;
101 }
102
103 void set(const mAng3_c &v) { x = v.x; y = v.y; z = v.z; }
104
105 void set(s16 fx, s16 fy, s16 fz) {
106 x = fx;
107 y = fy;
108 z = fz;
109 }
110
111 /// @brief Augmented addition operator.
112 mAng3_c &operator+=(const mAng3_c &v) { x += v.x; y += v.y; z += v.z; return *this; }
113
114 /// @brief Augmented subtraction operator.
115 mAng3_c &operator-=(const mAng3_c &v) { x -= v.x; y -= v.y; z -= v.z; return *this; }
116
117 /// @brief Positive operator.
118 mAng3_c operator+() const { return *this; }
119
120 /// @brief Negative operator.
121 mAng3_c operator-() const { return mAng3_c(-x, -y, -z); }
122
123 /// @brief Addition operator.
124 mAng3_c operator+(const mAng3_c &v) const { return mAng3_c(x + v.x, y + v.y, z + v.z); }
125
126 /// @brief Subtraction operator.
127 mAng3_c operator-(const mAng3_c &v) const { return mAng3_c(x - v.x, y - v.y, z - v.z); }
128
129 mAng x; ///< The rotation on the X axis.
130 mAng y; ///< The rotation on the Y axis.
131 mAng z; ///< The rotation on the Z axis.
132
133 static mAng3_c Zero; ///< The null rotation vector.
134 static mAng3_c Ex; ///< The unit rotation vector for the X axis.
135 static mAng3_c Ey; ///< The unit rotation vector for the Y axis.
136 static mAng3_c Ez; ///< The unit rotation vector for the Z axis.
137};
A three-dimensional short angle vector.
Definition m_angle.hpp:72
mAng3_c()
Constructs an empty vector.
Definition m_angle.hpp:76
mAng3_c operator+(const mAng3_c &v) const
Addition operator.
Definition m_angle.hpp:124
mAng3_c operator+() const
Positive operator.
Definition m_angle.hpp:118
static mAng3_c Ez
The unit rotation vector for the Z axis.
Definition m_angle.hpp:136
mAng3_c & operator-=(const mAng3_c &v)
Augmented subtraction operator.
Definition m_angle.hpp:115
static mAng3_c Ey
The unit rotation vector for the Y axis.
Definition m_angle.hpp:135
mAng3_c operator-(const mAng3_c &v) const
Subtraction operator.
Definition m_angle.hpp:127
mAng3_c(const mAng3_c &v)
Copy constructor.
Definition m_angle.hpp:94
mAng y
The rotation on the Y axis.
Definition m_angle.hpp:130
mAng3_c & operator+=(const mAng3_c &v)
Augmented addition operator.
Definition m_angle.hpp:112
mAng z
The rotation on the Z axis.
Definition m_angle.hpp:131
static mAng3_c Zero
The null rotation vector.
Definition m_angle.hpp:133
mAng3_c(s16 fx, s16 fy, s16 fz)
Constructs a vector from three short values.
Definition m_angle.hpp:82
static mAng3_c Ex
The unit rotation vector for the X axis.
Definition m_angle.hpp:134
mAng3_c operator-() const
Negative operator.
Definition m_angle.hpp:121
mAng x
The rotation on the X axis.
Definition m_angle.hpp:129
mAng3_c(mAng fx, mAng fy, mAng fz)
Constructs a vector from three mAng values.
Definition m_angle.hpp:91
mAng3_c(const s16 *p)
Constructs a vector from a short array.
Definition m_angle.hpp:79
BOOL chaseAngle(s16 *value, s16 target, s16 step)
Moves value towards target by a fixed step amount.
Definition s_lib.cpp:138
BOOL chase(s16 *value, s16 target, s16 step)
Moves value towards target by a fixed step amount.
Definition s_lib.cpp:122
A one-dimensional short angle vector.
Definition m_angle.hpp:12
mAng & operator+=(const mAng &v)
Augmented addition operator.
Definition m_angle.hpp:41
mAng()
Constructs an empty vector.
Definition m_angle.hpp:15
mAng operator-() const
Negative operator.
Definition m_angle.hpp:50
float cos() const
Computes the cosine of the angle.
Definition m_angle.hpp:62
float sin() const
Computes the sine of the angle.
Definition m_angle.hpp:59
s16 mAngle
The rotation.
Definition m_angle.hpp:64
mAng * operator=(s16 ang)
Assignment operator from a short value.
Definition m_angle.hpp:21
mAng & operator-=(const mAng &v)
Augmented subtraction operator.
Definition m_angle.hpp:44
mAng(s16 x)
Constructs a vector from a short value.
Definition m_angle.hpp:18
mAng operator-(const mAng &v) const
Subtraction operator.
Definition m_angle.hpp:56
mAng operator+() const
Positive operator.
Definition m_angle.hpp:47
mAng operator+(const mAng &v) const
Addition operator.
Definition m_angle.hpp:53