diff --git a/src/edit/include/edit/editor.hpp b/src/edit/include/edit/editor.hpp index 79d377583c17cdc1dc73d348f154097671a986d5..f10828edeeb87c6983d204d95727c07561d4653e 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 fc2287cae3abc8169d359d8ad04da9ff54e9c961..0c61122d8ea943bf6e8adf36909538c48ca1b3e2 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));