NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
m_mtx.hpp
1#pragma once
2#include <types.h>
3#include <game/mLib/m_angle.hpp>
4#include <game/mLib/m_vec.hpp>
5#include <nw4r/math.h>
6
7/// @brief A 3x4 matrix.
8/// @ingroup mlib
9class mMtx_c : public nw4r::math::MTX34 {
10public:
11 /// @brief Constructs an empty matrix.
12 mMtx_c() {}
13
14 /// @brief Constructs a matrix from an MTX34.
15 mMtx_c(const nw4r::math::MTX34 &mtx) : MTX34(mtx) {}
16
17 /// @brief Constructs a matrix with the given components.
18 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);
19
20 /// @brief Mtx cast operator.
21 operator Mtx*() { return &mtx; }
22
23 /// @brief Const Mtx cast operator.
24 operator const Mtx*() const { return &mtx; }
25
26 void XrotS(mAng angle); ///< Generates a rotation matrix for the X axis with the given angle.
27 void XrotM(mAng angle); ///< Rotates the matrix on the X axis by the given angle.
28 void YrotS(mAng angle); ///< Generates a rotation matrix for the Y axis with the given angle.
29 void YrotM(mAng angle); ///< Rotates the matrix on the Y axis by the given angle.
30 void ZrotS(mAng angle); ///< Generates a rotation matrix for the Z axis with the given angle.
31 void ZrotM(mAng angle); ///< Rotates the matrix on the Z axis by the given angle.
32
33 void ZXYrotM(mAng xRot, mAng yRot, mAng zRot); ///< Rotates the matrix on the Y, X and Z axes by the given angles.
34 void XYZrotM(mAng xRot, mAng yRot, mAng zRot); ///< Rotates the matrix on the Z, Y and X axes by the given angles.
35
36 void toRot(mAng3_c &out) const; ///< Extracts the rotation vector from the matrix.
37 void multVecZero(nw4r::math::VEC3 &out) const; ///< Extracts the translation vector from the matrix.
38 void zero(); ///< Zeroes out the matrix.
39
40 mVec3_c getTranslation() const {
41 float x = m[0][3];
42 float y = m[1][3];
43 float z = m[2][3];
44 return mVec3_c(x, y, z);
45 }
46
47 static mMtx_c createTrans(const mVec3_c &v) { return createTrans(v.x, v.y, v.z); }
48 static mMtx_c createTrans(float x, float y, float z) { mMtx_c mtx; PSMTXTrans(mtx, x, y, z); return mtx; }
49
50 mMtx_c &concat(const mMtx_c &other) { PSMTXConcat(*this, other, *this); return *this; }
51 mMtx_c &trans(const mVec3_c &v) { PSMTXTrans(*this, v.x, v.y, v.z); return *this; }
52 mMtx_c &trans(float x, float y, float z) { PSMTXTrans(*this, x, y, z); return *this; }
53 mMtx_c &ZXYrotM(const mAng3_c &ang) { ZXYrotM(ang.x, ang.y, ang.z); return *this; }
54
55 float transX() const { return getTranslation().x; }
56 float transY() const { return getTranslation().y; }
57 float transZ() const { return getTranslation().z; }
58
59 static mMtx_c Identity; ///< The identity matrix.
60};
A three-dimensional short angle vector.
Definition m_angle.hpp:59
mAng y
The rotation on the Y axis.
Definition m_angle.hpp:109
mAng z
The rotation on the Z axis.
Definition m_angle.hpp:110
mAng x
The rotation on the X axis.
Definition m_angle.hpp:108
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:75
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:107
void toRot(mAng3_c &out) const
Extracts the rotation vector from the matrix.
Definition m_mtx.cpp:121
void multVecZero(nw4r::math::VEC3 &out) const
Extracts the translation vector from the matrix.
Definition m_mtx.cpp:135
mMtx_c(const nw4r::math::MTX34 &mtx)
Constructs a matrix from an MTX34.
Definition m_mtx.hpp:15
void ZrotM(mAng angle)
Rotates the matrix on the Z axis by the given angle.
Definition m_mtx.cpp:93
void XrotS(mAng angle)
Generates a rotation matrix for the X axis with the given angle.
Definition m_mtx.cpp:23
void YrotS(mAng angle)
Generates a rotation matrix for the Y axis with the given angle.
Definition m_mtx.cpp:49
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:101
static mMtx_c Identity
The identity matrix.
Definition m_mtx.hpp:59
void XrotM(mAng angle)
Rotates the matrix on the X axis by the given angle.
Definition m_mtx.cpp:41
void zero()
Zeroes out the matrix.
Definition m_mtx.cpp:141
void YrotM(mAng angle)
Rotates the matrix on the Y axis by the given angle.
Definition m_mtx.cpp:67
A three-dimensional floating point vector.
Definition m_vec.hpp:112
A one-dimensional short angle vector.
Definition m_angle.hpp:12