#ifndef __SCOP_MAT4__ #define __SCOP_MAT4__ #include #include #include #include namespace Scop { template struct Vec2; template struct Vec3; template struct Vec4; template struct Quat; template struct Mat4 { T m11, m12, m13, m14; T m21, m22, m23, m24; T m31, m32, m33, m34; T m41, m42, m43, m44; constexpr Mat4() = default; constexpr Mat4(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 Mat4(const T& col_1, const T& col_2, const T& col_3, const T& col_4); constexpr Mat4(const Vec4& col_1, const Vec4& col_2, const Vec4& col_3, const Vec4& col_4); constexpr Mat4(const T matrix[16]); constexpr Mat4(const Mat4&) = default; constexpr Mat4(Mat4&&) = default; constexpr Mat4& ApplyRotation(const Quat& rotation); constexpr Mat4& ApplyScale(const Vec3& scale); constexpr Mat4& ApplyTranslation(const Vec3& translation); constexpr bool ApproxEqual(const Mat4& vec, T max_difference = std::numeric_limits::epsilon()) const; constexpr Mat4& Concatenate(const Mat4& matrix); constexpr Mat4& ConcatenateTransform(const Mat4& matrix); constexpr Vec4 GetColumn(std::size_t column) const; constexpr T GetDeterminant() const; constexpr T GetDeterminantTransform() const; constexpr bool GetInverse(Mat4* dest) const; constexpr bool GetInverseTransform(Mat4* dest) const; Quat GetRotation() const; constexpr Vec4 GetRow(std::size_t row) const; constexpr Vec3 GetScale() const; constexpr Vec3 GetSquaredScale() const; constexpr Vec3 GetTranslation() const; constexpr void GetTransposed(Mat4* dest) const; constexpr bool HasNegativeScale() const; constexpr bool HasScale() const; constexpr Mat4& Inverse(bool* succeeded = nullptr); constexpr Mat4& InverseTransform(bool* succeeded = nullptr); constexpr bool IsTransformMatrix() const; constexpr bool IsIdentity() const; constexpr Mat4& SetRotation(const Quat& rotation); constexpr Mat4& SetScale(const Vec3& scale); constexpr Mat4& SetTranslation(const Vec3& translation); std::string ToString() const; constexpr Vec2 Transform(const Vec2& vector, T z = 0.0, T w = 1.0) const; constexpr Vec3 Transform(const Vec3& vector, T w = 1.0) const; constexpr Vec4 Transform(const Vec4& vector) const; constexpr Mat4& 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 Mat4& operator=(const Mat4&) = default; constexpr Mat4& operator=(Mat4&&) = default; constexpr Mat4 operator*(const Mat4& matrix) const; constexpr Vec2 operator*(const Vec2& vector) const; constexpr Vec3 operator*(const Vec3& vector) const; constexpr Vec4 operator*(const Vec4& vector) const; constexpr Mat4 operator*(T scalar) const; constexpr Mat4& operator*=(const Mat4& matrix); constexpr Mat4& operator*=(T scalar); constexpr bool operator==(const Mat4& mat) const; constexpr bool operator!=(const Mat4& mat) const; static constexpr bool ApproxEqual(const Mat4& lhs, const Mat4& rhs, T max_difference = std::numeric_limits::epsilon()); static constexpr Mat4 Concatenate(const Mat4& left, const Mat4& right); static constexpr Mat4 ConcatenateTransform(const Mat4& left, const Mat4& right); static constexpr Mat4 Identity(); static constexpr Mat4 LookAt(const Vec3& eye, const Vec3& target, const Vec3& up = Vec3::Up()); static constexpr Mat4 Ortho(T left, T right, T top, T bottom, T zNear = -1.0, T zFar = 1.0); static Mat4 Perspective(RadianAngle angle, T ratio, T zNear, T zFar); static constexpr Mat4 Rotate(const Quat& rotation); static constexpr Mat4 Scale(const Vec3& scale); static constexpr Mat4 Translate(const Vec3& translation); static constexpr Mat4 Transform(const Vec3& translation, const Quat& rotation); static constexpr Mat4 Transform(const Vec3& translation, const Quat& rotation, const Vec3& scale); static constexpr Mat4 TransformInverse(const Vec3& translation, const Quat& rotation); static constexpr Mat4 TransformInverse(const Vec3& translation, const Quat& rotation, const Vec3& scale); static constexpr Mat4 Zero(); ~Mat4() = default; }; using Mat4d = Mat4; using Mat4f = Mat4; } #include #endif