summaryrefslogtreecommitdiff
path: root/project-base/src/camera.c
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-11-23 22:33:43 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-11-23 22:33:43 +0100
commitb1e857cf1471d1871a9396696b22fa531da98249 (patch)
tree3923008a8653057698cb339faf6dcfa92e18364b /project-base/src/camera.c
parent106bb7fcadf637cec883648916cc8d19529d6199 (diff)
add projbase to repo
Diffstat (limited to 'project-base/src/camera.c')
-rw-r--r--project-base/src/camera.c45
1 files changed, 45 insertions, 0 deletions
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