diff --git a/matrix.cpp b/matrix.cpp index 84939a5f..adce19f4 100644 --- a/matrix.cpp +++ b/matrix.cpp @@ -294,6 +294,56 @@ matrix::operator* (const matrix &rhs) const { } +//----------------------------------------------------------------------------- +template +vector<4> +matrix::operator* (const vector<4> &rhs) const { + return vector<4> { + values[0][0] * rhs.x + values[0][1] * rhs.y + values[0][2] * rhs.z + values[0][3] * rhs.w, + values[1][0] * rhs.x + values[1][1] * rhs.y + values[1][2] * rhs.z + values[1][3] * rhs.w, + values[2][0] * rhs.x + values[2][1] * rhs.y + values[2][2] * rhs.z + values[2][3] * rhs.w, + values[3][0] * rhs.x + values[3][1] * rhs.y + values[3][2] * rhs.z + values[3][3] * rhs.w + }; +} + + +//----------------------------------------------------------------------------- +template +matrix +matrix::operator/ (T s) const { + matrix m; + + for (size_t r = 0; r < m.rows; ++r) + for (size_t c = 0; c < m.cols; ++c) + m.values[r][c] = values[r][c] / s; + + return m; +} + + +//----------------------------------------------------------------------------- +template +matrix& +matrix::operator/= (T s) { + for (size_t r = 0; r < rows; ++r) + for (size_t c = 0; c < cols; ++c) + values[r][c] /= s; + + return *this; +} + + +//----------------------------------------------------------------------------- +template +bool +matrix::operator== (const matrix &rhs) const { + for (size_t r = 0; r < rows; ++r) + for (size_t c = 0; c < cols; ++c) + if (!almost_equal (rhs.values[r][c], values[r][c])) + return false; + return true; +} + //----------------------------------------------------------------------------- template util::point<3> diff --git a/matrix.hpp b/matrix.hpp index ead9e3b4..ed88422e 100644 --- a/matrix.hpp +++ b/matrix.hpp @@ -43,6 +43,13 @@ namespace util { T det (void) const; matrix operator* (const matrix&) const; + vector<4> operator* (const vector<4>&) const; + + matrix operator/ (T) const; + + matrix& operator/= (T); + + bool operator== (const matrix&) const; point<3> to_local (const point<3> &p) const; point<3> to_global (const point<3> &p) const;