diff --git a/examples/ExampleApps/MovingCubeApp.cpp b/examples/ExampleApps/MovingCubeApp.cpp index 9297ee5..2d79ef2 100644 --- a/examples/ExampleApps/MovingCubeApp.cpp +++ b/examples/ExampleApps/MovingCubeApp.cpp @@ -114,10 +114,11 @@ namespace OpenVulkano } public: - MovingCubeAppImpl() : m_camera(90, 16, 9, 0.1, 1000) + MovingCubeAppImpl() : m_camera(90) { m_morphableCameraControl.Init(&m_camera); m_cameraControl.Init(&m_camera); + m_camera.SetZoom(50); } void Init() override diff --git a/openVulkanoCpp/Scene/Camera.hpp b/openVulkanoCpp/Scene/Camera.hpp index f8b718c..e8711e2 100644 --- a/openVulkanoCpp/Scene/Camera.hpp +++ b/openVulkanoCpp/Scene/Camera.hpp @@ -25,7 +25,8 @@ namespace OpenVulkano::Scene Math::Vector4f m_camPosition{}; float m_nearPlane, m_farPlane, m_width, m_height; float m_fov = 0, m_aspect = 0, m_scaleFactor = 0, m_perPixelScaleFactor = 0; - std::array m_userData{}; + float m_contentScaleFactor = 1, m_zoom = 1; // For use with ortho camera + std::array m_userData{}; Camera() : m_nearPlane(0), m_farPlane(0), m_width(0), m_height(0) {} @@ -81,6 +82,17 @@ namespace OpenVulkano::Scene return m_farPlane; } + void SetContentScaleFactor(float contentScale = 1) + { + m_contentScaleFactor = 1.0f / contentScale; + } + + [[nodiscard]] float GetContentScaleFactor() const { return 1.0f / m_contentScaleFactor; } + + void SetZoom(float zoom) { m_zoom = 1.0f / zoom; } + + [[nodiscard]] float GetZoom() const { return 1.0f / m_zoom; } + virtual void UpdateProjectionMatrix() = 0; void UpdateViewProjectionMatrix() @@ -141,7 +153,7 @@ namespace OpenVulkano::Scene * The 16 byte of user data can be used to transmit additional data about the camera to the shader. * @return reference to the custom data array */ - [[nodiscard]] std::array& GetUserData() { return m_userData; } + [[nodiscard]] std::array& GetUserData() { return m_userData; } [[nodiscard]] float GetPixelScaleFactor() const { return m_perPixelScaleFactor; } }; @@ -245,7 +257,8 @@ namespace OpenVulkano::Scene public: void UpdateProjectionMatrix() final { - const float widthHalf = m_width * 0.5f, heightHalf = m_height * 0.5f; + 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(); } diff --git a/openVulkanoCpp/Scene/MorphableCamera.cpp b/openVulkanoCpp/Scene/MorphableCamera.cpp index 3643bf6..b7275b3 100644 --- a/openVulkanoCpp/Scene/MorphableCamera.cpp +++ b/openVulkanoCpp/Scene/MorphableCamera.cpp @@ -25,15 +25,15 @@ namespace OpenVulkano::Scene PerspectiveCamera::UpdateProjectionMatrix(); if (m_morphState != 0) { - float aspectH = m_aspect; - float aspectV = 1; + 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); if (m_morphState == 1) { - m_projection = Math::Utils::orthoRH_ZO(-aspectH, aspectH, -aspectV, aspectV, m_nearPlane, m_farPlane); + m_projection = m_orthoMatrix; } else { - m_orthoMatrix = Math::Utils::orthoRH_ZO(-aspectH, aspectH, -aspectV, aspectV, m_nearPlane, m_farPlane); m_projection = BlendMatrices(m_projection, m_orthoMatrix, m_morphState); } UpdateViewProjectionMatrix(); diff --git a/openVulkanoCpp/Scene/MorphableCamera.hpp b/openVulkanoCpp/Scene/MorphableCamera.hpp index 47b8b10..9b2c69f 100644 --- a/openVulkanoCpp/Scene/MorphableCamera.hpp +++ b/openVulkanoCpp/Scene/MorphableCamera.hpp @@ -16,7 +16,7 @@ namespace OpenVulkano::Scene Math::Matrix4f m_orthoMatrix; public: - MorphableCamera(float fovDegrees, float width, float height, float nearPlane, float farPlane) + MorphableCamera(float fovDegrees, float nearPlane = 0.1f, float farPlane = 1000.0f, float width = 16, float height = 9) : PerspectiveCamera(fovDegrees, nearPlane, farPlane, width, height), m_morphState(0.0f) { UpdateProjectionMatrix();