From b1e857cf1471d1871a9396696b22fa531da98249 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 23 Nov 2024 22:33:43 +0100 Subject: add projbase to repo --- project-base/src/camera.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 project-base/src/camera.c (limited to 'project-base/src/camera.c') diff --git a/project-base/src/camera.c b/project-base/src/camera.c new file mode 100644 index 0000000..73a4790 --- /dev/null +++ b/project-base/src/camera.c @@ -0,0 +1,45 @@ +/* +* BSD 2-Clause “Simplified” License +* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com +* All rights reserved. +*/ + +void _camera_apply_transformations(platform_window *window, camera *camera) +{ + s32 x = (window->width/2)+(camera->x); + s32 y = (window->height/2)+(camera->y); + IMP_glTranslatef(x, y, 0.0f); + IMP_glRotatef(camera->rotation, 0.0f, 0.0f, 1.0f); + IMP_glTranslatef(-x, -y, 0.0f); + + IMP_glMatrixMode(GL_PROJECTION); + IMP_glLoadIdentity(); + + IMP_glOrtho(camera->x, window->width+camera->x, + window->height+camera->y, camera->y, -100, 100); + + IMP_glMatrixMode(GL_MODELVIEW); +} + +vec4 camera_get_target_rectangle(platform_window *window) +{ + int w = window->width; + int h = window->height; + + double targetRatio = 16.0 / 9.0; + double ratio = (double)w / h; + if (ratio < targetRatio) // Too much height + { + int newHeight = (int)(w / targetRatio); + int newY = (h - newHeight) / 2; + return (vec4){0, newY, w, newHeight}; + } + else if (ratio > targetRatio) // Too much width + { + int newWidth = (int)(h * targetRatio); + int newX = (w - newWidth) / 2; + return (vec4){newX, 0, newWidth, h}; + } + + return (vec4){0,0,w,h}; +} \ No newline at end of file -- cgit v1.2.3-70-g09d2