From 6843cbaeaca73ecdbebe852b7e7899ce48f8a83c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 19 May 2013 21:25:47 +0300 Subject: [PATCH] Use a cached inverse transformation in TransformedShape --- source/geometry/transformedshape.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/source/geometry/transformedshape.h b/source/geometry/transformedshape.h index 10789ed..2168126 100644 --- a/source/geometry/transformedshape.h +++ b/source/geometry/transformedshape.h @@ -14,6 +14,7 @@ class TransformedShape: public Shape private: Shape *shape; AffineTransformation transformation; + AffineTransformation inverse_trans; public: TransformedShape(const Shape &, const AffineTransformation &); @@ -33,13 +34,15 @@ public: template inline TransformedShape::TransformedShape(const Shape &s, const AffineTransformation &t): shape(s.clone()), - transformation(t) + transformation(t), + inverse_trans(invert(t)) { } template inline TransformedShape::TransformedShape(const TransformedShape &other): shape(other.shape->clone()), - transformation(other.transformation) + transformation(other.transformation), + inverse_trans(other.inverse_trans) { } template @@ -48,6 +51,7 @@ inline TransformedShape &TransformedShape::operator=(const Transform delete shape; shape = other.shape->clone(); transformation = other.transformation; + inverse_trans = other.inverse_trans; } template @@ -72,11 +76,9 @@ inline HyperBox TransformedShape::get_axis_aligned_bounding_box() co template inline bool TransformedShape::check_intersection(const Ray &ray) const { - // TODO cache the inverse transformation for performance - LinAl::SquareMatrix inverse_trans = LinAl::invert(transformation.get_matrix()); - Ray trans_ray(reduce_vector(inverse_trans*augment_vector(ray.get_start(), T(1))), - reduce_vector(inverse_trans*augment_vector(ray.get_direction(), T(0)))); - return shape->check_intersection(trans_ray); + Ray local_ray(inverse_trans.transform(ray.get_start()), + inverse_trans.transform_linear(ray.get_direction())); + return shape->check_intersection(local_ray); } } // namespace Geometry -- 2.45.2