From 488f829c7233277adac6ea649d8bda2a001d29f8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20=C5=A0toura=C4=8D?= <525032@mail.muni.cz>
Date: Fri, 13 Oct 2023 22:37:08 +0200
Subject: [PATCH] objects add into active depth

---
 src/edit/include/edit/editor.hpp | 20 ++++++++++++++++++++
 src/edit/src/editor.cpp          |  9 ++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/edit/include/edit/editor.hpp b/src/edit/include/edit/editor.hpp
index 79d3775..f10828e 100644
--- a/src/edit/include/edit/editor.hpp
+++ b/src/edit/include/edit/editor.hpp
@@ -9,6 +9,7 @@
 #include <osi/window.hpp>
 #include <utils/math.hpp>
 
+#include <array>
 #include <memory>
 
 using ctrlhub_ptr = std::shared_ptr<ControlHub>;
@@ -19,10 +20,29 @@ namespace edit
 
     enum class state { select, move, rotate, plus };
 
+class Level
+{
+    std::array<float, 3> axes = {0.0f, 0.0f, 0.0f};
+
+    std::uint8_t active = 2;
+
+public:
+    std::uint8_t getActiveIndex() const { return active; }
+    float getActive() const { return axes[active]; }
+    void setActiveX() { active = 0; }
+    void setActiveY() { active = 1; }
+    void setActiveZ() { active = 2; }
+
+    Level& operator++() { ++axes[active]; return *this; }
+    Level& operator--() { --axes[active]; return *this; }
+};
+
+
 class Editor
 {
     bool editor_running = false;
     state control_state = state::select;
+    Level build_level;
 
     bool object_moving = false;
     glm::vec3 prev_plane_intersect;
diff --git a/src/edit/src/editor.cpp b/src/edit/src/editor.cpp
index fc2287c..0c61122 100644
--- a/src/edit/src/editor.cpp
+++ b/src/edit/src/editor.cpp
@@ -90,9 +90,16 @@ void Editor::addObject(scene_ptr scene, ctrlhub_ptr controls)
 
     auto [ ray_position , ray_direction ] = get_pick_ray(scene, mouse, window);
 
-    float distance = glm::length(ray_position - position);
+    bool cam_is_perspective = scene->getActiveCameras()[0].lock()->isPerspective();
+    float distance = cam_is_perspective
+                     ? glm::length(ray_position - position)
+                     : 1.0f;
     
     auto new_item_pos = ray_position + distance * ray_direction;
+
+    if (!cam_is_perspective)
+        new_item_pos[build_level.getActiveIndex()] = build_level.getActive();
+
     Frame new_item_frame(new_item_pos, rotation, scale);
     Node selection_copy(std::make_shared<Frame>(new_item_frame));
 
-- 
GitLab