added operator%() to util/Matrix

git-svn-id: svn://anubis/fart/trunk@30 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop 2009-01-23 00:14:22 +00:00
parent 0044dbb544
commit 2deee25004
2 changed files with 17 additions and 2 deletions

View File

@ -214,10 +214,11 @@ Matrix operator*(const Matrix & m1, const Matrix & m2)
return res; return res;
} }
/* transform a point */
Vector operator*(const Matrix & m, const Vector & v) Vector operator*(const Matrix & m, const Vector & v)
{ {
Vector res; Vector res;
for (int i = 0; i < 4; i++) for (int i = 0; i < 3; i++)
{ {
res[i] = m[i][0] * v[0] res[i] = m[i][0] * v[0]
+ m[i][1] * v[1] + m[i][1] * v[1]
@ -227,6 +228,19 @@ Vector operator*(const Matrix & m, const Vector & v)
return res; 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) bool operator==(const Matrix & m1, const Matrix & m2)
{ {
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)

View File

@ -26,7 +26,8 @@ class Matrix
}; };
Matrix operator*(const Matrix & m1, const Matrix & m2); 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); bool operator==(const Matrix & m1, const Matrix & m2);
std::ostream & operator<<(std::ostream & out, const Matrix & m); std::ostream & operator<<(std::ostream & out, const Matrix & m);