diff --git a/include/Scene.h b/include/Scene.h index 4aada7f..6e6e92c 100644 --- a/include/Scene.h +++ b/include/Scene.h @@ -4,6 +4,7 @@ #include #include "Model.h" +#include "Camera.h" // Класс сцены class Scene @@ -20,6 +21,7 @@ class Scene // Списки объектов, выступающих узлами std::list nodes; // Список пустых узлов std::list models; // Список моделей для рендера + std::list cameras; // Список камер protected: void rebuld_tree(const Scene& from); // Перестройка дерева после копирования или присваивания diff --git a/src/Camera.cpp b/src/Camera.cpp index 9ebcdb2..ba1f8ad 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -1,7 +1,7 @@ #include "Camera.h" // Защищенный (protected) конструктор камеры без перспективы -Camera::Camera(const glm::vec3 &pos, const glm::vec3 &initialRotation) +Camera::Camera(const glm::vec3 &pos, const glm::vec3 &initialRotation) : Node(NULL) // Пусть по умолчанию камера не относится к сцене { sensitivity = CAMERA_DEFAULT_SENSIVITY; position = pos; // задаем позицию @@ -30,7 +30,7 @@ Camera::Camera(float width, float height, const glm::vec3 &position, const glm:: // Конструктор копирования камеры Camera::Camera(const Camera& copy) -: projection(copy.projection), requiredRecalcVP(copy.requiredRecalcVP), sensitivity(copy.sensitivity) +: Node(copy), projection(copy.projection), requiredRecalcVP(copy.requiredRecalcVP), sensitivity(copy.sensitivity) { // Если у оригинала не было изменений - перепишем матрицу вида-проекции if (!requiredRecalcVP) @@ -40,6 +40,8 @@ Camera::Camera(const Camera& copy) // Оператор присваивания Camera& Camera::operator=(const Camera& other) { + Node::operator=(other); // Вызов родительского оператора= для переноса узла + projection = other.projection; requiredRecalcVP = other.requiredRecalcVP; sensitivity = other.sensitivity; diff --git a/src/Scene.cpp b/src/Scene.cpp index c03dbde..1a36fce 100644 --- a/src/Scene.cpp +++ b/src/Scene.cpp @@ -3,12 +3,12 @@ // Конструктор пустой сцены Scene::Scene() { - + } // Конструктор копирования Scene::Scene(const Scene ©): root(copy.root), -nodes(copy.nodes), models(copy.models) +nodes(copy.nodes), models(copy.models), cameras(copy.cameras) { rebuld_tree(copy); } @@ -19,6 +19,7 @@ Scene& Scene::operator=(const Scene& other) root = other.root; nodes = other.nodes; models = other.models; + cameras = other.cameras; rebuld_tree(other); @@ -51,6 +52,10 @@ void Scene::rebuild_Nodes_list(T& nodes, const Scene& from) // Если можно привести к модели, то ищем родителя среди моделей if (dynamic_cast(parent)) move_parent(*it, from.models, this->models); + else + // Иначе проверяем на принадлежность к камерам + if (dynamic_cast(parent)) + move_parent(*it, from.cameras, this->cameras); // Иначе это пустой узел else move_parent(*it, from.nodes, this->nodes); @@ -80,4 +85,5 @@ void Scene::rebuld_tree(const Scene& from) // Восстановим родителей в пустых узлах для копии rebuild_Nodes_list(nodes, from); rebuild_Nodes_list(models, from); + rebuild_Nodes_list(cameras, from); }