diff --git a/openVulkanoCpp/Scene/Camera.hpp b/openVulkanoCpp/Scene/Camera.hpp index 478176b..229f48c 100644 --- a/openVulkanoCpp/Scene/Camera.hpp +++ b/openVulkanoCpp/Scene/Camera.hpp @@ -97,9 +97,7 @@ namespace OpenVulkano::Scene void UpdateViewProjectionMatrix() { - //TODO this should be done based on the clipspace used by the rendering api - // In vulkan the screen space is defined as y=0=top and y=1=bottom and thus the coordinate have to be flipped - m_viewProjection = m_projection * Math::Matrix4f(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1) * m_view; + m_viewProjection = m_projection * m_view; } void UpdateWorldMatrix(const Math::Matrix4f& parentWorldMat) override @@ -115,6 +113,14 @@ namespace OpenVulkano::Scene SetMatrix(Math::Utils::inverse(view)); } + void SetProjectionMatrix(const Math::Matrix4f& projection) + { + //TODO this should be done based on the clipspace used by the rendering api + // In vulkan the screen space is defined as y=0=top and y=1=bottom and thus the coordinate have to be flipped + m_projection = projection * Math::Matrix4f(1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1); + UpdateViewProjectionMatrix(); + } + [[nodiscard]] const Math::Matrix4f& GetViewProjectionMatrix() const { return m_viewProjection; @@ -251,8 +257,7 @@ namespace OpenVulkano::Scene void UpdateProjectionMatrix() override { - m_projection = Math::Utils::perspectiveRH_ZO(m_fov, m_aspect, m_nearPlane, m_farPlane); - UpdateViewProjectionMatrix(); + SetProjectionMatrix(Math::Utils::perspectiveRH_ZO(m_fov, m_aspect, m_nearPlane, m_farPlane)); } [[nodiscard]] bool IsPerspective() const override { return true; } @@ -265,11 +270,9 @@ namespace OpenVulkano::Scene { const float scale = 0.5f * m_contentScaleFactor * m_zoom; const float widthHalf = m_width * scale, heightHalf = m_height * scale; - m_projection = Math::Utils::orthoRH_ZO(-widthHalf, widthHalf, -heightHalf, heightHalf, m_nearPlane, m_farPlane); - UpdateViewProjectionMatrix(); + SetProjectionMatrix(Math::Utils::orthoRH_ZO(-widthHalf, widthHalf, -heightHalf, heightHalf, m_nearPlane, m_farPlane)); } [[nodiscard]] bool IsOrtho() const override { return true; } }; } - diff --git a/openVulkanoCpp/Scene/MorphableCamera.cpp b/openVulkanoCpp/Scene/MorphableCamera.cpp index b7275b3..f47a52d 100644 --- a/openVulkanoCpp/Scene/MorphableCamera.cpp +++ b/openVulkanoCpp/Scene/MorphableCamera.cpp @@ -22,21 +22,21 @@ namespace OpenVulkano::Scene } void MorphableCamera::UpdateProjectionMatrix() { - PerspectiveCamera::UpdateProjectionMatrix(); + if (m_morphState == 0) PerspectiveCamera::UpdateProjectionMatrix(); if (m_morphState != 0) { const float scale = 0.5f * m_contentScaleFactor * m_zoom; const float widthHalf = m_width * scale, heightHalf = m_height * scale; - m_orthoMatrix = Math::Utils::orthoRH_ZO(-widthHalf, widthHalf, -heightHalf, heightHalf, m_nearPlane, m_farPlane); + Math::Matrix4f orthoMatrix = Math::Utils::orthoRH_ZO(-widthHalf, widthHalf, -heightHalf, heightHalf, m_nearPlane, m_farPlane); if (m_morphState == 1) { - m_projection = m_orthoMatrix; + SetProjectionMatrix(orthoMatrix); } else { - m_projection = BlendMatrices(m_projection, m_orthoMatrix, m_morphState); + Math::Matrix4f projection = Math::Utils::perspectiveRH_ZO(m_fov, m_aspect, m_nearPlane, m_farPlane); + SetProjectionMatrix(BlendMatrices(projection, orthoMatrix, m_morphState)); } - UpdateViewProjectionMatrix(); } } -} \ No newline at end of file +} diff --git a/openVulkanoCpp/Scene/MorphableCamera.hpp b/openVulkanoCpp/Scene/MorphableCamera.hpp index 8c1cb3c..caedb91 100644 --- a/openVulkanoCpp/Scene/MorphableCamera.hpp +++ b/openVulkanoCpp/Scene/MorphableCamera.hpp @@ -13,7 +13,6 @@ namespace OpenVulkano::Scene class MorphableCamera : public PerspectiveCamera { float m_morphState; - Math::Matrix4f m_orthoMatrix; public: MorphableCamera(float fovDegrees, float nearPlane = 0.1f, float farPlane = 1000.0f, float width = 16, float height = 9) @@ -33,4 +32,4 @@ namespace OpenVulkano::Scene [[nodiscard]] bool IsPerspective() const override { return m_morphState == 0; } [[nodiscard]] bool IsOrtho() const override { return m_morphState == 1; } }; -} \ No newline at end of file +}