Browse Source

SceneGraph: code cleanup, documentation, fixed assertions.

The original assertion didn't actually check anything, because the list
was always empty. Moved/copied it to relevant places.
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
177898f93c
  1. 34
      src/SceneGraph/Object.hpp

34
src/SceneGraph/Object.hpp

@ -144,20 +144,36 @@ template<class Transformation> std::vector<typename DimensionTraits<Transformati
return transformationMatrices; return transformationMatrices;
} }
/*
Computing absolute transformations for given list of objects
The goal is to compute absolute transformation only once for each object
involved. Objects contained in the subtree specified by `object` list are
divided into two groups:
- "joints", which are either part of `object` list or they have more than one
child in the subtree
- "non-joints", i.e. paths between joints
Then for all joints their transformation (relative to parent joint) is
computed and recursively concatenated together. Resulting transformations for
joints which were originally in `object` list is then returned.
*/
template<class Transformation> std::vector<typename Transformation::DataType> Object<Transformation>::transformations(std::vector<Object<Transformation>*> objects, const typename Transformation::DataType& initialTransformation) const { template<class Transformation> std::vector<typename Transformation::DataType> Object<Transformation>::transformations(std::vector<Object<Transformation>*> objects, const typename Transformation::DataType& initialTransformation) const {
CORRADE_ASSERT(objects.size() < 0xFFFFu, "SceneGraph::Object::transformations(): too large scene", {});
/* Remember object count for later */ /* Remember object count for later */
std::size_t objectCount = objects.size(); std::size_t objectCount = objects.size();
/** @bug What if there is one objects twice in the list */ /** @bug What if there is one objects twice in the list */
/* Create initial list of joints from original objects */ /* Mark all original objects as joints and create initial list of joints
std::vector<Object<Transformation>*> jointObjects(objects.size()); from them */
for(std::size_t i = 0; i != jointObjects.size(); ++i) { for(std::size_t i = 0; i != objects.size(); ++i) {
jointObjects[i] = static_cast<Object<Transformation>*>(objects[i]); CORRADE_INTERNAL_ASSERT(objects[i]->counter == 0xFFFFu);
CORRADE_INTERNAL_ASSERT(jointObjects[i]->counter == 0xFFFFu); objects[i]->counter = i;
jointObjects[i]->counter = i; objects[i]->flags |= Flag::Joint;
jointObjects[i]->flags |= Flag::Joint;
} }
std::vector<Object<Transformation>*> jointObjects(objects);
/* Scene object */ /* Scene object */
const Scene<Transformation>* scene = this->scene(); const Scene<Transformation>* scene = this->scene();
@ -186,6 +202,8 @@ template<class Transformation> std::vector<typename Transformation::DataType> Ob
/* If not already marked as joint, mark it as such and add it to /* If not already marked as joint, mark it as such and add it to
list of joint objects */ list of joint objects */
if(!(parent->flags & Flag::Joint)) { if(!(parent->flags & Flag::Joint)) {
CORRADE_ASSERT(jointObjects.size() < 0xFFFFu,
"SceneGraph::Object::transformations(): too large scene", {});
CORRADE_INTERNAL_ASSERT(parent->counter == 0xFFFFu); CORRADE_INTERNAL_ASSERT(parent->counter == 0xFFFFu);
parent->counter = jointObjects.size(); parent->counter = jointObjects.size();
parent->flags |= Flag::Joint; parent->flags |= Flag::Joint;
@ -199,8 +217,6 @@ template<class Transformation> std::vector<typename Transformation::DataType> Ob
if(it == objects.end()) it = objects.begin(); if(it == objects.end()) it = objects.begin();
} }
CORRADE_ASSERT(objects.size() < 0xFFFFu, "SceneGraph::Object::transformations(): too large scene", {});
/* Array of absolute transformations in joints */ /* Array of absolute transformations in joints */
std::vector<typename Transformation::DataType> jointTransformations(jointObjects.size()); std::vector<typename Transformation::DataType> jointTransformations(jointObjects.size());

Loading…
Cancel
Save