// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Math module" // For conditions of distribution and use, see copyright notice in Export.hpp #pragma once #ifndef NAZARA_MATH_MATRIX4_HPP #define NAZARA_MATH_MATRIX4_HPP ///FIXME: Matrices column-major, difficile de bosser avec (Tout passer en row-major et transposer dans les shaders ?) #include #include #include #include namespace Nz { struct SerializationContext; template class EulerAngles; template class Quaternion; template class Vector2; template class Vector3; template class Vector4; template class Matrix4 { public: constexpr Matrix4() = default; constexpr Matrix4(T r11, T r12, T r13, T r14, T r21, T r22, T r23, T r24, T r31, T r32, T r33, T r34, T r41, T r42, T r43, T r44); constexpr Matrix4(const T matrix[16]); template constexpr explicit Matrix4(const Matrix4& matrix); constexpr Matrix4(const Matrix4&) = default; constexpr Matrix4(Matrix4&&) = default; ~Matrix4() = default; constexpr Matrix4& ApplyRotation(const Quaternion& rotation); constexpr Matrix4& ApplyScale(const Vector3& scale); constexpr Matrix4& ApplyTranslation(const Vector3& translation); constexpr bool ApproxEqual(const Matrix4& vec, T maxDifference = std::numeric_limits::epsilon()) const; constexpr Matrix4& Concatenate(const Matrix4& matrix); constexpr Matrix4& ConcatenateTransform(const Matrix4& matrix); constexpr Vector4 GetColumn(std::size_t column) const; constexpr T GetDeterminant() const; constexpr T GetDeterminantTransform() const; constexpr bool GetInverse(Matrix4* dest) const; constexpr bool GetInverseTransform(Matrix4* dest) const; Quaternion GetRotation() const; constexpr Vector4 GetRow(std::size_t row) const; constexpr Vector3 GetScale() const; constexpr Vector3 GetSquaredScale() const; constexpr Vector3 GetTranslation() const; constexpr void GetTransposed(Matrix4* dest) const; constexpr bool HasNegativeScale() const; constexpr bool HasScale() const; constexpr Matrix4& Inverse(bool* succeeded = nullptr); constexpr Matrix4& InverseTransform(bool* succeeded = nullptr); constexpr bool IsTransformMatrix() const; constexpr bool IsIdentity() const; constexpr Matrix4& SetRotation(const Quaternion& rotation); constexpr Matrix4& SetScale(const Vector3& scale); constexpr Matrix4& SetTranslation(const Vector3& translation); std::string ToString() const; constexpr Vector2 Transform(const Vector2& vector, T z = 0.0, T w = 1.0) const; constexpr Vector3 Transform(const Vector3& vector, T w = 1.0) const; constexpr Vector4 Transform(const Vector4& vector) const; constexpr Matrix4& Transpose(); constexpr T& operator()(std::size_t x, std::size_t y); constexpr const T& operator()(std::size_t x, std::size_t y) const; constexpr T& operator[](std::size_t i); constexpr const T& operator[](std::size_t i) const; constexpr Matrix4& operator=(const Matrix4&) = default; constexpr Matrix4& operator=(Matrix4&&) = default; constexpr Matrix4 operator*(const Matrix4& matrix) const; constexpr Vector2 operator*(const Vector2& vector) const; constexpr Vector3 operator*(const Vector3& vector) const; constexpr Vector4 operator*(const Vector4& vector) const; constexpr Matrix4 operator*(T scalar) const; constexpr Matrix4& operator*=(const Matrix4& matrix); constexpr Matrix4& operator*=(T scalar); constexpr bool operator==(const Matrix4& mat) const; constexpr bool operator!=(const Matrix4& mat) const; static constexpr bool ApproxEqual(const Matrix4& lhs, const Matrix4& rhs, T maxDifference = std::numeric_limits::epsilon()); static constexpr Matrix4 Concatenate(const Matrix4& left, const Matrix4& right); static constexpr Matrix4 ConcatenateTransform(const Matrix4& left, const Matrix4& right); static constexpr Matrix4 Identity(); static constexpr Matrix4 LookAt(const Vector3& eye, const Vector3& target, const Vector3& up = Vector3::Up()); static constexpr Matrix4 Ortho(T left, T right, T top, T bottom, T zNear = -1.0, T zFar = 1.0); static Matrix4 Perspective(RadianAngle angle, T ratio, T zNear, T zFar); static constexpr Matrix4 Rotate(const Quaternion& rotation); static constexpr Matrix4 Scale(const Vector3& scale); static constexpr Matrix4 Translate(const Vector3& translation); static constexpr Matrix4 Transform(const Vector3& translation, const Quaternion& rotation); static constexpr Matrix4 Transform(const Vector3& translation, const Quaternion& rotation, const Vector3& scale); static constexpr Matrix4 TransformInverse(const Vector3& translation, const Quaternion& rotation); static constexpr Matrix4 TransformInverse(const Vector3& translation, const Quaternion& rotation, const Vector3& scale); static constexpr Matrix4 Zero(); T m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44; }; using Matrix4d = Matrix4; using Matrix4f = Matrix4; template bool Serialize(SerializationContext& context, const Matrix4& matrix, TypeTag>); template bool Unserialize(SerializationContext& context, Matrix4* matrix, TypeTag>); template std::ostream& operator<<(std::ostream& out, const Matrix4& matrix); template constexpr Matrix4 operator*(T scale, const Matrix4& matrix); } #include #endif // NAZARA_MATH_MATRIX4_HPP