From cf91c9c67e8631f0c8ef7fb22bc4accd496ebaae Mon Sep 17 00:00:00 2001 From: GeorgH93 Date: Tue, 1 Aug 2023 15:18:11 +0200 Subject: [PATCH] Cache camera position --- openVulkanoCpp/Scene/Camera.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openVulkanoCpp/Scene/Camera.hpp b/openVulkanoCpp/Scene/Camera.hpp index 7a2ed7b..ac785b7 100644 --- a/openVulkanoCpp/Scene/Camera.hpp +++ b/openVulkanoCpp/Scene/Camera.hpp @@ -15,6 +15,7 @@ namespace openVulkanoCpp::Scene { protected: Math::Matrix4f m_viewProjection{1}, m_view{1}, m_projection{1}; + Math::Vector4f m_camPosition{}; float m_nearPlane, m_farPlane, m_width, m_height; Camera() : m_nearPlane(0), m_farPlane(0), m_width(0), m_height(0) {} @@ -78,6 +79,7 @@ namespace openVulkanoCpp::Scene void UpdateWorldMatrix(const Math::Matrix4f& parentWorldMat) override { Node::UpdateWorldMatrix(parentWorldMat); + m_camPosition = GetWorldMatrix()[3]; m_view = Math::Utils::inverse(GetWorldMatrix()); UpdateViewProjectionMatrix(); } @@ -92,9 +94,9 @@ namespace openVulkanoCpp::Scene return m_viewProjection; } - [[nodiscard]] Math::Vector4f GetPosition() const + [[nodiscard]] const Math::Vector4f& GetPosition() const { - return GetWorldMatrix()[3]; + return m_camPosition; } [[nodiscard]] Math::Vector3f GetRightVector() const