From efe8ba4f115f7432bd39ea8a8fa6c893c6a4638c Mon Sep 17 00:00:00 2001 From: maverickdgg Date: Wed, 19 Oct 2022 10:32:52 +0800 Subject: [PATCH] Added some editor camera controls --- SHADE_Engine/src/Camera/SHCameraComponent.cpp | 12 +++--- SHADE_Engine/src/Camera/SHCameraSystem.cpp | 43 ++++++++++++++++++- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/SHADE_Engine/src/Camera/SHCameraComponent.cpp b/SHADE_Engine/src/Camera/SHCameraComponent.cpp index 9b84081f..a206d39a 100644 --- a/SHADE_Engine/src/Camera/SHCameraComponent.cpp +++ b/SHADE_Engine/src/Camera/SHCameraComponent.cpp @@ -37,24 +37,24 @@ namespace SHADE } void SHCameraComponent::SetPositionX(float x) noexcept { - position[0] = x; + position.x = x; dirtyView = true; } void SHCameraComponent::SetPositionY(float y) noexcept { - position[1] = y; + position.y = y; dirtyView = true; } void SHCameraComponent::SetPositionZ(float z) noexcept { - position[2] = z; + position.z = z; dirtyView = true; } void SHCameraComponent::SetPosition(float x,float y, float z) noexcept { - position[0] = x; - position[1] = y; - position[2] = z; + position.x = x; + position.y = y; + position.z = z; dirtyView = true; } void SHCameraComponent::SetPosition(SHVec3& pos) noexcept diff --git a/SHADE_Engine/src/Camera/SHCameraSystem.cpp b/SHADE_Engine/src/Camera/SHCameraSystem.cpp index 24d96028..6be26133 100644 --- a/SHADE_Engine/src/Camera/SHCameraSystem.cpp +++ b/SHADE_Engine/src/Camera/SHCameraSystem.cpp @@ -12,10 +12,49 @@ namespace SHADE { SHCameraSystem* system = static_cast(GetSystem()); + SHVec3 target{ 0.0f,0.0f,1.0f }; + SHVec3 up = { 0.0f,1.0f,0.0f }; + + + SHCameraComponent& camera = system->editorCamera; + SHVec3::RotateY(target, SHMath::DegreesToRadians(camera.yaw)); + SHVec3::RotateX(target, SHMath::DegreesToRadians(camera.pitch)); + //SHVec3::RotateZ(target, SHMath::DegreesToRadians(camera.roll)); + + target = SHVec3::Normalise(target); + + SHVec3::RotateZ(up, camera.roll); + up = SHVec3::Normalise(up); + + + SHVec3 view = target - camera.position; view = SHVec3::Normalise(view); + SHVec3 right = SHVec3::Cross(view, up); right = SHVec3::Normalise(right); + const SHVec3 UP = SHVec3::Cross(right, view); + + if (SHInputManagerSystem::GetKey(SHInputManagerSystem::SH_KEYCODE::A)) { - system->editorCamera.SetPositionX(system->editorCamera.position[0] - dt * system->editorCamera.movementSpeed); - + system->editorCamera.position -= right * dt * camera.movementSpeed; + } + if (SHInputManagerSystem::GetKey(SHInputManagerSystem::SH_KEYCODE::D)) + { + system->editorCamera.position += right * dt * camera.movementSpeed; + } + if (SHInputManagerSystem::GetKey(SHInputManagerSystem::SH_KEYCODE::W)) + { + system->editorCamera.position += view * dt * camera.movementSpeed; + } + if (SHInputManagerSystem::GetKey(SHInputManagerSystem::SH_KEYCODE::S)) + { + system->editorCamera.position -= view * dt * camera.movementSpeed; + } + if (SHInputManagerSystem::GetKey(SHInputManagerSystem::SH_KEYCODE::Q)) + { + system->editorCamera.position += UP * dt * camera.movementSpeed; + } + if (SHInputManagerSystem::GetKey(SHInputManagerSystem::SH_KEYCODE::E)) + { + system->editorCamera.position -= UP * dt * camera.movementSpeed; } system->UpdateCameraComponent(system->editorCamera); }