affichage etat de la rotation

This commit is contained in:
hugogogo
2021-07-18 15:31:44 +02:00
parent 59e2fdde4a
commit 3bef66f8ec
4 changed files with 46 additions and 25 deletions

Binary file not shown.

BIN
fdf

Binary file not shown.

View File

@@ -15,12 +15,14 @@ typedef struct s_map
{ {
void *mlx_ptr; void *mlx_ptr;
void *win_ptr; void *win_ptr;
void *img_ptr;
char *img_addr;
int win_size_x; int win_size_x;
int win_size_y; int win_size_y;
int img_size_x; int img_size_x;
int img_size_y; int img_size_y;
void *img_ptr; int map_size_x;
char *img_addr; int map_size_y;
int img_bpp; int img_bpp;
int img_sizel; int img_sizel;
int img_endian; int img_endian;

View File

@@ -4,23 +4,8 @@ t_map *init_map(void);
int print_keycode(int keycode); int print_keycode(int keycode);
int shut_down(t_map *map); int shut_down(t_map *map);
void draw_pixel(t_map *map, int x, int y, int color); void draw_pixel(t_map *map, int x, int y, int color);
int keypress(int keycode, t_map *map);
int keypress(int keycode, t_map *map) void rotation_state(t_map *map);
{
if (keycode == ESCAPE)
shut_down(map);
else if (keycode == LEFT)
(map->rot_x) -= 1;
else if (keycode == RIGHT)
(map->rot_x) += 1;
else if (keycode == UP)
(map->rot_y) -= 1;
else if (keycode == DOWN)
(map->rot_y) += 1;
else
print_keycode(keycode);
return (0);
}
void draw_image(t_map *map) void draw_image(t_map *map)
{ {
@@ -33,11 +18,15 @@ void draw_image(t_map *map)
x = 0; x = 0;
while ((x * map->img_bpp / 8) < map->img_sizel) while ((x * map->img_bpp / 8) < map->img_sizel)
{ {
draw_pixel(map, x, y, 0x94dd24); draw_pixel(map, x, y, 0xffffff);
x += 4; x += 4;
} }
y += 4; y += 4;
} }
// put image on screen
mlx_put_image_to_window(map->mlx_ptr, map->win_ptr, map->img_ptr, 0, 0);
// put rotation on screen
rotation_state(map);
} }
int main(int ac, char **av) int main(int ac, char **av)
@@ -57,6 +46,25 @@ int main(int ac, char **av)
return (0); return (0);
} }
int keypress(int keycode, t_map *map)
{
if (keycode == ESCAPE)
shut_down(map);
else if (keycode == LEFT)
(map->rot_x) -= 1;
else if (keycode == RIGHT)
(map->rot_x) += 1;
else if (keycode == UP)
(map->rot_y) += 1;
else if (keycode == DOWN)
(map->rot_y) -= 1;
else
print_keycode(keycode);
// draw image
draw_image(map);
return (0);
}
int print_keycode(int keycode) int print_keycode(int keycode)
{ {
ft_putnbr(keycode); ft_putnbr(keycode);
@@ -72,6 +80,20 @@ void draw_pixel(t_map *map, int x, int y, int color)
*(unsigned int*)(map->img_addr + position) = color; *(unsigned int*)(map->img_addr + position) = color;
} }
void rotation_state(t_map *map)
{
char *position;
int x;
int y;
x = map->img_size_x - 10;
y = map->img_size_y - 10;
position = ft_strjoin(ft_itoa(map->rot_x), " | ");
position = ft_strjoin(position, ft_itoa(map->rot_y));
x -= ft_strlen(position) * 6;
mlx_string_put(map->mlx_ptr, map->win_ptr, x, y, 0xffffff, position);
}
t_map *init_map(void) t_map *init_map(void)
{ {
t_map *map; t_map *map;
@@ -81,8 +103,8 @@ t_map *init_map(void)
map->win_size_x = 500; map->win_size_x = 500;
map->win_size_y = 500; map->win_size_y = 500;
// size image // size image
map->img_size_x = 400; map->img_size_x = map->win_size_x;
map->img_size_y = 400; map->img_size_y = map->win_size_y;
// view rotation // view rotation
map->rot_x = 0; map->rot_x = 0;
map->rot_y = 0; map->rot_y = 0;
@@ -95,9 +117,6 @@ t_map *init_map(void)
map->img_addr = mlx_get_data_addr(map->img_ptr, &(map->img_bpp), &(map->img_sizel), &(map->img_endian)); map->img_addr = mlx_get_data_addr(map->img_ptr, &(map->img_bpp), &(map->img_sizel), &(map->img_endian));
// draw image // draw image
draw_image(map); draw_image(map);
// put image on screen
mlx_put_image_to_window(map->mlx_ptr, map->win_ptr, map->img_ptr, 50, 50);
return (map); return (map);
} }