Mirai's Miscellaneous Misadventures

M50 / core / cameras.c

1/* license: AGPLv3 or later */
2/* copyright 2024 zamfofex */
3
4#include <mimimi.h>
5
6void mimimi_camera_tick(struct mimimi_position *camera, struct mimimi_position *position, int ox, int oy)
7{
8	camera->x *= 3;
9	camera->y *= 3;
10	camera->x += position->x + ox;
11	camera->y += position->y + oy;
12	camera->x /= 4;
13	camera->y /= 4;
14}
15
16void mimimi_clamped_camera_tick(struct mimimi_clamped_camera *camera, int width0, int height0)
17{
18	struct mimimi_position *input;
19	struct mimimi_position *output;
20	int x, y, width, height;
21	int left, right;
22	int top, bottom;
23	
24	input = camera->input;
25	output = &camera->output;
26	
27	x = camera->offset.x;
28	y = camera->offset.y;
29	width = camera->size.width;
30	height = camera->size.height;
31	
32	left = x * 128;
33	right = left + width * 128;
34	
35	top = y * 128;
36	bottom = top + height * 128;
37	
38	left += width0 * 4;
39	right -= width0 * 4;
40	top += height0 * 4;
41	bottom -= height0 * 4;
42	
43	*output = *input;
44	
45	if (output->x < left) output->x = left;
46	if (output->x > right) output->x = right;
47	if (output->y < top) output->y = top;
48	if (output->y > bottom) output->y = bottom;
49}