From 895eb56cc01cb7fc17446fecda47020fd3e5e8e6 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Sun, 13 Nov 2022 17:26:21 +0800 Subject: [PATCH] Integrate cam arm --- SHADE_Engine/src/Camera/SHCameraSystem.cpp | 8 ------ .../ViewportWindow/SHEditorViewport.cpp | 27 ++++++++++++++++--- .../ViewportWindow/SHEditorViewport.h | 2 ++ 3 files changed, 26 insertions(+), 11 deletions(-) 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