3
3
/* ::: :::::::: */
4
4
/* fdf.c :+: :+: :+: */
5
5
/* +:+ +:+ +:+ */
6
- /* By: ebabaogl <ebabaogl @student.42kocaeli.co +#+ +:+ +#+ */
6
+ /* By: obastug <obastug @student.42.fr> +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2025/01/02 11:39:32 by ebabaogl #+# #+# */
9
- /* Updated: 2025/01/03 16:55:03 by ebabaogl ### ########.fr */
9
+ /* Updated: 2025/01/04 16:36:54 by obastug ### ########.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
13
+ #include "mlx.h"
13
14
#include "fdf.h"
14
15
#include "window.h"
15
16
#include "libft.h"
18
19
#include <limits.h>
19
20
#include <stdio.h>
20
21
#include <unistd.h>
21
- unsigned int ft_atoi_hex (char * str );
22
22
23
- int main ()
23
+
24
+ void put_pixel (void * mlx_ptr , void * win_ptr , int x , int y , unsigned long color )
24
25
{
25
- //t_vars vars;
26
- //t_mlx mlx;
27
-
28
- // char *map = read_file("test_maps/42.fdf");
29
- // printf("%s", map);
30
- // free(map);
31
- //vars.mlx = &mlx;
32
- //if (init_win(vars.mlx) == -1)
33
- char * map_str = read_file ("test_maps/42.fdf" );
34
- unsigned long * * map = map_string_to_arr_2d (map_str );
35
- write (1 , "helloworld" , 10 );
36
- size_t i ;
37
- size_t j ;
26
+ printf ("pixel sent to mlx: %d, %d\n" , (WIN_WIDTH / 2 ) + x , (WIN_HEIGHT / 2 ) - y );
27
+ mlx_pixel_put (mlx_ptr , win_ptr , (WIN_WIDTH / 2 ) + x , (WIN_HEIGHT / 2 ) + y , color );
28
+ }
29
+
30
+ void render_and_put_pixel (t_vars * vars , int x , int y , unsigned long point )
31
+ {
32
+ int final_x ;
33
+ int final_y ;
34
+
35
+ final_x = (x - vars -> anchor_x ) * vars -> distance ;
36
+ final_y = (y - vars -> anchor_y ) * vars -> distance ;
37
+ put_pixel (vars -> mlx -> mlx_ptr , vars -> mlx -> win_ptr , final_x , final_y , get_color (point ));
38
+ printf ("anchor point: %d %d\n" , vars -> anchor_x , vars -> anchor_y );
39
+ printf ("coordinate: %d, %d\n" , final_x , final_y );
40
+ printf ("distance: %d\n" , vars -> distance );
41
+ }
42
+
43
+ void render_map (t_vars * vars )
44
+ {
45
+ int i ;
46
+ int j ;
38
47
i = 0 ;
39
- j = 0 ;
40
- while (map [i ])
48
+ while (vars -> map [i ])
41
49
{
42
- while (map [i ][j ] != ULONG_MAX )
50
+ j = 0 ;
51
+ while (vars -> map [i ][j ] != ULONG_MAX )
43
52
{
44
- printf ("i: %lu, " , i );
45
- printf ("z: %lu, " , map [i ][j ] >> 32 );
46
- printf ("color: %lu\n" , map [i ][j ] & COLOR_MASK );
53
+ render_and_put_pixel (vars , i , j , vars -> map [i ][j ]);
47
54
j ++ ;
48
55
}
49
56
i ++ ;
50
57
}
58
+ }
59
+
60
+ void fdf (t_vars * vars )
61
+ {
62
+ // mlx_hook(vars->mlx->mlx_ptr, ON_DESTROY, 0, close_win, vars->mlx);
63
+ reset_camera (vars );
64
+ mlx_key_hook (vars -> mlx -> win_ptr , key_handler , vars );
65
+ mlx_loop (vars -> mlx -> mlx_ptr );
66
+ mlx_destroy_display (vars -> mlx -> mlx_ptr );
67
+ free (vars -> mlx -> mlx_ptr );
68
+ }
69
+
70
+ void set_map_props (t_vars * vars )
71
+ {
72
+ int i ;
73
+
74
+ i = 0 ;
75
+ while (vars -> map [0 ][i ] != ULONG_MAX )
76
+ i ++ ;
77
+ vars -> line_len = i ;
78
+ vars -> anchor_x = i / 2 ;
79
+ i = 0 ;
80
+ while (vars -> map [i ])
81
+ i ++ ;
82
+ vars -> line_count = i ;
83
+ vars -> anchor_y = i / 2 ;
84
+ }
85
+
86
+ int main ()
87
+ {
88
+ t_vars vars ;
89
+ t_mlx mlx ;
90
+ char * map_str ;
91
+
92
+ map_str = read_file ("test_maps/2x2.fdf" );
93
+ if (!map_str )
94
+ return (write (1 , "file couldn't read" , 18 ), 1 );
95
+ vars .map = map_string_to_arr_2d (map_str );
96
+ if (!vars .map )
97
+ return (write (1 , "invalid map" , 11 ), 1 );
98
+ set_map_props (& vars );
99
+ vars .mlx = & mlx ;
100
+ init_win (& mlx );
101
+ fdf (& vars );
102
+
51
103
return (1 );
52
104
}
0 commit comments