matrix: add transpose functions

This commit is contained in:
Danny Robson 2014-12-15 13:42:44 +11:00
parent a198aa1cba
commit 253be704cb
2 changed files with 29 additions and 0 deletions

View File

@ -48,6 +48,32 @@ matrix<T>::translate (T x, T y, T z) {
}
//-----------------------------------------------------------------------------
template <typename T>
matrix<T>
matrix<T>::transposed (void) const
{
matrix<T> 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 <typename T>
matrix<T>&
matrix<T>::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 <typename T>
matrix<T>

View File

@ -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<T> inverse (void) const;
matrix<T>& invert (void);
matrix<T> inverse_affine (void) const;