From 55eb910ff55b326c897dc1ea26220eb3778b980e Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Sat, 29 Jun 2024 15:18:25 +0300 Subject: [PATCH] Normalizing plane normal in setter --- openVulkanoCpp/Scene/PlaneCameraController.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/openVulkanoCpp/Scene/PlaneCameraController.cpp b/openVulkanoCpp/Scene/PlaneCameraController.cpp index ea58849..a95b997 100644 --- a/openVulkanoCpp/Scene/PlaneCameraController.cpp +++ b/openVulkanoCpp/Scene/PlaneCameraController.cpp @@ -25,7 +25,7 @@ namespace OpenVulkano::Scene void PlaneCameraController::Init(Camera* camera, const Math::Vector3f& planeNormal) { CameraController::Init(camera); - m_planeNormal = Math::Utils::normalize(planeNormal); + SetPlaneNormal(planeNormal); SetDefaultKeybindings(); } @@ -47,7 +47,7 @@ namespace OpenVulkano::Scene Math::Vector3f direction(input->GetAxis(m_actionSide), input->GetAxis(m_actionUp), -input->GetAxis(m_actionForward)); - if (Math::Utils::length2(direction) > 1.0f) { direction = Math::Utils::normalize(direction); } + if (Math::Utils::length2(direction) > 0.0f) { direction = Math::Utils::normalize(direction); } const float SPEED = 3.0f; const float BOOST_FACTOR = 3.0; @@ -55,10 +55,8 @@ namespace OpenVulkano::Scene if (input->GetButton(m_actionBoost)) { direction *= BOOST_FACTOR; } float dt = CURRENT_FRAME.frameTime; - - direction *= dt * SPEED; - direction = direction - (Math::Utils::dot(direction, m_planeNormal) * m_planeNormal); - m_position += direction; + Math::Vector3f projDirection = direction - (Math::Utils::dot(direction, m_planeNormal) * m_planeNormal); + m_position += projDirection * dt * SPEED; Math::Matrix4f transformation = Math::Utils::translate(m_position); GetCamera()->SetMatrix(transformation); @@ -75,5 +73,8 @@ namespace OpenVulkano::Scene m_actionUp->BindAxisButtons(Input::InputKey::Keyboard::KEY_SPACE, Input::InputKey::Keyboard::KEY_LEFT_CONTROL); } - void PlaneCameraController::SetPlaneNormal(const Math::Vector3f& planeNormal) { m_planeNormal = planeNormal; } + void PlaneCameraController::SetPlaneNormal(const Math::Vector3f& planeNormal) + { + m_planeNormal = Math::Utils::normalize(planeNormal); + } } \ No newline at end of file