From 2deee25004c171dab7e08901df439684356edb10 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 23 Jan 2009 00:14:22 +0000 Subject: [PATCH] added operator%() to util/Matrix git-svn-id: svn://anubis/fart/trunk@30 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- util/Matrix.cc | 16 +++++++++++++++- util/Matrix.h | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) 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);