From ab384447907fbdb32e541374a5c597b068d3e672 Mon Sep 17 00:00:00 2001 From: Sara Date: Sat, 23 Sep 2023 22:53:07 +0200 Subject: [PATCH] implemented some of the camera functions --- src/camera.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/camera.c diff --git a/src/camera.c b/src/camera.c new file mode 100644 index 0000000..3c3089b --- /dev/null +++ b/src/camera.c @@ -0,0 +1,20 @@ +#include "camera.h" +#include "render.h" + +Camera g_camera; + +void camera_init() { + g_camera.centre = ZeroVector; + g_camera.width = 1; +} + +SDL_FRect render_calculate_unit_rect() { + // If the camera's width is 1, this rectangle should fill the width of the screen. + // If the camera's width is 2, this rectangle should fill half the width of the screen. + return (SDL_FRect) { + .x = -g_camera.centre.x * g_render_resolution.x, + .y = -g_camera.centre.y * g_render_resolution.x, + .w = g_render_resolution.x / g_camera.width, + .h = g_render_resolution.x / g_camera.width + }; +}