diff --git a/test/tests.cc b/test/tests.cc index cebd885..e2f2ef4 100644 --- a/test/tests.cc +++ b/test/tests.cc @@ -20,5 +20,11 @@ int main() Matrix mult = m * i; cout << "mult:" << endl << mult; + m *= m; + cout << "m^2:" << endl << m; + + m *= m; + cout << "m^4:" << endl << m; + return 0; } diff --git a/util/Matrix.cc b/util/Matrix.cc index 3cdc5e1..62744cf 100644 --- a/util/Matrix.cc +++ b/util/Matrix.cc @@ -191,6 +191,13 @@ Matrix Matrix::getInverse() return m; } +Matrix & Matrix::operator*=(const Matrix & other) +{ + Matrix temp = (*this) * other; + (*this) = temp; + return (*this); +} + Matrix operator*(const Matrix & m1, const Matrix & m2) { Matrix res; diff --git a/util/Matrix.h b/util/Matrix.h index 964aea2..84b780e 100644 --- a/util/Matrix.h +++ b/util/Matrix.h @@ -15,6 +15,7 @@ class Matrix static Matrix identity(); double determinant(); Matrix getInverse(); + Matrix & operator*=(const Matrix & other); protected: double m_matrix[4][4]; diff --git a/util/Transform.cc b/util/Transform.cc index 74c051e..f1fc8f5 100644 --- a/util/Transform.cc +++ b/util/Transform.cc @@ -8,7 +8,11 @@ Transform::Transform() void Transform::translate(double x, double y, double z) { - /* TODO: fill in */ + Matrix t = Matrix::identity(); + t[0][3] = x; + t[1][3] = y; + t[2][3] = z; + m_matrix *= t; } void Transform::rotate(double amt, double xv, double yv, double zv)