diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 60e66df6..62750d16 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -60,64 +60,49 @@ namespace SHADE camera.dirtyView = true; } + + + UpdateCameraComponent(editorCamera); + + if (SHInputManager::GetKeyDown(SHInputManager::SH_KEYCODE::LEFT_ALT)) + { + UpdateEditorArm(dt, true, SHVec3{ 0.0f }); + } + UpdateEditorArm(dt, false, SHVec3{ 0.0f }); } - void SHCameraSystem::EditorCameraUpdate::Execute(double dt) noexcept - { - SHCameraSystem* system = static_cast(GetSystem()); - auto& camera = system->editorCamera; - SHVec3 view, right, UP; - system->GetCameraAxis(camera, view, right, UP); - if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::A)) + void SHCameraSystem::UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept + { + if (active == false) { - //std::cout << "Camera movement: "<UpdateCameraComponent(system->editorCamera); - system->DecomposeViewMatrix(camera.viewMatrix, camera.pitch, camera.yaw, camera.roll, camera.position); - } + + editorCameraArm.armLength += SHInputManager::GetMouseWheelVerticalDelta() * dt; + + if (editorCameraArm.armLength < 1.0f) + editorCameraArm.armLength = 1.0f; + + UpdatePivotArmComponent(editorCameraArm); + + editorCamera.offset = editorCameraArm.GetOffset(); + + CameraLookAt(editorCamera, targetPos); + + } + void SHCameraSystem::Init(void) { @@ -164,6 +149,9 @@ namespace SHADE void SHCameraSystem::UpdateCameraComponent(SHCameraComponent& camera) noexcept { + if (camera.isActive == false) + return; + if (SHComponentManager::HasComponent(camera.GetEID()) == true && &camera != &editorCamera) { auto transform = SHComponentManager::GetComponent(camera.GetEID()); @@ -183,11 +171,17 @@ namespace SHADE if (SHComponentManager::HasComponent(camera.GetEID())) { auto arm = SHComponentManager::GetComponent(camera.GetEID()); - camera.offset = arm->GetOffset(); - if(arm->lookAtCameraOrigin) - CameraLookAt(camera, camera.position); + if (arm->isActive == true) + { + camera.offset = arm->GetOffset(); + if (arm->lookAtCameraOrigin) + CameraLookAt(camera, camera.position); + } + } + + SHVec3 view, right, UP; diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.h b/SHADE_Engine/src/Camera/SHCameraSystem.h index 98fd442f..fc6e9166 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.h +++ b/SHADE_Engine/src/Camera/SHCameraSystem.h @@ -5,6 +5,7 @@ #include "ECS_Base/System/SHSystemRoutine.h" #include "Resource/SHResourceLibrary.h" #include "SHCameraDirector.h" +#include "SHCameraArmComponent.h" #include "SH_API.h" namespace SHADE @@ -18,6 +19,7 @@ namespace SHADE //A camera component that represents editor camera. //This is not tied to any entity. Hence this EID should not be used. SHCameraComponent editorCamera; + SHCameraArmComponent editorCameraArm; SHResourceLibrary directorLibrary; std::vector directorHandleList; @@ -34,14 +36,7 @@ namespace SHADE void Init (void); void Exit (void); - class SH_API EditorCameraUpdate final : public SHSystemRoutine - { - public: - EditorCameraUpdate() : SHSystemRoutine("Editor Camera Update", true) { }; - virtual void Execute(double dt) noexcept override final; - - }; friend class EditorCameraUpdate; class SH_API CameraSystemUpdate final: public SHSystemRoutine @@ -63,6 +58,7 @@ namespace SHADE void DecomposeViewMatrix(SHMatrix const& matrix, float& pitch, float& yaw, float& roll, SHVec3& pos) noexcept; void SetCameraViewMatrix(SHCameraComponent& camera, SHMatrix const& viewMatrix) noexcept; void CameraLookAt(SHCameraComponent& camera, SHVec3 target) noexcept; + void UpdateEditorArm(double dt,bool active ,SHVec3 const& targetPos) noexcept; };