From ddeafd7bfa61cfc48ba46ed0e5e67ddae51ef316 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Tue, 27 Aug 2024 14:07:04 -0400 Subject: [PATCH] Added snapping --- Editor/src/Windows/EditorInterface.cpp | 51 +++++++++++++++++++++++++- Editor/src/Windows/EditorInterface.h | 2 + 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 08e54f0b..7cccf725 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -264,7 +264,8 @@ namespace Nuake { glm::value_ptr(cameraView), glm::value_ptr(cameraProjection), CurrentOperation, CurrentMode, - glm::value_ptr(transform) + glm::value_ptr(transform), NULL, + UseSnapping ? &CurrentSnapping.x : NULL ); if (ImGuizmo::IsUsing()) @@ -2427,6 +2428,54 @@ namespace Nuake { ImGui::PopStyleColor(); } + ImGui::SameLine(); + + selectedMode = CurrentMode == ImGuizmo::MODE::WORLD; + if (selectedMode) + { + Color color = Engine::GetProject()->Settings.PrimaryColor; + ImGui::PushStyleColor(ImGuiCol_Button, { color.r, color.g, color.b, 1.0f }); + } + + if (ImGui::Button(ICON_FA_GLOBE, ImVec2(30, 28))) + { + CurrentMode = ImGuizmo::MODE::WORLD; + } + + if (selectedMode) + { + ImGui::PopStyleColor(); + } + + ImGui::SameLine(); + + selectedMode = CurrentMode == ImGuizmo::MODE::LOCAL; + if (selectedMode) + { + Color color = Engine::GetProject()->Settings.PrimaryColor; + ImGui::PushStyleColor(ImGuiCol_Button, { color.r, color.g, color.b, 1.0f }); + } + + if (ImGui::Button(ICON_FA_CUBE, ImVec2(30, 28))) + { + CurrentMode = ImGuizmo::MODE::LOCAL; + } + + if (selectedMode) + { + ImGui::PopStyleColor(); + } + + ImGui::SameLine(); + + ImGui::Checkbox("Snapping", &UseSnapping); + + if (UseSnapping) + { + ImGui::SameLine(); + ImGui::DragFloat("##snapping", &CurrentSnapping.x, 0.01f, 0.0f, 100.0f); + } + ImGui::PopStyleVar(); ImGui::PopStyleVar(); ImGui::PopStyleColor(); diff --git a/Editor/src/Windows/EditorInterface.h b/Editor/src/Windows/EditorInterface.h index def15988..944e0111 100644 --- a/Editor/src/Windows/EditorInterface.h +++ b/Editor/src/Windows/EditorInterface.h @@ -51,6 +51,8 @@ namespace Nuake ImGuizmo::OPERATION CurrentOperation = ImGuizmo::TRANSLATE; ImGuizmo::MODE CurrentMode = ImGuizmo::WORLD; + bool UseSnapping = false; + Vector3 CurrentSnapping = { 0.0f, 0.0f, 0.0f }; Ref m_SelectedMaterial; Ref m_CurrentDirectory;