Mirai's Miscellaneous Misadventures

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