From 55f9c51c1e2761d669a9b0165f0ff49d43ebaf53 Mon Sep 17 00:00:00 2001
From: Alexander Gauggel <agauggel@uni-koblenz.de>
Date: Fri, 4 Jun 2021 14:23:16 +0200
Subject: [PATCH] [#34] Correct camera aspect ratio on resize

---
 projects/first_mesh/src/main.cpp | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/projects/first_mesh/src/main.cpp b/projects/first_mesh/src/main.cpp
index 58c56dba..606a29ac 100644
--- a/projects/first_mesh/src/main.cpp
+++ b/projects/first_mesh/src/main.cpp
@@ -18,6 +18,14 @@ int main(int argc, const char** argv) {
 	vkcv::CameraManager cameraManager(window, window.getWidth(), window.getHeight());
 
 	window.initEvents();
+    window.e_resize.add([&cameraManager](int width, int height) {
+        auto& camera = cameraManager.getCamera();
+        float near;
+        float far;
+        camera.getNearFar(near, far);
+        const float aspectRatio = static_cast<float>(width) / height;
+        camera.setPerspective(camera.getFov(), aspectRatio, near, far);
+    });
 
 	vkcv::Core core = vkcv::Core::create(
 		window,
-- 
GitLab