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>
4#include <nw4r/math.h>
5
6extern "C" {
7 int abs(int);
8}
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 operator s16() { return mAngle; }
21
22 bool chase(short target, short step) {
23 return sLib::chase(&mAngle, target, step);
24 }
25
26 mAng abs() const {
27 return mAng(::abs(mAngle));
28 }
29
30 /// @brief Augmented addition operator.
31 mAng &operator+=(const mAng &v) { mAngle += v.mAngle; return *this; }
32
33 /// @brief Augmented subtraction operator.
34 mAng &operator-=(const mAng &v) { mAngle -= v.mAngle; return *this; }
35
36 /// @brief Positive operator.
37 mAng operator+() const { return *this; }
38
39 /// @brief Negative operator.
40 mAng operator-() const { return mAng(-mAngle); }
41
42 /// @brief Addition operator.
43 mAng operator+(const mAng &v) const { return mAng(mAngle + v.mAngle); }
44
45 /// @brief Subtraction operator.
46 mAng operator-(const mAng &v) const { return mAng(mAngle - v.mAngle); }
47
48 /// @brief Computes the sine of the angle.
49 float sin() const { return nw4r::math::SinIdx(mAngle); }
50
51 /// @brief Computes the cosine of the angle.
52 float cos() const { return nw4r::math::CosIdx(mAngle); }
53
54 s16 mAngle; ///< The rotation.
55};
56
57/// @brief A three-dimensional short angle vector.
58/// @ingroup mlib
59class mAng3_c {
60public:
61
62 /// @brief Constructs an empty vector.
64
65 /// @brief Constructs a vector from a short array.
66 mAng3_c(const s16 *p) { x = p[0]; y = p[1]; z = p[2]; }
67
68 /// @brief Constructs a vector from three short values.
69 mAng3_c(s16 fx, s16 fy, s16 fz) { x = fx; y = fy; z = fz; }
70
71 static mAng3_c onlyY(s16 fy) {
72 mAng3_c tmp;
73 tmp.y = fy; tmp.x = tmp.z = mAng(0);
74 return tmp;
75 }
76
77 /// @brief Constructs a vector from three mAng values.
78 mAng3_c(mAng fx, mAng fy, mAng fz) : x(fx), y(fy), z(fz) {}
79
80 /// @brief Copy constructor.
81 mAng3_c(const mAng3_c &v) : x(v.x), y(v.y), z(v.z) {}
82
83 mAng3_c *operator=(const mAng3_c &v) {
84 x = v.x;
85 y = v.y;
86 z = v.z;
87 return this;
88 }
89
90 /// @brief Augmented addition operator.
91 mAng3_c &operator+=(const mAng3_c &v) { x += v.x; y += v.y; z += v.z; return *this; }
92
93 /// @brief Augmented subtraction operator.
94 mAng3_c &operator-=(const mAng3_c &v) { x -= v.x; y -= v.y; z -= v.z; return *this; }
95
96 /// @brief Positive operator.
97 mAng3_c operator+() const { return *this; }
98
99 /// @brief Negative operator.
100 mAng3_c operator-() const { return mAng3_c(-x, -y, -z); }
101
102 /// @brief Addition operator.
103 mAng3_c operator+(const mAng3_c &v) const { return mAng3_c(x + v.x, y + v.y, z + v.z); }
104
105 /// @brief Subtraction operator.
106 mAng3_c operator-(const mAng3_c &v) const { return mAng3_c(x - v.x, y - v.y, z - v.z); }
107
108 mAng x; ///< The rotation on the X axis.
109 mAng y; ///< The rotation on the Y axis.
110 mAng z; ///< The rotation on the Z axis.
111
112 static mAng3_c Zero; ///< The null rotation vector.
113 static mAng3_c Ex; ///< The unit rotation vector for the X axis.
114 static mAng3_c Ey; ///< The unit rotation vector for the Y axis.
115 static mAng3_c Ez; ///< The unit rotation vector for the Z axis.
116};
A three-dimensional short angle vector.
Definition m_angle.hpp:59
mAng3_c()
Constructs an empty vector.
Definition m_angle.hpp:63
mAng3_c operator+(const mAng3_c &v) const
Addition operator.
Definition m_angle.hpp:103
mAng3_c operator+() const
Positive operator.
Definition m_angle.hpp:97
static mAng3_c Ez
The unit rotation vector for the Z axis.
Definition m_angle.hpp:115
mAng3_c & operator-=(const mAng3_c &v)
Augmented subtraction operator.
Definition m_angle.hpp:94
static mAng3_c Ey
The unit rotation vector for the Y axis.
Definition m_angle.hpp:114
mAng3_c operator-(const mAng3_c &v) const
Subtraction operator.
Definition m_angle.hpp:106
mAng3_c(const mAng3_c &v)
Copy constructor.
Definition m_angle.hpp:81
mAng y
The rotation on the Y axis.
Definition m_angle.hpp:109
mAng3_c & operator+=(const mAng3_c &v)
Augmented addition operator.
Definition m_angle.hpp:91
mAng z
The rotation on the Z axis.
Definition m_angle.hpp:110
static mAng3_c Zero
The null rotation vector.
Definition m_angle.hpp:112
mAng3_c(s16 fx, s16 fy, s16 fz)
Constructs a vector from three short values.
Definition m_angle.hpp:69
static mAng3_c Ex
The unit rotation vector for the X axis.
Definition m_angle.hpp:113
mAng3_c operator-() const
Negative operator.
Definition m_angle.hpp:100
mAng x
The rotation on the X axis.
Definition m_angle.hpp:108
mAng3_c(mAng fx, mAng fy, mAng fz)
Constructs a vector from three mAng values.
Definition m_angle.hpp:78
mAng3_c(const s16 *p)
Constructs a vector from a short array.
Definition m_angle.hpp:66
A one-dimensional short angle vector.
Definition m_angle.hpp:12
mAng & operator+=(const mAng &v)
Augmented addition operator.
Definition m_angle.hpp:31
mAng()
Constructs an empty vector.
Definition m_angle.hpp:15
mAng operator-() const
Negative operator.
Definition m_angle.hpp:40
float cos() const
Computes the cosine of the angle.
Definition m_angle.hpp:52
float sin() const
Computes the sine of the angle.
Definition m_angle.hpp:49
s16 mAngle
The rotation.
Definition m_angle.hpp:54
mAng & operator-=(const mAng &v)
Augmented subtraction operator.
Definition m_angle.hpp:34
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:46
mAng operator+() const
Positive operator.
Definition m_angle.hpp:37
mAng operator+(const mAng &v) const
Addition operator.
Definition m_angle.hpp:43