#include "fdf.h"

void	move(t_FDF *FDF)
{
	recalculate_trnsf_matrs(FDF->map);
	mat4_mult_chain(FDF->map->trnsf);
	transform(FDF->map->trnsf->fin, FDF->map);
	mlx_destroy_image(FDF->mw->mlx, FDF->image);
	FDF->image = mlx_new_image(FDF->mw->mlx, WIDTH, HEIGHT);
	FDF->image_data = mlx_get_data_addr(
			FDF->image,
			&FDF->bpp,
			&FDF->line_size,
			&FDF->endian);
	render(FDF);
}

void	left_rot(t_FDF *FDF)
{
	FDF->map->y_rot -= 1;
	move(FDF);
}

void	right_rot(t_FDF *FDF)
{
	FDF->map->y_rot += 1;
	move(FDF);
}

void	forw_rot(t_FDF *FDF)
{
	FDF->map->x_rot += 1;
	move(FDF);
}

void	back_rot(t_FDF *FDF)
{
	FDF->map->x_rot -= 1;
	move(FDF);
}

void	clock_rot(t_FDF *FDF)
{
	FDF->map->z_rot -= 1;
	move(FDF);
}

void	aclock_rot(t_FDF *FDF)
{
	FDF->map->z_rot += 1;
	move(FDF);
}

void	scale_up_z(t_FDF *FDF)
{
	FDF->map->scale[2] += 1.0f / 100 * 20;
	move(FDF);
}

void	scale_down_z(t_FDF *FDF)
{
	FDF->map->scale[2] -= 1.0f / 100 * 20;
	move(FDF);
}

void	zoom_in(t_FDF *FDF)
{
	FDF->map->scale[0] += 1.0f / 100 * 20;
	FDF->map->scale[1] += 1.0f / 100 * 20;
	move(FDF);
}

void	zoom_out(t_FDF *FDF)
{
	FDF->map->scale[0] -= 1.0f / 100 * 20;
	FDF->map->scale[1] -= 1.0f / 100 * 20;
	move(FDF);
}

void	reset(t_FDF *FDF)
{
	FDF->map->z_rot = 0;
	FDF->map->y_rot = 0;
	FDF->map->x_rot = 0;
	FDF->map->scale[0] = 1;
	FDF->map->scale[1] = 1;
	FDF->map->scale[2] = 1;
	move(FDF);
}