#ifndef SPECTRE_MATH_MATRIX4_H #define SPECTRE_MATH_MATRIX4_H // 4x4 matrix implementation. #include #include #include #include namespace sp { template struct Matrix4 { // Column-major order are used for the matrices here to be compatible with OpenGL. union { T m[4][4]; // format: [col][row] /* Indicies to use for accessing elements. _ _ | | | 0 4 8 12 | | 1 5 9 13 | | 2 6 10 14 | | 3 7 11 15 | |_ _| */ T e[16]; }; static const Matrix4 Identity; inline Matrix4(); inline Matrix4( T a00, T a01, T a02, T a03, T a10, T a11, T a12, T a13, T a20, T a21, T a22, T a23, T a30, T a31, T a32, T a33); inline Matrix4(T *a); // ------------------- // Copy & Assignment // ------------------- template inline Matrix4(const Matrix4& mat); inline Matrix4& operator=(const Matrix4& mat); // ------------------ // Named operations // ------------------ // Transpose matrix. Matrix4 transpose() const; std::string toString() const; }; // ----------------- // Compare // ----------------- template inline bool operator==(const Matrix4& a, const Matrix4& b); template inline bool operator!=(const Matrix4& a, const Matrix4& b); // -------------------------- // Arithmetic: Matrix-Matrix // -------------------------- template inline Matrix4 operator*(const Matrix4& a, const Matrix4& b); template inline Matrix4& operator*=(Matrix4& a, const Matrix4& b); // -------------------------- // Arithmetic: Matrix-Vector // -------------------------- template inline Vector3 operator*(const Matrix4& mat, const Vector3& vec); template inline std::ostream& operator<<(std::ostream &s, const Matrix4& mat); // ----------------------------- // Common specialization types // ----------------------------- typedef Matrix4 Matrix4f; typedef Matrix4 Matrix4d; typedef Matrix4 Matrix4i; typedef Matrix4 Matrix4u; typedef Matrix4 mat4f; typedef Matrix4 mat4d; typedef Matrix4 mat4i; typedef Matrix4 mat4u; } // namespace sp // ---------------- // Implementation // ---------------- #include "Matrix4.inl" #endif /* SPECTRE_MATH_MATRIX4_H */