Mirai's Miscellaneous Misadventures

M45 / core / cameras.c

1/* license: AGPLv3 or later */
2/* copyright 2023 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)
17{
18	struct mimimi_position *position;
19	struct mimimi_position *input;
20	struct mimimi_position *output;
21	int i;
22	int left, right;
23	int top, bottom;
24	int count;
25	struct mimimi_clamped_camera_threshold *thresholds;
26	
27	position = camera->position;
28	input = camera->input;
29	output = &camera->output;
30	count = camera->count;
31	thresholds = camera->thresholds;
32	
33	for (i = 1 ; i < count ; i++)
34	{
35		if (position->x < thresholds[i].x * 128)
36			break;
37	}
38	
39	left = (thresholds[i - 1].x + 16) * 128;
40	right = (thresholds[i].x - 16) * 128;
41	
42	top = (thresholds[i].top - 4) * 128;
43	bottom = (thresholds[i].bottom - 4) * 128;
44	
45	*output = *input;
46	
47	if (output->x < left) output->x = left;
48	if (output->x > right) output->x = right;
49	if (output->y < top) output->y = top;
50	if (output->y > bottom) output->y = bottom;
51}