|
@@ -14,7 +14,7 @@
|
|
namespace Gfx {
|
|
namespace Gfx {
|
|
|
|
|
|
template<typename T>
|
|
template<typename T>
|
|
-class Matrix4x4 final : public Matrix<4, T> {
|
|
|
|
|
|
+class Matrix4x4 final {
|
|
public:
|
|
public:
|
|
constexpr Matrix4x4() = default;
|
|
constexpr Matrix4x4() = default;
|
|
constexpr Matrix4x4(T _11, T _12, T _13, T _14,
|
|
constexpr Matrix4x4(T _11, T _12, T _13, T _14,
|
|
@@ -38,10 +38,10 @@ public:
|
|
Matrix4x4 product;
|
|
Matrix4x4 product;
|
|
for (int i = 0; i < 4; ++i) {
|
|
for (int i = 0; i < 4; ++i) {
|
|
for (int j = 0; j < 4; ++j) {
|
|
for (int j = 0; j < 4; ++j) {
|
|
- product.m_elements[i][j] = m_elements[0][j] * other.m_elements[i][0]
|
|
|
|
- + m_elements[1][j] * other.m_elements[i][1]
|
|
|
|
- + m_elements[2][j] * other.m_elements[i][2]
|
|
|
|
- + m_elements[3][j] * other.m_elements[i][3];
|
|
|
|
|
|
+ product.m_elements[i][j] = m_elements[i][0] * other.m_elements[0][j]
|
|
|
|
+ + m_elements[i][1] * other.m_elements[1][j]
|
|
|
|
+ + m_elements[i][2] * other.m_elements[2][j]
|
|
|
|
+ + m_elements[i][3] * other.m_elements[3][j];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return product;
|
|
return product;
|
|
@@ -50,18 +50,18 @@ public:
|
|
constexpr Vector4<T> operator*(const Vector4<T>& v) const
|
|
constexpr Vector4<T> operator*(const Vector4<T>& v) const
|
|
{
|
|
{
|
|
return Vector4<T>(
|
|
return Vector4<T>(
|
|
- v.x() * m_elements[0][0] + v.y() * m_elements[1][0] + v.z() * m_elements[2][0] + v.w() * m_elements[3][0],
|
|
|
|
- v.x() * m_elements[0][1] + v.y() * m_elements[1][1] + v.z() * m_elements[2][1] + v.w() * m_elements[3][1],
|
|
|
|
- v.x() * m_elements[0][2] + v.y() * m_elements[1][2] + v.z() * m_elements[2][2] + v.w() * m_elements[3][2],
|
|
|
|
- v.x() * m_elements[0][3] + v.y() * m_elements[1][3] + v.z() * m_elements[2][3] + v.w() * m_elements[3][3]);
|
|
|
|
|
|
+ v.x() * m_elements[0][0] + v.y() * m_elements[0][1] + v.z() * m_elements[0][2] + v.w() * m_elements[0][3],
|
|
|
|
+ v.x() * m_elements[1][0] + v.y() * m_elements[1][1] + v.z() * m_elements[1][2] + v.w() * m_elements[1][3],
|
|
|
|
+ v.x() * m_elements[2][0] + v.y() * m_elements[2][1] + v.z() * m_elements[2][2] + v.w() * m_elements[2][3],
|
|
|
|
+ v.x() * m_elements[3][0] + v.y() * m_elements[3][1] + v.z() * m_elements[3][2] + v.w() * m_elements[3][3]);
|
|
}
|
|
}
|
|
|
|
|
|
constexpr Vector3<T> transform_point(const Vector3<T>& p) const
|
|
constexpr Vector3<T> transform_point(const Vector3<T>& p) const
|
|
{
|
|
{
|
|
return Vector3<T>(
|
|
return Vector3<T>(
|
|
- p.x() * m_elements[0][0] + p.y() * m_elements[1][0] + p.z() * m_elements[2][0] + m_elements[3][0],
|
|
|
|
- p.x() * m_elements[0][1] + p.y() * m_elements[1][1] + p.z() * m_elements[2][1] + m_elements[3][1],
|
|
|
|
- p.x() * m_elements[0][2] + p.y() * m_elements[1][2] + p.z() * m_elements[2][2] + m_elements[3][2]);
|
|
|
|
|
|
+ p.x() * m_elements[0][0] + p.y() * m_elements[0][1] + p.z() * m_elements[0][2] + m_elements[0][3],
|
|
|
|
+ p.x() * m_elements[1][0] + p.y() * m_elements[1][1] + p.z() * m_elements[1][2] + m_elements[1][3],
|
|
|
|
+ p.x() * m_elements[2][0] + p.y() * m_elements[2][1] + p.z() * m_elements[2][2] + m_elements[2][3]);
|
|
}
|
|
}
|
|
|
|
|
|
constexpr static Matrix4x4 identity()
|
|
constexpr static Matrix4x4 identity()
|
|
@@ -76,10 +76,10 @@ public:
|
|
constexpr static Matrix4x4 translate(const Vector3<T>& p)
|
|
constexpr static Matrix4x4 translate(const Vector3<T>& p)
|
|
{
|
|
{
|
|
return Matrix4x4(
|
|
return Matrix4x4(
|
|
- 1, 0, 0, 0,
|
|
|
|
- 0, 1, 0, 0,
|
|
|
|
- 0, 0, 1, 0,
|
|
|
|
- p.x(), p.y(), p.z(), 1);
|
|
|
|
|
|
+ 1, 0, 0, p.x(),
|
|
|
|
+ 0, 1, 0, p.y(),
|
|
|
|
+ 0, 0, 1, p.z(),
|
|
|
|
+ 0, 0, 0, 1);
|
|
}
|
|
}
|
|
|
|
|
|
constexpr static Matrix4x4 scale(const Vector3<T>& s)
|
|
constexpr static Matrix4x4 scale(const Vector3<T>& s)
|
|
@@ -107,6 +107,17 @@ public:
|
|
0, 0, 0, 1);
|
|
0, 0, 0, 1);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ constexpr Matrix4x4 transpose() const
|
|
|
|
+ {
|
|
|
|
+ Matrix4x4 result;
|
|
|
|
+ for (int i = 0; i < 4; ++i) {
|
|
|
|
+ for (int j = 0; j < 4; ++j) {
|
|
|
|
+ result.m_elements[i][j] = m_elements[j][i];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return result;
|
|
|
|
+ }
|
|
|
|
+
|
|
private:
|
|
private:
|
|
T m_elements[4][4];
|
|
T m_elements[4][4];
|
|
};
|
|
};
|