diff --git a/matrix.cpp b/matrix.cpp index 97a8ee36..53054419 100644 --- a/matrix.cpp +++ b/matrix.cpp @@ -48,6 +48,32 @@ matrix::translate (T x, T y, T z) { } +//----------------------------------------------------------------------------- +template +matrix +matrix::transposed (void) const +{ + matrix m; + for (size_t i = 0; i < 4; ++i) + for (size_t j = 0; j < 4; ++j) + m.values[i][j] = values[j][i]; + return m; +} + + +//----------------------------------------------------------------------------- +template +matrix& +matrix::transpose (void) +{ + for (size_t i = 0; i < 4; ++i) + for (size_t j = i + 1; j < 4; ++j) + std::swap (values[i][j], values[j][i]); + + return *this; +} + + //----------------------------------------------------------------------------- template matrix diff --git a/matrix.hpp b/matrix.hpp index 702ce5f1..5751d0ff 100644 --- a/matrix.hpp +++ b/matrix.hpp @@ -35,6 +35,9 @@ namespace util { void scale (T x, T y, T z); void translate (T x, T y, T z); + matrix& transpose (void); + matrix transposed (void) const; + matrix inverse (void) const; matrix& invert (void); matrix inverse_affine (void) const;