Mirai's Miscellaneous Misadventures
M52 / 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, 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 * 128;
30 height = camera->size.height * 128;
31
32 left = x * 128;
33 right = left + width;
34
35 top = y * 128;
36 bottom = top + height;
37
38 width0 *= 8;
39 height0 *= 8;
40
41 left += width0 / 2;
42 right -= width0 / 2;
43 top += height0 / 2;
44 bottom -= height0 / 2;
45
46 *output = *input;
47
48 if (output->x < left) output->x = left;
49 if (output->x > right) output->x = right;
50 if (output->y < top) output->y = top;
51 if (output->y > bottom) output->y = bottom;
52
53 if (width < width0) output->x = left - (width0 - width) / 2;
54 if (height < height0) output->y = top - (height0 - height) / 2;
55}
56
57void mimimi_boxing(struct mimimi_size *size, struct mimimi_image *image)
58{
59 int width, height;
60 int x, y;
61
62 width = image->width - size->width * 16;
63 height = image->height - size->height * 16;
64
65 for (y = 0 ; y < height ; y++)
66 for (x = 0 ; x < image->width ; x++)
67 {
68 image->colors[x + image->width * y] = 1;
69 image->colors[x + image->width * (image->height - y)] = 1;
70 }
71
72 for (y = 0 ; y < image->height ; y++)
73 for (x = 0 ; x < width ; x++)
74 {
75 image->colors[x + image->width * y] = 1;
76 image->colors[(image->width - x) + image->width * y] = 1;
77 }
78}