Skip to content

Commit 3a7b1d1

Browse files
committed
camera resetter initialized
1 parent bf96c09 commit 3a7b1d1

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

read_map.c

-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ unsigned long **map_string_to_arr_2d(char *whole_file)
9595
map_2d_ul = malloc(sizeof(unsigned long *) * (line_count + 1));
9696
if (!map_2d_ul)
9797
return (free(map_2d_str), NULL);
98-
printf("line_count: %lu\n", line_count);
9998
i = 0;
10099
while (map_2d_str[i])
101100
{

window_management.c

+35-10
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,39 @@
33
/* ::: :::::::: */
44
/* window_management.c :+: :+: :+: */
55
/* +:+ +:+ +:+ */
6-
/* By: ebabaogl <ebabaogl@student.42kocaeli.co +#+ +:+ +#+ */
6+
/* By: obastug <obastug@student.42.fr> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2025/01/02 15:09:01 by ebabaogl #+# #+# */
9-
/* Updated: 2025/01/02 15:37:30 by ebabaogl ### ########.fr */
9+
/* Updated: 2025/01/04 16:36:14 by obastug ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include <stdlib.h>
1414
#include "mlx.h"
1515
#include "window.h"
16+
#include "fdf.h"
1617

17-
static int close_win(void *param)
18+
void reset_camera(t_vars *vars)
19+
{
20+
int width_distance;
21+
int height_distance;
22+
23+
width_distance = (PADDED_WIDTH / 2) / (vars->line_count / 2);
24+
height_distance = (PADDED_HEIGHT / 2) / (vars->line_len / 2);
25+
vars->a_coef = 0;
26+
vars->d_coef = 0;
27+
vars->d_coef = 0;
28+
vars->s_coef = 0;
29+
vars->map_x = 0;
30+
vars->map_y = 0;
31+
vars->height = 1;
32+
if (width_distance > height_distance)
33+
vars->distance = height_distance;
34+
else
35+
vars->distance = width_distance;
36+
}
37+
38+
int close_win(void *param)
1839
{
1940
t_mlx *mlx;
2041

@@ -25,10 +46,19 @@ static int close_win(void *param)
2546
return (0);
2647
}
2748

28-
static int esc_handler(int keycode, void *param)
49+
int key_handler(int keycode, void *param)
2950
{
51+
t_vars *vars;
52+
53+
vars = (t_vars *)param;
54+
(void)keycode;
55+
(void)vars;
3056
if (keycode == ESC_KEY)
31-
close_win(param);
57+
{
58+
close_win(vars->mlx);
59+
return (0);
60+
}
61+
render_map(vars);
3262
return (0);
3363
}
3464

@@ -40,10 +70,5 @@ int init_win(t_mlx *mlx)
4070
mlx->win_ptr = mlx_new_window(mlx->mlx_ptr, WIN_WIDTH, WIN_HEIGHT, "FdF!!1!!!1");
4171
if (!mlx->win_ptr)
4272
return (free(mlx->mlx_ptr), -1);
43-
mlx_hook(mlx->win_ptr, ON_DESTROY, 0, close_win, mlx);
44-
mlx_key_hook(mlx->win_ptr, esc_handler, mlx);
45-
mlx_loop(mlx->mlx_ptr);
46-
mlx_destroy_display(mlx->mlx_ptr);
47-
free(mlx->mlx_ptr);
4873
return (0);
4974
}

0 commit comments

Comments
 (0)