From 78e37ade6ca1f861922d46cb1d9e23813941b5dd Mon Sep 17 00:00:00 2001 From: Shuyan Hu Date: Tue, 26 Apr 2022 10:45:52 +0800 Subject: [PATCH] can adjust camera move speed by holding right mouse button and scroll (#140) * can adjust camera move speed by holding right mouse button and scroll * fix the coding style * coding style Co-authored-by: Shuyan Hu Co-authored-by: Olorin --- engine/source/editor/include/editor_ui.h | 1 + engine/source/editor/source/editor_ui.cpp | 27 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/engine/source/editor/include/editor_ui.h b/engine/source/editor/include/editor_ui.h index d8fd1a38c..2f81686d6 100644 --- a/engine/source/editor/include/editor_ui.h +++ b/engine/source/editor/include/editor_ui.h @@ -80,6 +80,7 @@ namespace Pilot Vector2 m_engine_window_size {1280.0f, 768.0f}; float m_mouse_x {0.0f}; float m_mouse_y {0.0f}; + float m_camera_speed {0.05f}; bool m_is_editor_mode {true}; int m_key_state {0}; diff --git a/engine/source/editor/source/editor_ui.cpp b/engine/source/editor/source/editor_ui.cpp index 749ed1b17..120cbcd22 100644 --- a/engine/source/editor/source/editor_ui.cpp +++ b/engine/source/editor/source/editor_ui.cpp @@ -37,6 +37,7 @@ namespace Pilot Pilot::Quaternion& values, float resetValue = 0.0f, float columnWidth = 100.0f); + EditorUI::EditorUI(PilotEditor* editor) : m_editor(editor) { Path& path_service = Path::getInstance(); @@ -690,6 +691,11 @@ namespace Pilot { ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "Press Left Alt key to display the mouse cursor!"); } + else + { + ImGui::TextColored( + ImVec4(0.0f, 1.0f, 0.0f, 1.0f), "Current editor camera move speed: [%f]", m_camera_speed); + } auto menu_bar_rect = ImGui::GetCurrentWindow()->MenuBarRect(); @@ -877,7 +883,7 @@ namespace Pilot void EditorUI::processEditorCommand() { - float camera_speed = 0.05f; + float camera_speed = m_camera_speed; Quaternion camera_rotate = m_tmp_uistate->m_editor_camera->rotation().inverse(); Vector3 camera_relative_pos(0, 0, 0); @@ -977,10 +983,25 @@ namespace Pilot { return; } - // wheel scrolled up = zoom in by 2 extra degrees + if (isCursorInRect(m_engine_window_pos, m_engine_window_size)) { - m_tmp_uistate->m_editor_camera->zoom((float)yoffset * 2.0f); + if (m_io->isMouseButtonDown(GLFW_MOUSE_BUTTON_RIGHT)) + { + if (yoffset > 0) + { + m_camera_speed *= 1.2f; + } + else + { + m_camera_speed *= 0.8f; + } + } + else + { + m_tmp_uistate->m_editor_camera->zoom((float)yoffset * + 2.0f); // wheel scrolled up = zoom in by 2 extra degrees + } } }