From dcdbbe938db945c6d57373c0205c2ef52ab0fc04 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 15 Dec 2014 13:43:53 +1100 Subject: [PATCH] matrix: add scalar multiply --- matrix.cpp | 12 ++++++++++++ matrix.hpp | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/matrix.cpp b/matrix.cpp index 68d8cb00..8fdd4262 100644 --- a/matrix.cpp +++ b/matrix.cpp @@ -336,6 +336,18 @@ matrix::operator* (const vector<4> &rhs) const { } +//----------------------------------------------------------------------------- +template +matrix& +matrix::operator*= (T f){ + for (size_t i = 0; i < 4; ++i) + for (size_t j = 0; j < 4; ++j) + values[i][j] *= f; + + return *this; +} + + //----------------------------------------------------------------------------- template matrix diff --git a/matrix.hpp b/matrix.hpp index 5751d0ff..40b4ad0a 100644 --- a/matrix.hpp +++ b/matrix.hpp @@ -48,8 +48,8 @@ namespace util { matrix operator* (const matrix&) const; vector<4> operator* (const vector<4>&) const; - matrix operator/ (T) const; - + matrix& operator*= (T); + matrix operator/ (T) const; matrix& operator/= (T); bool operator== (const matrix&) const;