Mirai's Miscellaneous Misadventures
M53 / core / cameras.c
1
2
3
4#include "../mimimi.h"
5
6void mimimi_camera_tick(struct mimimi_position *camera,
7 struct mimimi_position *position, int ox, int oy)
8{
9 camera->x *= 3;
10 camera->y *= 3;
11 camera->x += position->x + ox;
12 camera->y += position->y + oy;
13 camera->x /= 4;
14 camera->y /= 4;
15}
16
17void mimimi_clamped_camera_tick(struct mimimi_clamped_camera *camera,
18 int width0, int height0)
19{
20 struct mimimi_position *input;
21 struct mimimi_position *output;
22 int x, y, width, height;
23 int left, right;
24 int top, bottom;
25
26 input = camera->input;
27 output = &camera->output;
28
29 x = camera->offset.x;
30 y = camera->offset.y;
31 width = camera->size.width * 128;
32 height = camera->size.height * 128;
33
34 left = x * 128;
35 right = left + width;
36
37 top = y * 128;
38 bottom = top + height;
39
40 width0 *= 8;
41 height0 *= 8;
42
43 left += width0 / 2;
44 right -= width0 / 2;
45 top += height0 / 2;
46 bottom -= height0 / 2;
47
48 *output = *input;
49
50 if (output->x < left)
51 output->x = left;
52 if (output->x > right)
53 output->x = right;
54 if (output->y < top)
55 output->y = top;
56 if (output->y > bottom)
57 output->y = bottom;
58
59 if (width < width0)
60 output->x = left - (width0 - width) / 2;
61 if (height < height0)
62 output->y = top - (height0 - height) / 2;
63}
64
65void mimimi_boxing(struct mimimi_size *size, struct mimimi_image *image)
66{
67 int width, height;
68 int x, y;
69
70 width = image->width - size->width * 16;
71 height = image->height - size->height * 16;
72
73 width = mimimi_div_up(width, 2);
74 height = mimimi_div_up(height, 2);
75
76 for (y = 0; y < height; y++)
77 for (x = 0; x < image->width; x++) {
78 image->colors[x + image->width * y] = 1;
79 image->colors[x + image->width * (image->height - y)] = 1;
80 }
81
82 for (y = 0; y < image->height; y++)
83 for (x = 0; x <= width; x++) {
84 image->colors[x + image->width * y] = 1;
85 image->colors[(image->width - x) + image->width * y] = 1;
86 }
87}