From 466008bba8ca619eee4e73dff5de23b1431f5d22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 13 Nov 2012 12:03:37 +0100 Subject: [PATCH] SceneGraph: externalized object cleaning function. Will be used elsewhere. --- src/SceneGraph/Object.h | 2 ++ src/SceneGraph/Object.hpp | 73 ++++++++++++++++++++------------------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/SceneGraph/Object.h b/src/SceneGraph/Object.h index 3246fcd0e..0cda03b2d 100644 --- a/src/SceneGraph/Object.h +++ b/src/SceneGraph/Object.h @@ -213,6 +213,8 @@ template class Object: public AbstractObject*>& jointObjects, std::vector& jointTransformations, const std::size_t joint, const typename Transformation::DataType& initialTransformation) const; + void setClean(const typename Transformation::DataType& absoluteTransformation); + typedef Implementation::ObjectFlag Flag; typedef Implementation::ObjectFlags Flags; std::uint16_t counter; diff --git a/src/SceneGraph/Object.hpp b/src/SceneGraph/Object.hpp index dec18a843..a663fc8bb 100644 --- a/src/SceneGraph/Object.hpp +++ b/src/SceneGraph/Object.hpp @@ -123,42 +123,9 @@ template void Object::setClean() { Object* o = objects.top(); objects.pop(); - /* Compose transformations */ + /* Compose transformation and clean object */ absoluteTransformation = Transformation::compose(absoluteTransformation, o->transformation()); - - /* "Lazy storage" for transformation matrix and inverted transformation matrix */ - typedef typename AbstractFeature::CachedTransformation CachedTransformation; - typename AbstractFeature::CachedTransformations cached; - typename DimensionTraits::MatrixType - matrix, invertedMatrix; - - /* Clean all features */ - for(AbstractFeature* i = o->firstFeature(); i; i = i->nextFeature()) { - /* Cached absolute transformation, compute it if it wasn't - computed already */ - if(i->cachedTransformations() & CachedTransformation::Absolute) { - if(!(cached & CachedTransformation::Absolute)) { - cached |= CachedTransformation::Absolute; - matrix = Transformation::toMatrix(absoluteTransformation); - } - - i->clean(matrix); - } - - /* Cached inverse absolute transformation, compute it if it wasn't - computed already */ - if(i->cachedTransformations() & CachedTransformation::InvertedAbsolute) { - if(!(cached & CachedTransformation::InvertedAbsolute)) { - cached |= CachedTransformation::InvertedAbsolute; - invertedMatrix = Transformation::toMatrix(Transformation::inverted(absoluteTransformation)); - } - - i->cleanInverted(invertedMatrix); - } - } - - /* Mark object as clean */ - o->flags &= ~Flag::Dirty; + o->setClean(absoluteTransformation); } } @@ -286,6 +253,42 @@ template typename Transformation::DataType Object void Object::setClean(const typename Transformation::DataType& absoluteTransformation) { + /* "Lazy storage" for transformation matrix and inverted transformation matrix */ + typedef typename AbstractFeature::CachedTransformation CachedTransformation; + typename AbstractFeature::CachedTransformations cached; + typename DimensionTraits::MatrixType + matrix, invertedMatrix; + + /* Clean all features */ + for(AbstractFeature* i = this->firstFeature(); i; i = i->nextFeature()) { + /* Cached absolute transformation, compute it if it wasn't + computed already */ + if(i->cachedTransformations() & CachedTransformation::Absolute) { + if(!(cached & CachedTransformation::Absolute)) { + cached |= CachedTransformation::Absolute; + matrix = Transformation::toMatrix(absoluteTransformation); + } + + i->clean(matrix); + } + + /* Cached inverse absolute transformation, compute it if it wasn't + computed already */ + if(i->cachedTransformations() & CachedTransformation::InvertedAbsolute) { + if(!(cached & CachedTransformation::InvertedAbsolute)) { + cached |= CachedTransformation::InvertedAbsolute; + invertedMatrix = Transformation::toMatrix(Transformation::inverted(absoluteTransformation)); + } + + i->cleanInverted(invertedMatrix); + } + } + + /* Mark object as clean */ + flags &= ~Flag::Dirty; +} + }} #endif