diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index 1731eddf..e174f19b 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -79,6 +79,7 @@ namespace Nuake { { ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0)); std::string name = ICON_FA_GAMEPAD + std::string(" Scene"); + if (ImGui::Begin(name.c_str())) { ImGui::PopStyleVar(); @@ -242,8 +243,11 @@ namespace Nuake { } } - if (m_IsHoveringViewport && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_1) && !ImGuizmo::IsUsing()) + m_IsViewportFocused = ImGui::IsWindowFocused(); + if (m_IsHoveringViewport && Input::IsMouseButtonPressed(GLFW_MOUSE_BUTTON_2) && !ImGuizmo::IsUsing()) { + ImGui::FocusWindow(ImGui::GetCurrentWindow()); + const auto windowPosNuake = Vector2(windowPos.x, windowPos.y); auto& gbuffer = Engine::GetCurrentScene()->mSceneRenderer->GetGBuffer(); auto pixelPos = Input::GetMousePosition() - windowPosNuake; @@ -1513,7 +1517,11 @@ namespace Nuake { } auto& editorCam = Engine::GetCurrentScene()->m_EditorCamera; - editorCam->Update(ts, m_IsHoveringViewport); + + if (m_IsViewportFocused) + { + editorCam->Update(ts, m_IsHoveringViewport); + } const bool entityIsSelected = Selection.Type == EditorSelectionType::Entity && Selection.Entity.IsValid(); if (entityIsSelected && Input::IsKeyPressed(GLFW_KEY_F)) diff --git a/Editor/src/Windows/EditorInterface.h b/Editor/src/Windows/EditorInterface.h index 57f5ac94..740b3a1b 100644 --- a/Editor/src/Windows/EditorInterface.h +++ b/Editor/src/Windows/EditorInterface.h @@ -26,6 +26,8 @@ namespace Nuake bool m_DebugCollisions = true; bool m_ShowOverlay = true; bool m_IsHoveringViewport = false; + bool m_IsViewportFocused = false; + Vector2 m_ViewportPos = {0, 0}; Vector2 m_ViewportSize = {}; diff --git a/Nuake/src/Scene/EditorCamera.cpp b/Nuake/src/Scene/EditorCamera.cpp index 9d80a962..79d0c177 100644 --- a/Nuake/src/Scene/EditorCamera.cpp +++ b/Nuake/src/Scene/EditorCamera.cpp @@ -164,6 +164,8 @@ namespace Nuake mouseLastX = x; mouseLastY = y; controlled = true; + + SetDirection(glm::normalize(Direction)); } else if (Input::YScroll != 0) { @@ -171,6 +173,7 @@ namespace Nuake Input::YScroll = 0.0f; } + SetDirection(glm::normalize(Direction)); mouseLastX = x; mouseLastY = y; } @@ -192,7 +195,8 @@ namespace Nuake Direction.y = sin(glm::radians(Pitch)); Direction.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch)); Direction = glm::normalize(Direction); - Right = glm::normalize(glm::cross(Up, Direction)); + SetDirection(Direction); + } void EditorCamera::SetYaw(float yaw)