aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/camera.cpp19
-rw-r--r--src/main.cpp1
-rw-r--r--src/vk-renderer.cpp6
-rw-r--r--src/window.cpp2
4 files changed, 22 insertions, 6 deletions
diff --git a/src/camera.cpp b/src/camera.cpp
index 027ad1e..54c847d 100644
--- a/src/camera.cpp
+++ b/src/camera.cpp
@@ -10,18 +10,29 @@ camera::camera(
float aspect_ratio,
float aperture,
float focus_dist
- ) : position(position), lens_radius(aperture / 2.0) {
+ ) : position(position), lens_radius(aperture / 2.0), fov(v_fov), focus_distance(focus_dist) {
- auto forward = (target - position).unit();
+ forward = (target - position).unit();
right = forward.cross(vec3{ 0.0, 1.0, 0.0 }).unit();
up = right.cross(forward).unit();
- auto h = tan(deg_to_rad(v_fov) / 2.0);
+ auto h = tan(deg_to_rad(fov) / 2.0);
auto viewport_height = 2.0 * h;
auto viewport_width = viewport_height * aspect_ratio;
horizontal = focus_dist * viewport_width * right;
vertical = focus_dist * viewport_height * up;
- first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_dist * forward;
+ first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_distance * forward;
+}
+
+void camera::set_aspect_ratio(float aspect_ratio) {
+ auto h = tan(deg_to_rad(fov) / 2.0);
+ auto viewport_height = 2.0 * h;
+ auto viewport_width = viewport_height * aspect_ratio;
+
+ horizontal = focus_distance * viewport_width * right;
+ vertical = focus_distance * viewport_height * up;
+
+ first_pixel = position - horizontal / 2.0 - vertical / 2.0 + focus_distance * forward;
}
diff --git a/src/main.cpp b/src/main.cpp
index b449c4c..0de69f7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -67,6 +67,7 @@ int main() {
} else {
canRender = true;
renderer.recreate_swapchain();
+ renderer.mapped_data->cam.set_aspect_ratio((float)event.width / (float)event.height);
}
break;
}
diff --git a/src/vk-renderer.cpp b/src/vk-renderer.cpp
index cfb437e..e3eca75 100644
--- a/src/vk-renderer.cpp
+++ b/src/vk-renderer.cpp
@@ -309,10 +309,12 @@ void vkrenderer::create_swapchain() {
if (wantedExtent.width < caps.minImageExtent.width) {
wantedExtent.width = caps.minImageExtent.width;
- } else if (wantedExtent.height < caps.minImageExtent.height) {
- wantedExtent.height = caps.minImageExtent.height;
} else if (wantedExtent.width > caps.maxImageExtent.width) {
wantedExtent.width = caps.maxImageExtent.width;
+ }
+
+ if (wantedExtent.height < caps.minImageExtent.height) {
+ wantedExtent.height = caps.minImageExtent.height;
} else if (wantedExtent.height > caps.maxImageExtent.height) {
wantedExtent.height = caps.maxImageExtent.height;
}
diff --git a/src/window.cpp b/src/window.cpp
index c273f43..77e8f1c 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -81,6 +81,7 @@ void window::poll_events() {
auto client_message_event = (xcb_client_message_event_t*)event;
if (client_message_event->data.data32[0] == win_delete_atom) {
events.push_back({ .type = EVENT_TYPES::QUIT });
+ isOpen = false;
}
}
default: {
@@ -159,6 +160,7 @@ LRESULT window::message_handler(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lpar
case WM_CLOSE:
case WM_DESTROY:
case WM_QUIT: {
+ events.push_back({ .type = EVENT_TYPES::QUIT });
isOpen = false;
return 0;
}