X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Ftransformedshape.h;h=2168126242ab88d1823230ac3b56f34df0eaa564;hb=6843cbaeaca73ecdbebe852b7e7899ce48f8a83c;hp=10af1e7588a7c2efb357037113f9e22970fe887f;hpb=07a1aaf95d6a9e7e0ade2a10cc4e4b7f91486f98;p=libs%2Fmath.git diff --git a/source/geometry/transformedshape.h b/source/geometry/transformedshape.h index 10af1e7..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 @@ -47,7 +50,8 @@ inline TransformedShape &TransformedShape::operator=(const Transform { delete shape; shape = other.shape->clone(); - transformation = other.transformation(); + 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