diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 8f886926..ff942666 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -63,14 +63,6 @@ namespace SHADE } UpdateCameraComponent(editorCamera); - - if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::LEFT_ALT)) - { - UpdateEditorArm(dt, true, SHVec3{ 0.0f }); - } - else - UpdateEditorArm(dt, false, SHVec3{ 0.0f }); - } void SHCameraSystem::UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept diff --git a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp index 7b3b5411..d0b32ff5 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.cpp @@ -33,14 +33,32 @@ namespace SHADE void SHEditorViewport::Update() { SHEditorWindow::Update(); - if (shouldUpdateCamera) + auto camSystem = SHSystemManager::GetSystem(); + SHEditor* editor = SHSystemManager::GetSystem(); + + if (!editor->selectedEntities.empty()) + { + if (SHTransformComponent* transform = SHComponentManager::GetComponent_s(editor->selectedEntities.front())) + { + targetPos = transform->GetWorldPosition(); + } + else + { + targetPos = {}; + } + } + else + { + targetPos = {}; + } + if (shouldUpdateCamera || shouldUpdateCamArm) { - auto camSystem = SHSystemManager::GetSystem(); camSystem->UpdateEditorCamera(SHFrameRateController::GetRawDeltaTime()); shouldUpdateCamera = false; } + camSystem->UpdateEditorArm(SHFrameRateController::GetRawDeltaTime(), shouldUpdateCamArm, targetPos); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); - SHEditor* editor = SHSystemManager::GetSystem(); if (Begin()) { @@ -64,6 +82,9 @@ namespace SHADE shouldUpdateCamera = true; } + + shouldUpdateCamArm = ImGui::IsWindowHovered() && ImGui::IsKeyDown(ImGuiKey_LeftAlt) && ImGui::IsMouseDown(ImGuiMouseButton_Left); + if (editor->editorState != SHEditor::State::PLAY && ImGui::IsWindowFocused() && !ImGui::IsMouseDown(ImGuiMouseButton_Right)) { if (ImGui::IsKeyReleased(ImGuiKey_W)) diff --git a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.h b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.h index 0fae4317..8f49c514 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.h +++ b/SHADE_Engine/src/Editor/EditorWindow/ViewportWindow/SHEditorViewport.h @@ -29,5 +29,7 @@ namespace SHADE void DrawMenuBar() noexcept; SHVec2 beginCursorPos; bool shouldUpdateCamera = false; + bool shouldUpdateCamArm = false; + SHVec3 targetPos; };//class SHEditorViewport }//namespace SHADE