diff --git a/openVulkanoCpp/Base/FrameMetadata.hpp b/openVulkanoCpp/Base/FrameMetadata.hpp index 80a5973..c384f40 100644 --- a/openVulkanoCpp/Base/FrameMetadata.hpp +++ b/openVulkanoCpp/Base/FrameMetadata.hpp @@ -15,7 +15,7 @@ namespace OpenVulkano public: uint64_t frameId = 0; double frameTime = 1; - bool shouldDraw = true; + bool needsRedraw = true; FrameMetadata() = default; }; diff --git a/openVulkanoCpp/Controller/ArcballCameraController.cpp b/openVulkanoCpp/Controller/ArcballCameraController.cpp index 3d512bd..dcb4716 100644 --- a/openVulkanoCpp/Controller/ArcballCameraController.cpp +++ b/openVulkanoCpp/Controller/ArcballCameraController.cpp @@ -26,17 +26,23 @@ namespace OpenVulkano { if (!GetCamera()) return; Input::InputManager* input = Input::InputManager::GetInstance(); + float inYaw = input->GetAxis(m_actionLookSide); + float inPitch = input->GetAxis(m_actionLookUp);; Math::Vector4f_SIMD position = GetCamera()->GetPosition(); - yaw += input->GetAxis(m_actionLookSide); - pitch += input->GetAxis(m_actionLookUp); + bool updated = false; - pitch = std::min(1.5f, std::max(-1.5f, pitch)); + if (inYaw != 0 || inPitch != 0) + { + yaw += inYaw; + pitch = std::min(1.5f, std::max(-1.5f, pitch + inPitch)); - Math::Matrix4f rotateY = Math::Utils::rotate(yaw, Math::Vector3f_SIMD(0, 1, 0)); - Math::Vector4f x = rotateY * Math::Vector4f(1, 0, 0, 0); - Math::Matrix4f rotateX = Math::Utils::rotate(pitch, Math::Vector3f_SIMD(x)); - position = rotateX * rotateY * Math::Vector4f_SIMD(0, 0, 3, 0); - position += m_pivotPoint; + Math::Matrix4f rotateY = Math::Utils::rotate(yaw, Math::Vector3f_SIMD(0, 1, 0)); + Math::Vector4f x = rotateY * Math::Vector4f(1, 0, 0, 0); + Math::Matrix4f rotateX = Math::Utils::rotate(pitch, Math::Vector3f_SIMD(x)); + position = rotateX * rotateY * Math::Vector4f_SIMD(0, 0, 3, 0); + position += m_pivotPoint; + updated = true; + } // Move the camera and the pivot point Math::Vector3f_SIMD vec(input->GetAxis(m_actionSide), input->GetAxis(m_actionUp), -input->GetAxis(m_actionForward)); @@ -52,12 +58,17 @@ namespace OpenVulkano const Math::Vector4f_SIMD movement(vec, 0); position += movement; m_pivotPoint += movement; + updated = true; } - // Update the camera view - GetCamera()->SetViewMatrix(Math::Utils::lookAt(reinterpret_cast(position), - reinterpret_cast(m_pivotPoint), - Math::Vector3f_SIMD(0,1,0))); + if (updated) + { + // Update the camera view + GetCamera()->SetViewMatrix(Math::Utils::lookAt(reinterpret_cast(position), + reinterpret_cast(m_pivotPoint), + Math::Vector3f_SIMD(0, 1, 0))); + CURRENT_FRAME.needsRedraw = true; + } } void ArcballCameraController::SetActive() diff --git a/openVulkanoCpp/Controller/MapCameraController.cpp b/openVulkanoCpp/Controller/MapCameraController.cpp index a2c228b..03212fc 100644 --- a/openVulkanoCpp/Controller/MapCameraController.cpp +++ b/openVulkanoCpp/Controller/MapCameraController.cpp @@ -7,6 +7,7 @@ #include "MapCameraController.hpp" #include "Input/InputManager.hpp" #include "Scene/Camera.hpp" +#include "Base/FrameMetadata.hpp" namespace OpenVulkano { @@ -22,7 +23,9 @@ namespace OpenVulkano { if (!GetCamera()) return; auto input = Input::InputManager::GetInstance(); - Math::Vector3f_SIMD vec = m_dirUp * input->GetAxis(m_actionUp) + m_dirSide * input->GetAxis(m_actionSide); + float up = input->GetAxis(m_actionUp); + float side = input->GetAxis(m_actionSide); + Math::Vector3f_SIMD vec = m_dirUp * up + m_dirSide * side; vec /= GetCamera()->GetZoom(); vec /= GetCamera()->GetContentScaleFactor(); @@ -35,7 +38,11 @@ namespace OpenVulkano GetCamera()->UpdateProjectionMatrix(); } - GetCamera()->SetMatrix(Math::Utils::translate(vec) * GetCamera()->GetMatrix()); + if (zoom != 0 || up != 0 || side != 0) + { + GetCamera()->SetMatrix(Math::Utils::translate(vec) * GetCamera()->GetMatrix()); + CURRENT_FRAME.needsRedraw = true; + } } void MapCameraController::SetDefaultKeybindings() diff --git a/openVulkanoCpp/Host/GraphicsAppManager.cpp b/openVulkanoCpp/Host/GraphicsAppManager.cpp index bf93552..590985e 100644 --- a/openVulkanoCpp/Host/GraphicsAppManager.cpp +++ b/openVulkanoCpp/Host/GraphicsAppManager.cpp @@ -141,12 +141,12 @@ namespace OpenVulkano { Input::InputManager::GetInstance()->Tick(); app->Tick(); - if (CURRENT_FRAME.shouldDraw) renderer->Tick(); + if (CURRENT_FRAME.needsRedraw) renderer->Tick(); frameTimer.Tick(); UpdateFps(); CURRENT_FRAME.frameId = frameCount; CURRENT_FRAME.frameTime = frameTimer.GetTickSeconds(); - CURRENT_FRAME.shouldDraw = !EngineConfiguration::GetEngineConfiguration()->GetLazyRendering(); + CURRENT_FRAME.needsRedraw = !EngineConfiguration::GetEngineConfiguration()->GetLazyRendering(); } }