diff --git a/node.cpp b/node.cpp index 4da8090..7472f30 100755 --- a/node.cpp +++ b/node.cpp @@ -58,9 +58,6 @@ namespace vb01{ for(Skeleton *sk : skeletons) sk->update(); - - for(Node *c : children) - c->update(); } for(Driver *driver : drivers) diff --git a/root.cpp b/root.cpp index 9aa0328..0c9545c 100755 --- a/root.cpp +++ b/root.cpp @@ -153,7 +153,7 @@ namespace vb01{ AnimationController::getSingleton()->update(); - rootNode->update(); + updateNodeTree(rootNode); LineRenderer::getSingleton()->drawLines(); @@ -167,12 +167,38 @@ namespace vb01{ updateGuiPlane(); glEnable(GL_DEPTH_TEST); - guiNode->update(); + updateNodeTree(guiNode); glfwSwapBuffers(window); glfwPollEvents(); } + //TODO replace sorting algorithm and sort only transparent objects + void Root::updateNodeTree(Node *node){ + vector descendants; + node->getDescendants(descendants); + + int numDesc = descendants.size(); + + for(int i = 0; i < numDesc; i++){ + Vector3 v1 = descendants[i]->getPosition() - camera->getPosition(); + float a1 = v1.norm().getAngleBetween(camera->getDirection()); + float d1 = v1.getLength() * cos(a1); + + for(int j = i; j < numDesc; j++){ + Vector3 v2 = descendants[j]->getPosition() - camera->getPosition(); + float a2 = v2.norm().getAngleBetween(camera->getDirection()); + float d2 = v2.getLength() * cos(a2); + + if(d1 < d2) + swap(descendants[i], descendants[j]); + } + } + + for(Node *desc : descendants) + desc->update(); + } + void Root::updateBloomFramebuffer(){ bool horizontal = false; blurShader->use(); diff --git a/root.h b/root.h index d9aeda9..ddabe3b 100755 --- a/root.h +++ b/root.h @@ -69,6 +69,7 @@ namespace vb01{ void initGuiPlane(Texture*, Texture*); void updateBloomFramebuffer(); void updateGuiPlane(); + void updateNodeTree(vb01::Node*); }; }