# HG changeset patch # User Teemu Piippo # Date 1572779935 -7200 # Node ID 771168ee2c766a98c771be26133e36fb56aae5db # Parent e249d97c7fe62f2339386ec77d7b7c4eeca63d62 added matrix conversions and datastream operators diff -r e249d97c7fe6 -r 771168ee2c76 src/matrix.h --- a/src/matrix.h Sun Nov 03 13:07:04 2019 +0200 +++ b/src/matrix.h Sun Nov 03 13:18:55 2019 +0200 @@ -1,5 +1,5 @@ #pragma once -#include +#include template struct Matrix @@ -15,7 +15,42 @@ } }; +template +QGenericMatrix matrixToQGenericMatrix(const Matrix& matrix) +{ + return {matrix.values}; +} + +template +Matrix matrixFromQGenericMatrix(const QGenericMatrix matrix) +{ + Matrix result; + for (int row = 0; row < Rows; row += 1) + { + for (int column = 0; column < Columns; column += 1) + { + result(row, column) = matrix(row, column); + } + } + return result; +} + using Matrix3x3 = Matrix<3, 3>; Q_DECLARE_METATYPE(Matrix3x3); using Matrix4x4 = Matrix<4, 4>; Q_DECLARE_METATYPE(Matrix4x4); + +template +QDataStream& operator<<(QDataStream& stream, const Matrix& matrix) +{ + return stream << matrixToQGenericMatrix(matrix); +} + +template +QDataStream& operator>>(QDataStream& stream, Matrix& matrix) +{ + QGenericMatrix qmatrix; + stream >> qmatrix; + matrix = matrixFromQGenericMatrix(matrix); + return stream; +}