From 29b6e7050d742c4a104417f33f2dfb1e269fb237 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Fri, 21 Oct 2022 08:11:12 +0800 Subject: [PATCH 1/7] camera director WIP --- SHADE_Engine/src/Camera/SHCameraDirector.cpp | 50 ++++++++++++++++++++ SHADE_Engine/src/Camera/SHCameraDirector.h | 36 ++++++++++++++ SHADE_Engine/src/Camera/SHCameraSystem.cpp | 10 ++++ SHADE_Engine/src/Camera/SHCameraSystem.h | 18 +++++-- 4 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 SHADE_Engine/src/Camera/SHCameraDirector.cpp create mode 100644 SHADE_Engine/src/Camera/SHCameraDirector.h diff --git a/SHADE_Engine/src/Camera/SHCameraDirector.cpp b/SHADE_Engine/src/Camera/SHCameraDirector.cpp new file mode 100644 index 00000000..4ade9dbd --- /dev/null +++ b/SHADE_Engine/src/Camera/SHCameraDirector.cpp @@ -0,0 +1,50 @@ +#include "SHpch.h" +#include "SHCameraDirector.h" +#include "SHCameraComponent.h" +#include "ECS_Base/Managers/SHComponentManager.h" +#include "ECS_Base/SHECSMacros.h" +#include "Tools/SHLog.h" + +namespace SHADE +{ + SHCameraDirector::SHCameraDirector() + :mainCameraEID(MAX_EID), transitionCameraEID(MAX_EID) + { + } + + + SHMatrix SHCameraDirector::GetViewMatrix() const noexcept + { + return viewMatrix; + } + SHMatrix SHCameraDirector::GetProjMatrix() const noexcept + { + return projMatrix; + } + SHMatrix SHCameraDirector::GetVPMatrix() const noexcept + { + return projMatrix * viewMatrix; + } + + void SHCameraDirector::UpdateMatrix() noexcept + { + if (mainCameraEID == MAX_EID) + { + return; + } + SHCameraComponent* camComponent = SHComponentManager::GetComponent_s(mainCameraEID); + if (!camComponent) + { + SHLOG_WARNING("Camera Director warning: Entity does not have a camera"); + } + else + { + viewMatrix = camComponent->GetViewMatrix(); + projMatrix = camComponent->GetProjMatrix(); + } + + + } + + +} diff --git a/SHADE_Engine/src/Camera/SHCameraDirector.h b/SHADE_Engine/src/Camera/SHCameraDirector.h new file mode 100644 index 00000000..00e2d0c2 --- /dev/null +++ b/SHADE_Engine/src/Camera/SHCameraDirector.h @@ -0,0 +1,36 @@ +#pragma once + +#include "SH_API.h" +#include "ECS_Base/Entity/SHEntity.h" +#include "Math/SHMatrix.h" + + +namespace SHADE +{ + class SH_API SHCameraDirector + { + public: + SHCameraDirector(); + ~SHCameraDirector() = default; + + + EntityID mainCameraEID; + EntityID transitionCameraEID; + + SHMatrix GetViewMatrix() const noexcept; + SHMatrix GetProjMatrix() const noexcept; + SHMatrix GetVPMatrix() const noexcept; + void UpdateMatrix() noexcept; + + + private: + + + protected: + SHMatrix viewMatrix; + SHMatrix projMatrix; + + }; + + +} diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index a9b356de..e0d983b2 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -3,6 +3,7 @@ #include "Math/SHMathHelpers.h" #include "Input/SHInputManager.h" #include "Math/Vector/SHVec2.h" +#include "ECS_Base/Managers/SHComponentManager.h" @@ -169,5 +170,14 @@ namespace SHADE upVec = SHVec3::Cross(forward, right); } + void SHCameraSystem::CameraSystemUpdate::Execute(double dt) noexcept + { + SHCameraSystem* system = static_cast(GetSystem()); + auto& dense = SHComponentManager::GetDense(); + for (auto& cam : dense) + { + system->UpdateCameraComponent(cam); + } + } } diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.h b/SHADE_Engine/src/Camera/SHCameraSystem.h index 43e386e7..2f8e6142 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.h +++ b/SHADE_Engine/src/Camera/SHCameraSystem.h @@ -3,8 +3,9 @@ #include "ECS_Base/System/SHSystem.h" #include "SHCameraComponent.h" #include "ECS_Base/System/SHSystemRoutine.h" -#include "SH_API.h" +#include "Resource/ResourceLibrary.h" +#include "SH_API.h" namespace SHADE { @@ -14,7 +15,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; - + public: @@ -34,13 +35,22 @@ namespace SHADE }; friend class EditorCameraUpdate; - SHCameraComponent* GetEditorCamera (void) noexcept; + class SH_API CameraSystemUpdate final: public SHSystemRoutine + { + public: + CameraSystemUpdate() : SHSystemRoutine("Camera System Update", false) {}; + virtual void Execute(double dt)noexcept override final; + }; + friend class CameraSystemUpdate; + + SHCameraComponent* GetEditorCamera (void) noexcept; + void GetCameraAxis(SHCameraComponent const& camera, SHVec3& forward, SHVec3& right, SHVec3& up) const noexcept; protected: void UpdateCameraComponent(SHCameraComponent& camera) noexcept; - void GetCameraAxis(SHCameraComponent const& camera, SHVec3& forward, SHVec3& right, SHVec3& up) const noexcept; + }; From 31ad8b8c87398b96bb6ca55c2cc18af89d7b61db Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Fri, 21 Oct 2022 09:29:13 +0800 Subject: [PATCH 2/7] Added Resource Lib and handle for CameraDirector into camera system --- SHADE_Engine/src/Camera/SHCameraSystem.cpp | 14 ++++++++++++++ SHADE_Engine/src/Camera/SHCameraSystem.h | 7 +++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index e0d983b2..02e6cd1c 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -178,6 +178,20 @@ namespace SHADE { system->UpdateCameraComponent(cam); } + for (auto& handle : system->directorHandleList) + { + handle->UpdateMatrix(); + } + + + } + + + Handle SHCameraSystem::CreateDirector() noexcept + { + auto handle = directorLibrary.Create(); + directorHandleList.emplace_back(handle); + return handle; } } diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.h b/SHADE_Engine/src/Camera/SHCameraSystem.h index 2f8e6142..5b946389 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.h +++ b/SHADE_Engine/src/Camera/SHCameraSystem.h @@ -4,7 +4,8 @@ #include "SHCameraComponent.h" #include "ECS_Base/System/SHSystemRoutine.h" #include "Resource/ResourceLibrary.h" - +#include "SHCameraDirector.h" +#include "Resource/Handle.h" #include "SH_API.h" namespace SHADE @@ -16,7 +17,8 @@ namespace SHADE //This is not tied to any entity. Hence this EID should not be used. SHCameraComponent editorCamera; - + ResourceLibrary directorLibrary; + std::vector> directorHandleList; public: SHCameraSystem(void) = default; @@ -46,6 +48,7 @@ namespace SHADE SHCameraComponent* GetEditorCamera (void) noexcept; void GetCameraAxis(SHCameraComponent const& camera, SHVec3& forward, SHVec3& right, SHVec3& up) const noexcept; + Handle CreateDirector() noexcept; protected: void UpdateCameraComponent(SHCameraComponent& camera) noexcept; From 267ad5f8c6a82ddb422ab7a00671581e12d67272 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Fri, 21 Oct 2022 09:53:19 +0800 Subject: [PATCH 3/7] Set up the CameraDirector creation and setting of main camera --- SHADE_Engine/src/Camera/SHCameraComponent.cpp | 11 ++++++++++- SHADE_Engine/src/Camera/SHCameraComponent.h | 2 ++ SHADE_Engine/src/Camera/SHCameraDirector.cpp | 12 +++++++++++- SHADE_Engine/src/Camera/SHCameraDirector.h | 7 +++++++ SHADE_Engine/src/Camera/SHCameraSystem.cpp | 14 +++++++++++++- SHADE_Engine/src/Camera/SHCameraSystem.h | 6 +++--- 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/SHADE_Engine/src/Camera/SHCameraComponent.cpp b/SHADE_Engine/src/Camera/SHCameraComponent.cpp index 7ba6855c..755311a0 100644 --- a/SHADE_Engine/src/Camera/SHCameraComponent.cpp +++ b/SHADE_Engine/src/Camera/SHCameraComponent.cpp @@ -1,7 +1,8 @@ #include "SHpch.h" #include "SHCameraComponent.h" #include "ECS_Base/Managers/SHComponentManager.h" - +#include "SHCameraSystem.h" +#include "ECS_Base/Managers/SHSystemManager.h" namespace SHADE { @@ -128,4 +129,12 @@ namespace SHADE return projMatrix; } + void SHCameraComponent::SetMainCamera(size_t directorCameraIndex) noexcept + { + auto system = SHSystemManager::GetSystem(); + system->GetDirector(directorCameraIndex)->SetMainCamera(*this); + } + + + } diff --git a/SHADE_Engine/src/Camera/SHCameraComponent.h b/SHADE_Engine/src/Camera/SHCameraComponent.h index c86fa160..1149b1e1 100644 --- a/SHADE_Engine/src/Camera/SHCameraComponent.h +++ b/SHADE_Engine/src/Camera/SHCameraComponent.h @@ -70,6 +70,8 @@ namespace SHADE const SHMatrix& GetViewMatrix() const noexcept; const SHMatrix& GetProjMatrix() const noexcept; + void SetMainCamera(size_t cameraDirectorIndex = 0) noexcept; + float movementSpeed; SHVec3 turnSpeed; diff --git a/SHADE_Engine/src/Camera/SHCameraDirector.cpp b/SHADE_Engine/src/Camera/SHCameraDirector.cpp index 4ade9dbd..5e49fdfe 100644 --- a/SHADE_Engine/src/Camera/SHCameraDirector.cpp +++ b/SHADE_Engine/src/Camera/SHCameraDirector.cpp @@ -3,6 +3,7 @@ #include "SHCameraComponent.h" #include "ECS_Base/Managers/SHComponentManager.h" #include "ECS_Base/SHECSMacros.h" +#include "ECS_Base/Managers/SHEntityManager.h" #include "Tools/SHLog.h" namespace SHADE @@ -42,9 +43,18 @@ namespace SHADE viewMatrix = camComponent->GetViewMatrix(); projMatrix = camComponent->GetProjMatrix(); } + } - + void SHCameraDirector::SetMainCamera(SHCameraComponent& camera) noexcept + { + if (SHEntityManager::IsValidEID(camera.GetEID()) == false) + { + SHLOG_WARNING("Camera Director Warning: Attempting to set an invalid entity as main camera.") + return; + } + mainCameraEID = camera.GetEID(); } + } diff --git a/SHADE_Engine/src/Camera/SHCameraDirector.h b/SHADE_Engine/src/Camera/SHCameraDirector.h index 00e2d0c2..b1311147 100644 --- a/SHADE_Engine/src/Camera/SHCameraDirector.h +++ b/SHADE_Engine/src/Camera/SHCameraDirector.h @@ -3,10 +3,15 @@ #include "SH_API.h" #include "ECS_Base/Entity/SHEntity.h" #include "Math/SHMatrix.h" +#include "Resource/Handle.h" namespace SHADE { + class SHCameraComponent; + + + class SH_API SHCameraDirector { public: @@ -21,6 +26,7 @@ namespace SHADE SHMatrix GetProjMatrix() const noexcept; SHMatrix GetVPMatrix() const noexcept; void UpdateMatrix() noexcept; + void SetMainCamera(SHCameraComponent& cam) noexcept; private: @@ -32,5 +38,6 @@ namespace SHADE }; + typedef Handle DirectorHandle; } diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 02e6cd1c..04c017c0 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -187,11 +187,23 @@ namespace SHADE } - Handle SHCameraSystem::CreateDirector() noexcept + DirectorHandle SHCameraSystem::CreateDirector() noexcept { auto handle = directorLibrary.Create(); directorHandleList.emplace_back(handle); return handle; } + DirectorHandle SHCameraSystem::GetDirector(size_t index) noexcept + { + if (index < directorHandleList.size()) + { + return directorHandleList[index]; + } + else + { + return CreateDirector(); + } + } + } diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.h b/SHADE_Engine/src/Camera/SHCameraSystem.h index 5b946389..0d89b842 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.h +++ b/SHADE_Engine/src/Camera/SHCameraSystem.h @@ -5,7 +5,6 @@ #include "ECS_Base/System/SHSystemRoutine.h" #include "Resource/ResourceLibrary.h" #include "SHCameraDirector.h" -#include "Resource/Handle.h" #include "SH_API.h" namespace SHADE @@ -18,7 +17,7 @@ namespace SHADE SHCameraComponent editorCamera; ResourceLibrary directorLibrary; - std::vector> directorHandleList; + std::vector directorHandleList; public: SHCameraSystem(void) = default; @@ -48,7 +47,8 @@ namespace SHADE SHCameraComponent* GetEditorCamera (void) noexcept; void GetCameraAxis(SHCameraComponent const& camera, SHVec3& forward, SHVec3& right, SHVec3& up) const noexcept; - Handle CreateDirector() noexcept; + DirectorHandle CreateDirector() noexcept; + DirectorHandle GetDirector(size_t index) noexcept; protected: void UpdateCameraComponent(SHCameraComponent& camera) noexcept; From 7e04bee8d6a7ef341430a054017177f64d9788c1 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Fri, 21 Oct 2022 10:17:32 +0800 Subject: [PATCH 4/7] Defaults main camera if the mainCamera is still unset --- SHADE_Engine/src/Camera/SHCameraDirector.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Camera/SHCameraDirector.cpp b/SHADE_Engine/src/Camera/SHCameraDirector.cpp index 5e49fdfe..559897c0 100644 --- a/SHADE_Engine/src/Camera/SHCameraDirector.cpp +++ b/SHADE_Engine/src/Camera/SHCameraDirector.cpp @@ -31,7 +31,12 @@ namespace SHADE { if (mainCameraEID == MAX_EID) { - return; + auto& dense = SHComponentManager::GetDense(); + if (dense.size() == 0) + { + return; + } + mainCameraEID = dense[0].GetEID(); } SHCameraComponent* camComponent = SHComponentManager::GetComponent_s(mainCameraEID); if (!camComponent) From 6039ec534dc12548d8aa608b5078ad8741998707 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Sun, 23 Oct 2022 12:32:08 +0800 Subject: [PATCH 5/7] Added clamping of camera, and copying of position and rotation from transform --- SHADE_Engine/src/Camera/SHCameraComponent.cpp | 49 +++++++++++++++++++ SHADE_Engine/src/Camera/SHCameraSystem.cpp | 29 ++++++++++- SHADE_Engine/src/Camera/SHCameraSystem.h | 2 + 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Camera/SHCameraComponent.cpp b/SHADE_Engine/src/Camera/SHCameraComponent.cpp index 755311a0..5d49c887 100644 --- a/SHADE_Engine/src/Camera/SHCameraComponent.cpp +++ b/SHADE_Engine/src/Camera/SHCameraComponent.cpp @@ -3,6 +3,7 @@ #include "ECS_Base/Managers/SHComponentManager.h" #include "SHCameraSystem.h" #include "ECS_Base/Managers/SHSystemManager.h" +#include "Math/Transform/SHTransformComponent.h" namespace SHADE { @@ -23,33 +24,69 @@ namespace SHADE void SHCameraComponent::SetYaw(float yaw) noexcept { this->yaw = yaw; + if (SHComponentManager::HasComponent(GetEID())) + { + auto transform = SHComponentManager::GetComponent(GetEID()); + SHVec3 rotation = transform->GetWorldRotation(); + transform->SetWorldRotation(SHVec3{rotation.x,yaw, rotation.z}); + } dirtyView = true; } void SHCameraComponent::SetPitch(float pitch) noexcept { this->pitch = pitch; + if (SHComponentManager::HasComponent(GetEID())) + { + auto transform = SHComponentManager::GetComponent(GetEID()); + SHVec3 rotation = transform->GetWorldRotation(); + transform->SetWorldRotation(SHVec3{ pitch,rotation.y, rotation.z }); + } dirtyView = true; } void SHCameraComponent::SetRoll(float roll) noexcept { this->roll = roll; + if (SHComponentManager::HasComponent(GetEID())) + { + auto transform = SHComponentManager::GetComponent(GetEID()); + SHVec3 rotation = transform->GetWorldRotation(); + transform->SetWorldRotation(SHVec3{ rotation.x,rotation.y, roll}); + } dirtyView = true; } void SHCameraComponent::SetPositionX(float x) noexcept { position.x = x; + if (SHComponentManager::HasComponent(GetEID())) + { + auto transform = SHComponentManager::GetComponent(GetEID()); + SHVec3 position = transform->GetWorldPosition(); + transform->SetWorldRotation(SHVec3{ x,position.y, position.z}); + } dirtyView = true; } void SHCameraComponent::SetPositionY(float y) noexcept { position.y = y; + if (SHComponentManager::HasComponent(GetEID())) + { + auto transform = SHComponentManager::GetComponent(GetEID()); + SHVec3 position = transform->GetWorldPosition(); + transform->SetWorldRotation(SHVec3{ position.x,y, position.z }); + } dirtyView = true; } void SHCameraComponent::SetPositionZ(float z) noexcept { position.z = z; + if (SHComponentManager::HasComponent(GetEID())) + { + auto transform = SHComponentManager::GetComponent(GetEID()); + SHVec3 position = transform->GetWorldPosition(); + transform->SetWorldRotation(SHVec3{ position.x,position.y, z }); + } dirtyView = true; } void SHCameraComponent::SetPosition(float x,float y, float z) noexcept @@ -57,11 +94,23 @@ namespace SHADE position.x = x; position.y = y; position.z = z; + if (SHComponentManager::HasComponent(GetEID())) + { + auto transform = SHComponentManager::GetComponent(GetEID()); + SHVec3 position = transform->GetWorldPosition(); + transform->SetWorldRotation(SHVec3{ x,y, z }); + } dirtyView = true; } void SHCameraComponent::SetPosition(SHVec3& pos) noexcept { this->position = pos; + if (SHComponentManager::HasComponent(GetEID())) + { + auto transform = SHComponentManager::GetComponent(GetEID()); + SHVec3 position = transform->GetWorldPosition(); + transform->SetWorldRotation(pos); + } dirtyView = true; } diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 04c017c0..576ceb6b 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -4,7 +4,7 @@ #include "Input/SHInputManager.h" #include "Math/Vector/SHVec2.h" #include "ECS_Base/Managers/SHComponentManager.h" - +#include "Math/Transform/SHTransformComponent.h" namespace SHADE @@ -84,10 +84,25 @@ namespace SHADE void SHCameraSystem::UpdateCameraComponent(SHCameraComponent& camera) noexcept { + if (SHComponentManager::HasComponent(camera.GetEID()) == true) + { + auto transform = SHComponentManager::GetComponent(camera.GetEID()); + SHVec3 rotation = transform->GetWorldRotation(); + camera.pitch = rotation.x; + camera.yaw = rotation.y; + camera.roll = rotation.z; + camera.position = transform->GetWorldPosition(); + } + + if (camera.dirtyView) { SHVec3 view, right, UP; + + + ClampCameraRotation(camera); + GetCameraAxis(camera, view, right, UP); camera.viewMatrix = SHMatrix::Identity; @@ -205,5 +220,17 @@ namespace SHADE return CreateDirector(); } } + void SHCameraSystem::ClampCameraRotation(SHCameraComponent& camera) noexcept + { + if (camera.pitch > 85) + camera.SetPitch(85); + if (camera.pitch < -85) + camera.SetPitch(-85); + if (camera.roll > 85) + camera.SetRoll(85); + if (camera.roll < -85) + camera.SetRoll(-85); + + } } diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.h b/SHADE_Engine/src/Camera/SHCameraSystem.h index 0d89b842..26d15a5d 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.h +++ b/SHADE_Engine/src/Camera/SHCameraSystem.h @@ -49,6 +49,8 @@ namespace SHADE void GetCameraAxis(SHCameraComponent const& camera, SHVec3& forward, SHVec3& right, SHVec3& up) const noexcept; DirectorHandle CreateDirector() noexcept; DirectorHandle GetDirector(size_t index) noexcept; + void ClampCameraRotation(SHCameraComponent& camera) noexcept; + protected: void UpdateCameraComponent(SHCameraComponent& camera) noexcept; From c15994532bbf03d6b1c8bd3f25bc9161a8023240 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Sun, 23 Oct 2022 12:42:25 +0800 Subject: [PATCH 6/7] Added a function for editor camera update --- SHADE_Engine/src/Camera/SHCameraSystem.cpp | 53 ++++++++++++++++++++++ SHADE_Engine/src/Camera/SHCameraSystem.h | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 576ceb6b..0f2003f1 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -9,7 +9,57 @@ namespace SHADE { + void SHCameraSystem::UpdateEditorCamera(double dt) noexcept + { + + auto& camera = editorCamera; + SHVec3 view, right, UP; + GetCameraAxis(camera, view, right, UP); + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::A)) + { + camera.position -= right * dt * camera.movementSpeed; + camera.dirtyView = true; + } + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::D)) + { + camera.position += right * dt * camera.movementSpeed; + camera.dirtyView = true; + } + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::W)) + { + camera.position += view * dt * camera.movementSpeed; + camera.dirtyView = true; + } + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::S)) + { + camera.position -= view * dt * camera.movementSpeed; + camera.dirtyView = true; + } + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::Q)) + { + camera.position += UP * dt * camera.movementSpeed; + camera.dirtyView = true; + } + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::E)) + { + camera.position -= UP * dt * camera.movementSpeed; + camera.dirtyView = true; + } + if (SHInputManager::GetKey(SHInputManager::SH_KEYCODE::RMB)) + { + double mouseX, mouseY; + SHInputManager::GetMouseVelocity(&mouseX, &mouseY); + + //std::cout << camera.yaw << std::endl; + + camera.pitch -= mouseY * dt * camera.turnSpeed.x; + camera.yaw -= mouseX * dt * camera.turnSpeed.y; + camera.dirtyView = true; + } + + UpdateCameraComponent(editorCamera); + } void SHCameraSystem::EditorCameraUpdate::Execute(double dt) noexcept { SHCameraSystem* system = static_cast(GetSystem()); @@ -222,6 +272,9 @@ namespace SHADE } void SHCameraSystem::ClampCameraRotation(SHCameraComponent& camera) noexcept { + + + if (camera.pitch > 85) camera.SetPitch(85); if (camera.pitch < -85) diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.h b/SHADE_Engine/src/Camera/SHCameraSystem.h index 26d15a5d..dacda574 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.h +++ b/SHADE_Engine/src/Camera/SHCameraSystem.h @@ -50,7 +50,7 @@ namespace SHADE DirectorHandle CreateDirector() noexcept; DirectorHandle GetDirector(size_t index) noexcept; void ClampCameraRotation(SHCameraComponent& camera) noexcept; - + void UpdateEditorCamera(double dt) noexcept; protected: void UpdateCameraComponent(SHCameraComponent& camera) noexcept; From 96a7896da92b7f3deabda7adedde73a7a0550560 Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Sun, 23 Oct 2022 12:50:56 +0800 Subject: [PATCH 7/7] changed includes to SHHandle and SHResourceLibrary --- SHADE_Engine/src/Camera/SHCameraDirector.h | 2 +- SHADE_Engine/src/Camera/SHCameraSystem.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Camera/SHCameraDirector.h b/SHADE_Engine/src/Camera/SHCameraDirector.h index b1311147..5d09788b 100644 --- a/SHADE_Engine/src/Camera/SHCameraDirector.h +++ b/SHADE_Engine/src/Camera/SHCameraDirector.h @@ -3,7 +3,7 @@ #include "SH_API.h" #include "ECS_Base/Entity/SHEntity.h" #include "Math/SHMatrix.h" -#include "Resource/Handle.h" +#include "Resource/SHHandle.h" namespace SHADE diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.h b/SHADE_Engine/src/Camera/SHCameraSystem.h index dacda574..68071160 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.h +++ b/SHADE_Engine/src/Camera/SHCameraSystem.h @@ -3,7 +3,7 @@ #include "ECS_Base/System/SHSystem.h" #include "SHCameraComponent.h" #include "ECS_Base/System/SHSystemRoutine.h" -#include "Resource/ResourceLibrary.h" +#include "Resource/SHResourceLibrary.h" #include "SHCameraDirector.h" #include "SH_API.h" @@ -16,7 +16,7 @@ namespace SHADE //This is not tied to any entity. Hence this EID should not be used. SHCameraComponent editorCamera; - ResourceLibrary directorLibrary; + SHResourceLibrary directorLibrary; std::vector directorHandleList; public: