From 277252ef775b848bdc3c22d658f5a7d4c08903cb Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Fri, 23 Jan 2009 00:27:29 +0000 Subject: [PATCH] added transformation operations to util/Transform git-svn-id: svn://anubis/fart/trunk@31 7f9b0f55-74a9-4bce-be96-3c2cd072584d --- util/Transform.cc | 18 ++++++++++++++++++ util/Transform.h | 6 ++++++ 2 files changed, 24 insertions(+) diff --git a/util/Transform.cc b/util/Transform.cc index ec1f8ff..3e7be63 100644 --- a/util/Transform.cc +++ b/util/Transform.cc @@ -53,3 +53,21 @@ void Transform::scale(double xs, double ys, double zs) t[2][2] = zs; m_matrix *= t; } + +Vector operator*(Transform & t, const Vector & v) +{ + return t.getMatrix() * v; +} + +Vector operator%(Transform & t, const Vector & v) +{ + return t.getMatrix() % v; +} + +Ray operator*(Transform & t, const Ray & r) +{ + Vector newPosition = t.getMatrix() * r.getOrigin(); + Vector newDirection = t.getMatrix() % r.getDirection(); + Ray res(newPosition, newDirection); + return res; +} diff --git a/util/Transform.h b/util/Transform.h index 38a6242..f11d4c5 100644 --- a/util/Transform.h +++ b/util/Transform.h @@ -3,6 +3,8 @@ #define TRANSFORM_H TRANSFORM_H #include "Matrix.h" +#include "Ray.h" +#include "Vector.h" #include class Transform @@ -18,5 +20,9 @@ class Transform Matrix m_matrix; }; +Vector operator*(Transform & t, const Vector & v); +Vector operator%(Transform & t, const Vector & v); +Ray operator*(Transform & t, const Ray & r); + #endif