NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
m_mtx.cpp
1#include <types.h>
2#include <utility_inlines.hpp>
5#include <lib/rvl/mtx/mtx.h>
6#include <dol/cLib/c_math.hpp>
7#include <dol/mLib/m_mtx.hpp>
8
9mMtx_c mMtx_c::Identity = mMtx_c(1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
10
11mMtx_c::mMtx_c(float _00, float _01, float _02, float _03, float _10, float _11, float _12, float _13, float _20, float _21, float _22, float _23) {
12 mData[0][0] = _00;
13 mData[0][1] = _01;
14 mData[0][2] = _02;
15 mData[0][3] = _03;
16 mData[1][0] = _10;
17 mData[1][1] = _11;
18 mData[1][2] = _12;
19 mData[1][3] = _13;
20 mData[2][0] = _20;
21 mData[2][1] = _21;
22 mData[2][2] = _22;
23 mData[2][3] = _23;
24}
25
26void mMtx_c::XrotS(mAng angle) {
27 float cos = angle.cos();
28 float sin = angle.sin();
29
30 mData[0][0] = 1.0f;
31 mData[0][1] = 0.0f;
32 mData[0][2] = 0.0f;
33 mData[0][3] = 0.0f;
34 mData[1][0] = 0.0f;
35 mData[1][1] = cos;
36 mData[1][2] = -sin;
37 mData[1][3] = 0.0f;
38 mData[2][0] = 0.0f;
39 mData[2][1] = sin;
40 mData[2][2] = cos;
41 mData[2][3] = 0.0f;
42}
43
44void mMtx_c::XrotM(mAng angle) {
45 if (angle.mAngle != 0) {
46 mMtx_c rotatedMtx = mMtx_c();
47 rotatedMtx.XrotS(angle);
48 PSMTXConcat(*this, rotatedMtx, *this);
49 }
50}
51
52void mMtx_c::YrotS(mAng angle) {
53 float cos = angle.cos();
54 float sin = angle.sin();
55
56 mData[0][0] = cos;
57 mData[0][1] = 0.0f;
58 mData[0][2] = sin;
59 mData[0][3] = 0.0f;
60 mData[1][0] = 0.0f;
61 mData[1][1] = 1.0f;
62 mData[1][2] = 0.0f;
63 mData[1][3] = 0.0f;
64 mData[2][0] = -sin;
65 mData[2][1] = 0.0f;
66 mData[2][2] = cos;
67 mData[2][3] = 0.0f;
68}
69
70void mMtx_c::YrotM(mAng angle) {
71 if (angle.mAngle != 0) {
72 mMtx_c rotatedMtx = mMtx_c();
73 rotatedMtx.YrotS(angle);
74 PSMTXConcat(*this, rotatedMtx, *this);
75 }
76}
77
78void mMtx_c::ZrotS(mAng angle) {
79 float cos = angle.cos();
80 float sin = angle.sin();
81
82 mData[0][0] = cos;
83 mData[0][1] = -sin;
84 mData[0][2] = 0.0f;
85 mData[0][3] = 0.0f;
86 mData[1][0] = sin;
87 mData[1][1] = cos;
88 mData[1][2] = 0.0f;
89 mData[1][3] = 0.0f;
90 mData[2][0] = 0.0f;
91 mData[2][1] = 0.0f;
92 mData[2][2] = 1.0f;
93 mData[2][3] = 0.0f;
94}
95
96void mMtx_c::ZrotM(mAng angle) {
97 if (angle.mAngle != 0) {
98 mMtx_c rotatedMtx = mMtx_c();
99 rotatedMtx.ZrotS(angle);
100 PSMTXConcat(*this, rotatedMtx, *this);
101 }
102}
103
104void mMtx_c::ZXYrotM(mAng xRot, mAng yRot, mAng zRot) {
105 YrotM(yRot);
106 XrotM(xRot);
107 ZrotM(zRot);
108}
109
110void mMtx_c::XYZrotM(mAng xRot, mAng yRot, mAng zRot) {
111 ZrotM(zRot);
112 YrotM(yRot);
113 XrotM(xRot);
114}
115
116// [This approach is required for matching].
117inline float calcLengthSq(float x, float y) {
118 x *= x;
119 y *= y;
120 x += y;
121 return x;
122}
123
124void mMtx_c::toRot(mAng3_c &out) const {
125 float cos = nw4r::math::FSqrt(calcLengthSq(mData[0][2], mData[2][2]));
126
127 short xRot = cM::atan2s(-mData[1][2], cos);
128 out.x = xRot;
129 if (xRot == 0x4000 || xRot == -0x4000) {
130 out.z = 0;
131 out.y = cM::atan2s(-mData[2][0], mData[0][0]);
132 } else {
133 out.y = cM::atan2s(mData[0][2], mData[2][2]);
134 out.z = cM::atan2s(mData[1][0], mData[1][1]);
135 }
136}
137
139 out.x = mData[0][3];
140 out.y = mData[1][3];
141 out.z = mData[2][3];
142}
143
145 mData[0][0] = 0.0f;
146 mData[0][1] = 0.0f;
147 mData[0][2] = 0.0f;
148 mData[0][3] = 0.0f;
149 mData[1][0] = 0.0f;
150 mData[1][1] = 0.0f;
151 mData[1][2] = 0.0f;
152 mData[1][3] = 0.0f;
153 mData[2][0] = 0.0f;
154 mData[2][1] = 0.0f;
155 mData[2][2] = 0.0f;
156 mData[2][3] = 0.0f;
157}
A three-dimensional short angle vector.
Definition m_angle.hpp:61
s16 y
The rotation on the Y axis.
Definition m_angle.hpp:113
s16 z
The rotation on the Z axis.
Definition m_angle.hpp:114
s16 x
The rotation on the X axis.
Definition m_angle.hpp:112
A 3x4 matrix.
Definition m_mtx.hpp:9
mMtx_c()
Constructs an empty matrix.
Definition m_mtx.hpp:12
void ZrotS(mAng angle)
Generates a rotation matrix for the Z axis with the given angle.
Definition m_mtx.cpp:78
void XYZrotM(mAng xRot, mAng yRot, mAng zRot)
Rotates the matrix on the Z, Y and X axes by the given angles.
Definition m_mtx.cpp:110
void toRot(mAng3_c &out) const
Converts the matrix to a rotation vector.
Definition m_mtx.cpp:124
void multVecZero(nw4r::math::VEC3 &out) const
Converts the matrix to a vector.
Definition m_mtx.cpp:138
void ZrotM(mAng angle)
Rotates the matrix on the Z axis by the given angle.
Definition m_mtx.cpp:96
void XrotS(mAng angle)
Generates a rotation matrix for the X axis with the given angle.
Definition m_mtx.cpp:26
void YrotS(mAng angle)
Generates a rotation matrix for the Y axis with the given angle.
Definition m_mtx.cpp:52
void ZXYrotM(mAng xRot, mAng yRot, mAng zRot)
Rotates the matrix on the Y, X and Z axes by the given angles.
Definition m_mtx.cpp:104
static mMtx_c Identity
The identity matrix.
Definition m_mtx.hpp:39
void XrotM(mAng angle)
Rotates the matrix on the X axis by the given angle.
Definition m_mtx.cpp:44
void zero()
Zeroes out the matrix.
Definition m_mtx.cpp:144
void YrotM(mAng angle)
Rotates the matrix on the Y axis by the given angle.
Definition m_mtx.cpp:70
float mData[3][4]
The matrix components.
Definition m_mtx.hpp:37
void PSMTXConcat(const Mtx *a, const Mtx *b, Mtx *out)
Concatenates two matrices.
s16 atan2s(float sin, float cos)
Converts a sine and a cosine to an angle in units.
Definition c_math.cpp:168
float FSqrt(float x)
Computes the square root of the given value.
A one-dimensional short angle vector.
Definition m_angle.hpp:8
float cos() const
Computes the cosine of the angle.
Definition m_angle.hpp:53
float sin() const
Computes the sine of the angle.
Definition m_angle.hpp:50
s16 mAngle
The rotation.
Definition m_angle.hpp:56
A three-dimensional floating point vector.
Definition vec.hpp:13