diff options
author | Paul Lemire <paul.lemire@kdab.com> | 2015-11-04 15:26:13 +0100 |
---|---|---|
committer | Andy Nichols <andy.nichols@theqtcompany.com> | 2015-11-16 09:17:49 +0000 |
commit | 06e5c80e23e8578517eb47bf2acee9d086fac9ce (patch) | |
tree | cd940f6d694e685d8bc63f400c185d56f632fc2e /src/render/jobs | |
parent | c86d743aa9039df38a19f387969f62afb528023c (diff) |
Update bounding volume job to actually compute something
Change-Id: Ie30ff21112f6fbaf6bb990a8662c24375d237c96
Reviewed-by: Andy Nichols <andy.nichols@theqtcompany.com>
Diffstat (limited to 'src/render/jobs')
-rw-r--r-- | src/render/jobs/updateboundingvolumejob.cpp | 46 |
1 files changed, 10 insertions, 36 deletions
diff --git a/src/render/jobs/updateboundingvolumejob.cpp b/src/render/jobs/updateboundingvolumejob.cpp index deaaab756..b31b7e85f 100644 --- a/src/render/jobs/updateboundingvolumejob.cpp +++ b/src/render/jobs/updateboundingvolumejob.cpp @@ -41,8 +41,6 @@ #include <Qt3DRender/private/renderlogging_p.h> #include <Qt3DRender/private/sphere_p.h> -#include <QElapsedTimer> -#include <QStack> #include <QThread> QT_BEGIN_NAMESPACE @@ -54,41 +52,17 @@ namespace { void expandWorldBoundingVolume(Qt3DRender::Render::Entity *node) { - Qt3DRender::Render::Entity *currentNode = node; - QStack<int> childIndexStack; - forever { - - // Find left most leaf node of currentNode - while (!currentNode && !currentNode->children().isEmpty()) { - childIndexStack.push(1); - currentNode = currentNode->children().first(); - } - - if (!currentNode || !currentNode->parent()) - return; - - // Initialize parent bounding volume to be equal to that of the first child - Qt3DRender::Render::Entity *parentNode = currentNode->parent(); + // Go to the nodes that have the most depth + Q_FOREACH (Entity *c, node->children()) + expandWorldBoundingVolume(c); + + // Then traverse to root + // Initialize parent bounding volume to be equal to that of the first child + Qt3DRender::Render::Entity *parentNode = node->parent(); + if (parentNode) { Qt3DRender::Render::Sphere *parentBoundingVolume = parentNode->worldBoundingVolumeWithChildren(); - *(parentBoundingVolume) = *(currentNode->worldBoundingVolumeWithChildren()); - - // Expand the parent bounding volume by each of remaining the siblings - QVector<Entity *> siblings = parentNode->children(); - const int siblingCount = siblings.count(); - for (int i = 1; i < siblingCount; ++i) { - Qt3DRender::Render::Sphere *siblingBoundingVolume = siblings.at(i)->worldBoundingVolumeWithChildren(); - parentBoundingVolume->expandToContain(*siblingBoundingVolume); - } - - // Move to parent's next sibling - childIndexStack.pop(); - currentNode = Q_NULLPTR; - if (!childIndexStack.empty() && parentNode->parent()) { - const int nextSiblingIndex = childIndexStack.top()++; - QVector<Entity *> parentSiblings = parentNode->parent()->children(); - if (nextSiblingIndex < parentSiblings.size()) - currentNode = parentSiblings.at(nextSiblingIndex); - } + Qt3DRender::Render::Sphere *nodeBoundingVolume = node->worldBoundingVolumeWithChildren(); + parentBoundingVolume->expandToContain(*nodeBoundingVolume); } } |