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