matrix scalar division

metadata
Wenzel Jakob 2011-02-04 17:15:47 +01:00
parent 8ea4716dd8
commit 6f5f0c11d2
1 changed files with 27 additions and 0 deletions

View File

@ -198,6 +198,33 @@ public:
return *this; return *this;
} }
/// Scalar division (creates a temporary)
inline Matrix operator/(T value) const {
Matrix result;
#ifdef MTS_DEBUG
if (value == 0)
SLog(EWarn, "Matrix: Division by zero!");
#endif
Float recip = 1/value;
for (int i=0; i<M; ++i)
for (int j=0; j<N; ++j)
result.m[i][j] = m[i][j]*recip;
return result;
}
/// Scalar division
inline const Matrix& operator/=(T value) {
#ifdef MTS_DEBUG
if (value == 0)
SLog(EWarn, "Matrix: Division by zero!");
#endif
Float recip = 1/value;
for (int i=0; i<M; ++i)
for (int j=0; j<N; ++j)
m[i][j] *= recip;
return *this;
}
/// Matrix multiplication (creates a temporary) /// Matrix multiplication (creates a temporary)
template <int M2, int N2> inline Matrix<M, N2, T> operator*(const Matrix<M2, N2, T> &mat) const { template <int M2, int N2> inline Matrix<M, N2, T> operator*(const Matrix<M2, N2, T> &mat) const {
BOOST_STATIC_ASSERT(N == M2); BOOST_STATIC_ASSERT(N == M2);