Mirai's Miscellaneous Misadventures
M43 / core / cameras.c
1
2
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 i = 1;
36 while (i < count)
37 {
38 if (position->x / 128 < thresholds[i].x + origin->x)
39 break;
40 i++;
41 }
42
43 left = (thresholds[i - 1].x + origin->x + 16) * 128;
44 right = (thresholds[i].x + origin->x - 16) * 128;
45
46 top = (thresholds[i].top + origin->y - 4) * 128;
47 bottom = (thresholds[i].bottom + origin->y - 4) * 128;
48
49 *output = *input;
50
51 if (output->x < left) output->x = left;
52 if (output->x > right) output->x = right;
53 if (output->y < top) output->y = top;
54 if (output->y > bottom) output->y = bottom;
55}