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