From 27e590f716f063f603e170f6fc9dd66b8fc099ff Mon Sep 17 00:00:00 2001 From: Mel Date: Fri, 7 Jul 2023 23:06:04 +0200 Subject: Fix Util::ImageViewer on aspect other than 1 --- src/Util/ImageViewer.cpp | 8 ++++---- src/Util/ImageViewer.hpp | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Util/ImageViewer.cpp b/src/Util/ImageViewer.cpp index f94ccd0..9720408 100644 --- a/src/Util/ImageViewer.cpp +++ b/src/Util/ImageViewer.cpp @@ -20,7 +20,7 @@ ImageViewer::ImageViewer( model_uniform.set(Math::MVP::model({}, {})); view_uniform.set(Math::MVP::view({}, {})); - projection_uniform.set(Math::MVP::orthographic_projection(1000 * window_aspect, 1000, 0.0f, 100.0f)); + projection_uniform.set(Math::MVP::orthographic_projection(view_size * window_aspect, view_size, 0.0f, 100.0f)); m_program.unbind(); } @@ -37,12 +37,12 @@ void ImageViewer::render() const { GFX::Mesh ImageViewer::create_mesh(float window_aspect, uint32_t image_width, uint32_t image_height) { auto aspect = (float)image_width / image_height; - float max_size = 500.0f; + float max_size = view_size * 0.8f; float width = max_size * std::min(1.0f, aspect); float height = max_size * std::min(1.0f, 1/aspect); - float x = max_size * window_aspect - width / 2.0f; - float y = max_size - height / 2.0f; + float x = (view_size * window_aspect - width) / 2.0f; + float y = (view_size - height) / 2.0f; return {{ std::vector>{ diff --git a/src/Util/ImageViewer.hpp b/src/Util/ImageViewer.hpp index 59c0bf3..16ef2dd 100644 --- a/src/Util/ImageViewer.hpp +++ b/src/Util/ImageViewer.hpp @@ -16,6 +16,8 @@ public: private: static GFX::Mesh create_mesh(float window_aspect, uint32_t image_width, uint32_t image_height); + static constexpr float view_size = 1000.0f; + static const char* vertex; static const char* fragment; -- cgit 1.4.1