From 66634b039e555fd240df1f38f0cacb6bd05bf32e Mon Sep 17 00:00:00 2001 From: Gregory Date: Wed, 15 Mar 2017 11:23:05 +0200 Subject: [PATCH] translade code from macos to linux --- inc/fdf.h | 14 +++++++------- src/FDF_init.c | 5 +---- src/image_routine.c | 14 ++++---------- src/main.c | 29 +++++++++++++++++++---------- src/map_init.c | 2 +- src/map_movement.c | 25 ++++++++++++++++++------- 6 files changed, 50 insertions(+), 39 deletions(-) diff --git a/inc/fdf.h b/inc/fdf.h index 532f322..202bc21 100644 --- a/inc/fdf.h +++ b/inc/fdf.h @@ -15,12 +15,11 @@ #include #include -# define HEIGHT 1000 -# define WIDTH 1000 -# define BPP 32 -# define ENDIAN 1 -# define COLOR1 2604805 -# define COLOR2 12518661 +# define HEIGHT 1300 +# define WIDTH 2500 +# define ENDIAN 0 +# define COLOR1 16515072 +# define COLOR2 252 # define INIT_X 30 # define INIT_Y -20 # define INIT_Z -45 @@ -155,7 +154,7 @@ t_color color_init(int red, int green, int blue); t_color color_lerp(t_color c1, t_color c2, float step); t_color int_to_color(int c); int color_to_int(t_color c); -t_color choose_color(t_line *line, t_swap *s, t_FDF *FDF); +t_color choose_color(t_line *line, t_swap *s); void first_color(t_pnt *pnt, float z, t_map *map); t_mw *mlx_and_win_ptr_init(int x, int y); @@ -175,5 +174,6 @@ void scale_up_z(t_FDF *FDF); void scale_down_z(t_FDF *FDF); void zoom_in(t_FDF *FDF); void zoom_out(t_FDF *FDF); +void reset(t_FDF *FDF); #endif diff --git a/src/FDF_init.c b/src/FDF_init.c index c95c64a..cdc6cd8 100644 --- a/src/FDF_init.c +++ b/src/FDF_init.c @@ -22,11 +22,8 @@ t_FDF *FDF_init(char *path) pnt_init(FDF->map); FDF->w_height = HEIGHT; FDF->w_width = WIDTH; - FDF->bpp = BPP; - FDF->line_size = WIDTH; - FDF->endian = ENDIAN; FDF->mw = mlx_and_win_ptr_init(WIDTH, HEIGHT); - FDF->image = mlx_new_image(FDF->mw->mlx, FDF->w_height, FDF->w_height); + FDF->image = mlx_new_image(FDF->mw->mlx, WIDTH, HEIGHT); FDF->image_data = mlx_get_data_addr( FDF->image, &FDF->bpp, diff --git a/src/image_routine.c b/src/image_routine.c index a8dabf6..1c403c7 100644 --- a/src/image_routine.c +++ b/src/image_routine.c @@ -12,15 +12,9 @@ void put_pixel_to_image(t_line *line, t_swap *s, t_FDF *FDF) y = line->p1.x; x = line->p1.y; } - if (x < 0) - x = 0; - if (x > FDF->w_width) - x = FDF->w_width; - if (y < 0) - y = 0; - if (y > FDF->w_height) - y = FDF->w_height; - *((int *)FDF->image_data + x + y * FDF->w_width) = color_to_int( - choose_color(line, s, FDF)); + if (x < 0 || y < 0 || x >= FDF->w_width || y >= FDF->w_height) + return ; + *(int *)((FDF->image_data + x * FDF->bpp / 8 + y * FDF->line_size)) = + color_to_int(choose_color(line, s)); } diff --git a/src/main.c b/src/main.c index cb8cde8..7275b2e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,14 +1,30 @@ #include "fdf.h" +void parse_input(int ac, char **av) +{ + if (ac == 2 && ft_strstr(av[1], "--help")) + { + print_help(); + } + if (ac == 4 && ft_strstr(av[1], "--heatmap")) + { + + } +} + int main(int argc, char **argv) { t_FDF *FDF; -// int i = 0; - if (argc < 2) + + if (argc < 2 && argc > 4) { print_help(); return (0); } + else if (argc < 4) + { + parse_input(argc, argv); + } FDF = FDF_init(argv[1]); center(FDF->map); FDF->map->trnsf = initial_trnsf_mats(FDF); @@ -16,14 +32,7 @@ int main(int argc, char **argv) mat4_mult_chain(FDF); transform(FDF->map->trnsf->fin, FDF->map); render(FDF); -// sleep(10); -// while (i < 360) -// { -// usleep(15000); -// clock_rot(FDF); -// i++; -// } - mlx_key_hook(FDF->mw->win, key_hook, FDF); + mlx_hook(FDF->mw->win, 2, 5, key_hook, FDF); mlx_loop(FDF->mw->mlx); return (0); } diff --git a/src/map_init.c b/src/map_init.c index 0ed44c8..2b9e509 100644 --- a/src/map_init.c +++ b/src/map_init.c @@ -75,7 +75,7 @@ t_map *map_init(char *path) map->scale[2] = 1; if (!(str_map = to_str_map(path))) { - ft_putstr("Wrong path to a map! For help help put \"fdf --help\""); + ft_putstr("Wrong path to a map! For help help put \"fdf --help\"\n"); quit(0); } tab_map = ft_strsplit(str_map, '\n'); diff --git a/src/map_movement.c b/src/map_movement.c index 0ecca91..c58259a 100644 --- a/src/map_movement.c +++ b/src/map_movement.c @@ -6,7 +6,7 @@ void move(t_FDF *FDF) mat4_mult_chain(FDF); transform(FDF->map->trnsf->fin, FDF->map); mlx_destroy_image(FDF->mw->mlx, FDF->image); - FDF->image = mlx_new_image(FDF->mw->mlx, FDF->w_height, FDF->w_height); + FDF->image = mlx_new_image(FDF->mw->mlx, WIDTH, HEIGHT); FDF->image_data = mlx_get_data_addr( FDF->image, &FDF->bpp, @@ -17,37 +17,37 @@ void move(t_FDF *FDF) void left_rot(t_FDF *FDF) { - FDF->map->y_rot -= 2; + FDF->map->y_rot -= 1; move(FDF); } void right_rot(t_FDF *FDF) { - FDF->map->y_rot += 2; + FDF->map->y_rot += 1; move(FDF); } void forw_rot(t_FDF *FDF) { - FDF->map->x_rot += 2; + FDF->map->x_rot += 1; move(FDF); } void back_rot(t_FDF *FDF) { - FDF->map->x_rot -= 2; + FDF->map->x_rot -= 1; move(FDF); } void clock_rot(t_FDF *FDF) { - FDF->map->z_rot -= 2; + FDF->map->z_rot -= 1; move(FDF); } void aclock_rot(t_FDF *FDF) { - FDF->map->z_rot += 2; + FDF->map->z_rot += 1; move(FDF); } @@ -75,4 +75,15 @@ 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); } \ No newline at end of file