diff --git a/util/Matrix.cc b/util/Matrix.cc index 62744cf..39a9ae3 100644 --- a/util/Matrix.cc +++ b/util/Matrix.cc @@ -214,10 +214,11 @@ Matrix operator*(const Matrix & m1, const Matrix & m2) return res; } +/* transform a point */ Vector operator*(const Matrix & m, const Vector & v) { Vector res; - for (int i = 0; i < 4; i++) + for (int i = 0; i < 3; i++) { res[i] = m[i][0] * v[0] + m[i][1] * v[1] @@ -227,6 +228,19 @@ Vector operator*(const Matrix & m, const Vector & v) return res; } +/* transform a direction */ +Vector operator%(const Matrix & m, const Vector & v) +{ + Vector res; + for (int i = 0; i < 3; i++) + { + res[i] = m[i][0] * v[0] + + m[i][1] * v[1] + + m[i][2] * v[2]; + } + return res; +} + bool operator==(const Matrix & m1, const Matrix & m2) { for (int i = 0; i < 4; i++) diff --git a/util/Matrix.h b/util/Matrix.h index 84b780e..5ccd23f 100644 --- a/util/Matrix.h +++ b/util/Matrix.h @@ -26,7 +26,8 @@ class Matrix }; Matrix operator*(const Matrix & m1, const Matrix & m2); -Vector operator*(const Matrix & m, const Vector & v); +Vector operator*(const Matrix & m, const Vector & v); /* transform point */ +Vector operator%(const Matrix & m, const Vector & v); /* transform direction */ bool operator==(const Matrix & m1, const Matrix & m2); std::ostream & operator<<(std::ostream & out, const Matrix & m);