Камера как часть сцены

This commit is contained in:
2023-10-17 02:14:37 +03:00
committed by re.kovalev
parent 7e1ffdfdfb
commit 7dba133763
3 changed files with 14 additions and 4 deletions

View File

@@ -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;

View File

@@ -3,12 +3,12 @@
// Конструктор пустой сцены
Scene::Scene()
{
}
// Конструктор копирования
Scene::Scene(const Scene &copy): 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<Model*>(parent))
move_parent(*it, from.models, this->models);
else
// Иначе проверяем на принадлежность к камерам
if (dynamic_cast<Camera*>(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);
}