implemented find/swap/pop for removing object of scene tree

This commit is contained in:
Lendemor 2016-06-15 20:04:44 +02:00
parent aeaf4e08dd
commit 4295481cfe
2 changed files with 13 additions and 8 deletions

View File

@ -1,7 +1,7 @@
#include "scenetree.h"
#include "resourcemanager.h"
#include <pipeline.h>
#include <algorithm>
// Scene
SceneTree::SceneTree() :
@ -42,19 +42,23 @@ void SceneTree::addObject(ContainerNode *parent, SceneNode *node)
parent->addChild(node);
Light *light = node->getLight();
GeometryNode *geometrynode = node->getGeometryNode();
//TODO : Check for doublon in m_lights et m_geometries
//TODO : Check for doublon in m_lights et m_geometries => not necessary if correctly removed ?
if (light) m_lights.push_back(light);
if (geometrynode) m_geometries.push_back(geometrynode);
}
void SceneTree::removeObject(ContainerNode* parent,SceneNode *node){
parent->removeChild(node);
Light *l = node->getLight();
GeometryNode *g = node->getGeometryNode();
//TODO : remove light and geometrynode from m_lights et m_geometries
// debug following line
// m_lights.erase(std::remove(m_lights.begin(),m_lights.end(),&(*l)),m_lights.end());
// m_geometries.erase(std::remove(m_geometries.begin(),m_geometries.end(),g),m_geometries.end());
auto it_l = std::find(m_lights.begin(),m_lights.end(),node->getLight());
if (it_l != m_lights.end()){
std::iter_swap(it_l,m_lights.end()-1);
m_lights.pop_back();
}
auto it_g = std::find(m_geometries.begin(),m_geometries.end(),node->getGeometryNode());
if (it_g != m_geometries.end()){
std::iter_swap(it_g,m_geometries.end()-1);
m_geometries.pop_back();
}
}

View File

@ -46,6 +46,7 @@ protected:
/**
* @brief The CameraNode class is a scene node that can be used by the renderer
*/
//TODO : Fix compil error here
class CameraNode : public Camera, SceneNode
{