// Copyright (C) 2021 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Math module" // For conditions of distribution and use, see copyright notice in Config.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 #include namespace Nz { struct SerializationContext; template class EulerAngles; template class Quaternion; template class Vector2; template class Vector3; template class Vector4; template class Matrix4 { public: Matrix4() = default; 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); //Matrix4(const Matrix3& matrix); Matrix4(const T matrix[16]); template explicit Matrix4(const Matrix4& matrix); Matrix4(const Matrix4& matrix) = default; ~Matrix4() = default; Matrix4& ApplyRotation(const Quaternion& rotation); Matrix4& ApplyScale(const Vector3& scale); Matrix4& ApplyTranslation(const Vector3& translation); Matrix4& Concatenate(const Matrix4& matrix); Matrix4& ConcatenateAffine(const Matrix4& matrix); void Decompose(Vector3& translation, Quaternion& rotation, Vector3& scale); Vector4 GetColumn(unsigned int column) const; T GetDeterminant() const; T GetDeterminantAffine() const; bool GetInverse(Matrix4* dest) const; bool GetInverseAffine(Matrix4* dest) const; Quaternion GetRotation() const; //Matrix3 GetRotationMatrix() const; Vector4 GetRow(unsigned int row) const; Vector3 GetScale() const; Vector3 GetSquaredScale() const; Vector3 GetTranslation() const; void GetTransposed(Matrix4* dest) const; bool HasNegativeScale() const; bool HasScale() const; Matrix4& Inverse(bool* succeeded = nullptr); Matrix4& InverseAffine(bool* succeeded = nullptr); bool IsAffine() const; bool IsIdentity() const; Matrix4& MakeIdentity(); Matrix4& MakeLookAt(const Vector3& eye, const Vector3& target, const Vector3& up = Vector3::Up()); Matrix4& MakeOrtho(T left, T right, T top, T bottom, T zNear = -1.0, T zFar = 1.0); Matrix4& MakePerspective(RadianAngle angle, T ratio, T zNear, T zFar); Matrix4& MakeRotation(const Quaternion& rotation); Matrix4& MakeScale(const Vector3& scale); Matrix4& MakeTranslation(const Vector3& translation); Matrix4& MakeTransform(const Vector3& translation, const Quaternion& rotation); Matrix4& MakeTransform(const Vector3& translation, const Quaternion& rotation, const Vector3& scale); Matrix4& MakeViewMatrix(const Vector3& translation, const Quaternion& rotation); Matrix4& MakeZero(); Matrix4& Set(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); //Matrix4(const Matrix3& matrix); template Matrix4& Set(const Matrix4& matrix); Matrix4& SetRotation(const Quaternion& rotation); Matrix4& SetScale(const Vector3& scale); Matrix4& SetTranslation(const Vector3& translation); std::string ToString() const; Vector2 Transform(const Vector2& vector, T z = 0.0, T w = 1.0) const; Vector3 Transform(const Vector3& vector, T w = 1.0) const; Vector4 Transform(const Vector4& vector) const; Matrix4& Transpose(); T& operator()(std::size_t x, std::size_t y); T operator()(std::size_t x, std::size_t y) const; T& operator[](std::size_t i); T operator[](std::size_t i) const; Matrix4& operator=(const Matrix4& matrix) = default; Matrix4 operator*(const Matrix4& matrix) const; Vector2 operator*(const Vector2& vector) const; Vector3 operator*(const Vector3& vector) const; Vector4 operator*(const Vector4& vector) const; Matrix4 operator*(T scalar) const; Matrix4& operator*=(const Matrix4& matrix); Matrix4& operator*=(T scalar); bool operator==(const Matrix4& mat) const; bool operator!=(const Matrix4& mat) const; static Matrix4 Concatenate(const Matrix4& left, const Matrix4& right); static Matrix4 ConcatenateAffine(const Matrix4& left, const Matrix4& right); static Matrix4 Identity(); static Matrix4 LookAt(const Vector3& eye, const Vector3& target, const Vector3& up = Vector3::Up()); static 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 Matrix4 Rotate(const Quaternion& rotation); static Matrix4 Scale(const Vector3& scale); static Matrix4 Translate(const Vector3& translation); static Matrix4 Transform(const Vector3& translation, const Quaternion& rotation); static Matrix4 Transform(const Vector3& translation, const Quaternion& rotation, const Vector3& scale); static Matrix4 ViewMatrix(const Vector3& translation, const Quaternion& rotation); static 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 Nz::Matrix4& matrix); template Nz::Matrix4 operator*(T scale, const Nz::Matrix4& matrix); #include #endif // NAZARA_MATH_MATRIX4_HPP