Browse Source

SceneGraph: externalized object cleaning function.

Will be used elsewhere.
pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
466008bba8
  1. 2
      src/SceneGraph/Object.h
  2. 73
      src/SceneGraph/Object.hpp

2
src/SceneGraph/Object.h

@ -213,6 +213,8 @@ template<class Transformation> class Object: public AbstractObject<Transformatio
typename Transformation::DataType computeJointTransformation(const std::vector<Object<Transformation>*>& jointObjects, std::vector<typename Transformation::DataType>& jointTransformations, const std::size_t joint, const typename Transformation::DataType& initialTransformation) const; typename Transformation::DataType computeJointTransformation(const std::vector<Object<Transformation>*>& jointObjects, std::vector<typename Transformation::DataType>& 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::ObjectFlag Flag;
typedef Implementation::ObjectFlags Flags; typedef Implementation::ObjectFlags Flags;
std::uint16_t counter; std::uint16_t counter;

73
src/SceneGraph/Object.hpp

@ -123,42 +123,9 @@ template<class Transformation> void Object<Transformation>::setClean() {
Object<Transformation>* o = objects.top(); Object<Transformation>* o = objects.top();
objects.pop(); objects.pop();
/* Compose transformations */ /* Compose transformation and clean object */
absoluteTransformation = Transformation::compose(absoluteTransformation, o->transformation()); absoluteTransformation = Transformation::compose(absoluteTransformation, o->transformation());
o->setClean(absoluteTransformation);
/* "Lazy storage" for transformation matrix and inverted transformation matrix */
typedef typename AbstractFeature<Transformation::Dimensions, typename Transformation::Type>::CachedTransformation CachedTransformation;
typename AbstractFeature<Transformation::Dimensions, typename Transformation::Type>::CachedTransformations cached;
typename DimensionTraits<Transformation::Dimensions, typename Transformation::Type>::MatrixType
matrix, invertedMatrix;
/* Clean all features */
for(AbstractFeature<Transformation::Dimensions, typename Transformation::Type>* 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;
} }
} }
@ -286,6 +253,42 @@ template<class Transformation> typename Transformation::DataType Object<Transfor
} }
} }
template<class Transformation> void Object<Transformation>::setClean(const typename Transformation::DataType& absoluteTransformation) {
/* "Lazy storage" for transformation matrix and inverted transformation matrix */
typedef typename AbstractFeature<Transformation::Dimensions, typename Transformation::Type>::CachedTransformation CachedTransformation;
typename AbstractFeature<Transformation::Dimensions, typename Transformation::Type>::CachedTransformations cached;
typename DimensionTraits<Transformation::Dimensions, typename Transformation::Type>::MatrixType
matrix, invertedMatrix;
/* Clean all features */
for(AbstractFeature<Transformation::Dimensions, typename Transformation::Type>* 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 #endif

Loading…
Cancel
Save