From d025adb453702b91963bcce6a076e922d4ecc4dd Mon Sep 17 00:00:00 2001 From: Nomango Date: Tue, 30 Jul 2019 13:05:16 +0800 Subject: [PATCH] fix potential errors in matrix multiplication --- kiwano/2d/Node.cpp | 2 +- kiwano/math/Matrix.hpp | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/kiwano/2d/Node.cpp b/kiwano/2d/Node.cpp index cf77abc7..52d18492 100644 --- a/kiwano/2d/Node.cpp +++ b/kiwano/2d/Node.cpp @@ -220,7 +220,7 @@ namespace kiwano if (parent_) { - transform_matrix_ = transform_matrix_ * parent_->transform_matrix_; + transform_matrix_ *= parent_->transform_matrix_; } // update children's transform diff --git a/kiwano/math/Matrix.hpp b/kiwano/math/Matrix.hpp index dd251212..5c3f7194 100644 --- a/kiwano/math/Matrix.hpp +++ b/kiwano/math/Matrix.hpp @@ -78,8 +78,8 @@ namespace kiwano { } - template - MatrixT(T const& other) + template + MatrixT(_MTy const& other) { for (int i = 0; i < 6; i++) m[i] = other[i]; @@ -95,12 +95,24 @@ namespace kiwano return m[index]; } - template - inline MatrixT& operator= (MatrixMultiply const& other) + inline MatrixT& operator= (MatrixT const& other) { for (int i = 0; i < 6; i++) m[i] = other[i]; - return *this; + return (*this); + } + + template + inline MatrixT& operator= (MatrixMultiply const& other) + { + MatrixT result(other); + (*this) = result; + return (*this); + } + + inline MatrixT& operator*= (MatrixT const& other) + { + return operator=((*this) * other); } inline void Identity()