86 lines
2.1 KiB
C
86 lines
2.1 KiB
C
#include "fdf.h"
|
|
|
|
// add "print_keycode(keycode);" at begining to print keycode
|
|
int keypress(int keycode, t_fdf *fdf)
|
|
{
|
|
if (keycode == ESCAPE)
|
|
shut_down(fdf);
|
|
else if (keycode == LEFT)
|
|
(fdf->rot_x) += 1;
|
|
else if (keycode == RIGHT)
|
|
(fdf->rot_x) -= 1;
|
|
else if (keycode == UP)
|
|
(fdf->rot_y) += 1;
|
|
else if (keycode == DOWN)
|
|
(fdf->rot_y) -= 1;
|
|
else if (keycode == Q)
|
|
(fdf->mov_x) -= 6;
|
|
else if (keycode == D)
|
|
(fdf->mov_x) += 6;
|
|
else if (keycode == Z)
|
|
(fdf->mov_y) -= 6;
|
|
else if (keycode == S)
|
|
(fdf->mov_y) += 6;
|
|
else if (keycode == A)
|
|
(fdf->zoom) += 6;
|
|
else if (keycode == W)
|
|
(fdf->zoom) -= 6;
|
|
draw_image(fdf);
|
|
return (0);
|
|
}
|
|
|
|
// return an int[3] : int[0] = x, int[1] = y, int[2] = z
|
|
int *new_coordinates(t_fdf *fdf, int i, int j)
|
|
{
|
|
int x;
|
|
int y;
|
|
int z;
|
|
int *point;
|
|
|
|
point = ft_calloc(3, sizeof(int));
|
|
// pre zoom
|
|
x = i * (fdf->offset + fdf->zoom);
|
|
y = j * (fdf->offset + fdf->zoom);
|
|
// pre center
|
|
x -= (fdf->map_size_x + fdf->zoom * fdf->map_width) / 2;
|
|
y -= (fdf->map_size_y + fdf->zoom * fdf->map_height) / 2;
|
|
// rotation
|
|
z = fdf->map[j][i] * fdf->altitude;
|
|
point[0] = x * cos(fdf->rad_x) + y * sin(fdf->rad_x);
|
|
point[1] = y * cos(fdf->rad_x) - x * sin(fdf->rad_x);
|
|
point[1] = point[1] * cos(fdf->rad_y) - -z * sin(fdf->rad_y);
|
|
// deplacements
|
|
point[0] += fdf->margin + fdf->mov_x;
|
|
point[1] += fdf->margin + fdf->mov_y;
|
|
// post zoom
|
|
point[0] -= ((fdf->map_size_x / 2) / fdf->offset) * fdf->zoom;
|
|
point[1] -= ((fdf->map_size_y / 2) / fdf->offset) * fdf->zoom;
|
|
// post center
|
|
point[0] += (fdf->map_size_x + fdf->zoom * fdf->map_width) / 2;
|
|
point[1] += (fdf->map_size_y + fdf->zoom * fdf->map_height) / 2;
|
|
|
|
point[2] = z;
|
|
return (point);
|
|
}
|
|
|
|
int print_keycode(int keycode)
|
|
{
|
|
ft_putnbr(keycode);
|
|
ft_putchar(' ');
|
|
return(0);
|
|
}
|
|
|
|
void rotation_state(t_fdf *fdf)
|
|
{
|
|
char *position;
|
|
int x;
|
|
int y;
|
|
|
|
x = fdf->img_size_x - 10;
|
|
y = fdf->img_size_y - 10;
|
|
position = ft_strjoin(ft_itoa(fdf->rot_x), ft_strdup(" | "));
|
|
position = ft_strjoin(position, ft_itoa(fdf->rot_y));
|
|
x -= ft_strlen(position) * 6;
|
|
mlx_string_put(fdf->mlx_ptr, fdf->win_ptr, x, y, 0xffffff, position);
|
|
}
|