Mirai's Miscellaneous Misadventures

M47 / core / cameras.c

/* license: AGPLv3 or later */
/* copyright 2023 zamfofex */

#include <mimimi.h>

void mimimi_camera_tick(struct mimimi_position *camera, struct mimimi_position *position, int ox, int oy)
{
	camera->x *= 3;
	camera->y *= 3;
	camera->x += position->x + ox;
	camera->y += position->y + oy;
	camera->x /= 4;
	camera->y /= 4;
}

void mimimi_clamped_camera_tick(struct mimimi_clamped_camera *camera)
{
	struct mimimi_position *position;
	struct mimimi_position *input;
	struct mimimi_position *output;
	int i;
	int left, right;
	int top, bottom;
	int count;
	struct mimimi_clamped_camera_threshold *thresholds;
	
	position = camera->position;
	input = camera->input;
	output = &camera->output;
	count = camera->count;
	thresholds = camera->thresholds;
	
	for (i = 1 ; i < count ; i++)
	{
		if (position->x < thresholds[i].x * 128)
			break;
	}
	
	left = (thresholds[i - 1].x + 16) * 128;
	right = (thresholds[i].x - 16) * 128;
	
	top = (thresholds[i].top - 4) * 128;
	bottom = (thresholds[i].bottom - 4) * 128;
	
	*output = *input;
	
	if (output->x < left) output->x = left;
	if (output->x > right) output->x = right;
	if (output->y < top) output->y = top;
	if (output->y > bottom) output->y = bottom;
}