From da01f1737b2f6c748a8b667ccd2e3d0e314724ba Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Fri, 21 Feb 2020 19:47:21 +0100 Subject: on est la --- src/main.c | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'src') diff --git a/src/main.c b/src/main.c index ededacf..52bb211 100644 --- a/src/main.c +++ b/src/main.c @@ -15,30 +15,17 @@ #include #include #include -#include -#include - -void - *ft_zik(void *vargp) -{ - (void)vargp; - system("afplay revelations.mp3"); - return NULL; -} int main(int argc, const char *argv[]) { t_cub *clist; - pthread_t thread_id; if (argc < 2) { ft_dprintf(STDERR_FILENO, "Error\n\033[1;31mNo map selected\n\033[0m"); return (1); } - pthread_create(&thread_id, NULL, ft_zik, NULL); - pthread_join(thread_id, NULL); if (ft_init_cub3d(&clist) < 0) return (2); ft_parse_map(argv[1], clist); -- cgit v1.2.3 From 2bc91ff7a1cdb2c7a97df74d89609e0c3ca1bb8e Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Fri, 21 Feb 2020 21:44:26 +0100 Subject: que des maths --- src/ft_get_sprite.c | 20 +++++++++++++++++++- src/ft_raycasting.c | 12 ++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index 43de290..806489f 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -17,8 +17,26 @@ void ft_get_sprite_spawn(t_cub *clist) { + size_t x; + size_t y; - (void)clist; + x = 1; + y = 1; + while (clist->mlist->map[y]) + { + while (clist->mlist->map[y][x]) + { + if (ft_ischarset("2", clist->mlist->map[y][x])) + { + clist->sp_list.s_pos_x = x + 0.5; + clist->sp_list.s_pos_y = y + 0.5; + return ; + } + x++; + } + x = 1; + y++; + } } int8_t diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index dd2be64..589d2da 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -16,6 +16,17 @@ #include void + ft_calc_sprite(t_cub *cl) +{ + cl->sp_list.s_x = cl->sp_list.s_pos_x - cl->plist->pos_x; + cl->sp_list.s_y = cl->sp_list.s_pos_y - cl->plist->pos_y; + cl->sp_list.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_x - cl->plist->dir_y * cl->plist->plane_y); + cl->sp_list.sprite_transform_x = cl->sp_list.inv_c_m * (cl->plist->dir_y * cl->sp_list.s_x - cl->plist->dir_x * cl->sp_list.s_y); + cl->sp_list.sprite_transform_y = cl->sp_list.inv_c_m * (cl->plist->plane_y * cl->sp_list.s_x - cl->plist->plane_x * cl->sp_list.s_y); + +} + +static void ft_calc_tex(t_cub *clist) { if (clist->rlist.side == 0) @@ -83,6 +94,7 @@ void cl->rlist.wall_b = wl->y_size - 1; ft_choose_tex(cl); ft_calc_tex(cl); + ft_calc_sprite(cl); ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); i++; } -- cgit v1.2.3 From d2f53e38cbf711e35035a4576070a5211a1d055d Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Sat, 22 Feb 2020 20:56:50 +0100 Subject: shpritz --- src/ft_draw_sprite.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/ft_raycasting.c | 20 ++++++++++++++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 src/ft_draw_sprite.c (limited to 'src') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c new file mode 100644 index 0000000..38c1fd9 --- /dev/null +++ b/src/ft_draw_sprite.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include +#include + +void +ft_draw_verline_sprite(t_cub *cl, int x, int y, int tex_y) +{ + cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = + (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * + cl->tlist[cl->w_side].img_h * tex_y]; + cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = + (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * + cl->tlist[cl->w_side].img_h * tex_y + 1]; + cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = + (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * + cl->tlist[cl->w_side].img_h * tex_y + 2]; + cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; +} + +void +ft_draw_sprite(t_cub *cl, int x) +{ + int ver_it;/*stripe*/ + int hor_it;/*y*/ + int tex_x; + int tex_y; + int d; + + ver_it = cl->sp_list.s_start_x; + while (ver_it < cl->sp_list.s_end_x) + { + tex_x = (int)(256 * (ver_it - (-cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x)) * cl->tlist[4].img_w / cl->sp_list.s_w) / 256; + hor_it = cl->sp_list.s_start_y; + while (hor_it < cl->sp_list.s_end_y) + { + d = hor_it * 256 - cl->wlist->y_size * 128 + cl->sp_list.s_h * 128; + tex_y = ((d * cl->tlist[4].img_h) / cl->sp_list.s_h) / 256; + ft_draw_verline_sprite(cl, x, hor_it, tex_y); + } + ver_it++; + } +} diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 589d2da..b42e0b7 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -13,6 +13,7 @@ #include #include #include +#include #include void @@ -23,7 +24,21 @@ void cl->sp_list.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_x - cl->plist->dir_y * cl->plist->plane_y); cl->sp_list.sprite_transform_x = cl->sp_list.inv_c_m * (cl->plist->dir_y * cl->sp_list.s_x - cl->plist->dir_x * cl->sp_list.s_y); cl->sp_list.sprite_transform_y = cl->sp_list.inv_c_m * (cl->plist->plane_y * cl->sp_list.s_x - cl->plist->plane_x * cl->sp_list.s_y); - + cl->sp_list.s_screen_x = (int)((cl->wlist->y_size / 2) * (1 + cl->sp_list.sprite_transform_x / cl->sp_list.sprite_transform_y)); + cl->sp_list.s_h = abs((int)(cl->wlist->y_size * cl->sp_list.sprite_transform_y)); /*sprite height*/ + cl->sp_list.s_start_y = -cl->sp_list.s_h / 2 + cl->wlist->y_size / 2; + if (cl->sp_list.s_start_y < 0) + cl->sp_list.s_start_y = 0; + cl->sp_list.s_end_y = cl->sp_list.s_h / 2 + cl->wlist->y_size / 2; + if (cl->sp_list.s_end_y > (int)cl->wlist->y_size) + cl->sp_list.s_end_y = cl->wlist->y_size - 1;; + cl->sp_list.s_w = abs((int)(cl->wlist->x_size * cl->sp_list.sprite_transform_y)); /*sprite width*/ + cl->sp_list.s_start_x = -cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x; + if (cl->sp_list.s_start_x < 0) + cl->sp_list.s_start_y = 0; + cl->sp_list.s_end_x = cl->sp_list.s_w / 2 + cl->wlist->x_size; + if (cl->sp_list.s_end_x < (int)cl->wlist->x_size) + cl->sp_list.s_end_x = cl->wlist->x_size - 1; } static void @@ -35,7 +50,7 @@ static void else clist->rlist.wall_hit_x = (clist->plist->pos_y) + clist->rlist.wall_dist * clist->rlist.x_ray_dir; - clist->rlist.wall_hit_x -= floor(clist->rlist.wall_hit_x); + clist->rlist.wall_hit_x -= floor(clist->rlist.wall_hit_x); clist->tlist[clist->w_side].tex_x = (int)(clist->rlist.wall_hit_x * (double)clist->tlist[clist->w_side].img_w); if (clist->rlist.side == 0 && clist->rlist.x_ray_dir > 0) @@ -95,6 +110,7 @@ void ft_choose_tex(cl); ft_calc_tex(cl); ft_calc_sprite(cl); + ft_draw_sprite(cl , i); ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); i++; } -- cgit v1.2.3 From 9fc4434c0deac6a3537183266adb9e85f3883db8 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 24 Feb 2020 10:20:20 +0100 Subject: tests --- src/ft_detect.c | 3 +-- src/ft_draw_sprite.c | 12 ++++++++---- src/ft_raycasting.c | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ft_detect.c b/src/ft_detect.c index fc49a2d..10d7147 100644 --- a/src/ft_detect.c +++ b/src/ft_detect.c @@ -74,8 +74,7 @@ void cl->rlist.sqy += cl->mlist->y_step; cl->rlist.side = 1; } - if (cl->mlist->map[cl->rlist.sqx][cl->rlist.sqy] == '1' - || cl->mlist->map[cl->rlist.sqx][cl->rlist.sqy] == '2') + if (cl->mlist->map[cl->rlist.sqx][cl->rlist.sqy] == '1') cl->rlist.hit = 1; } } diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 38c1fd9..e7df49b 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -29,15 +30,18 @@ ft_draw_sprite(t_cub *cl, int x) int d; ver_it = cl->sp_list.s_start_x; - while (ver_it < cl->sp_list.s_end_x) + ver_it = (ver_it < 0) ? -ver_it : ver_it ; + while (ver_it < cl->sp_list.s_end_x - 1) { tex_x = (int)(256 * (ver_it - (-cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x)) * cl->tlist[4].img_w / cl->sp_list.s_w) / 256; hor_it = cl->sp_list.s_start_y; - while (hor_it < cl->sp_list.s_end_y) + while (hor_it < cl->sp_list.s_end_y - 1) { - d = hor_it * 256 - cl->wlist->y_size * 128 + cl->sp_list.s_h * 128; - tex_y = ((d * cl->tlist[4].img_h) / cl->sp_list.s_h) / 256; + d = (hor_it) * 256 - cl->wlist->y_size * 128 + cl->sp_list.s_h * 128; + tex_y = ((d * cl->tlist[4].img_w) / cl->sp_list.s_h) / 256; ft_draw_verline_sprite(cl, x, hor_it, tex_y); + hor_it++; + printf("hor_it : %d ver it : %d", hor_it, ver_it); } ver_it++; } diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index b42e0b7..dd68cd3 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -110,8 +110,8 @@ void ft_choose_tex(cl); ft_calc_tex(cl); ft_calc_sprite(cl); - ft_draw_sprite(cl , i); ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); + ft_draw_sprite(cl , i); i++; } } -- cgit v1.2.3 From 84a92b0d2824a97c3358f8ce86290aa8a718618e Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 24 Feb 2020 18:19:58 +0100 Subject: very bad --- src/ft_draw_sprite.c | 53 ++++++++++++++++++++++++++-------------------------- src/ft_key_loop.c | 2 +- 2 files changed, 28 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index e7df49b..5f7fd31 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -8,41 +8,42 @@ void ft_draw_verline_sprite(t_cub *cl, int x, int y, int tex_y) { - cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = - (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * - cl->tlist[cl->w_side].img_h * tex_y]; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = - (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * - cl->tlist[cl->w_side].img_h * tex_y + 1]; - cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = - (char)cl->tlist[cl->w_side].ptr[cl->tlist[cl->w_side].tex_x * 4 + 4 * - cl->tlist[cl->w_side].img_h * tex_y + 2]; - cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; + if (cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * + cl->tlist[4].img_h * tex_y] != 0) + { + cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = + (char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * + cl->tlist[4].img_h * tex_y]; + cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = + (char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * + cl->tlist[4].img_h * tex_y + 1]; + cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = + (char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * + cl->tlist[4].img_h * tex_y + 2]; + cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; + } + else + { + cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)255; + } } void -ft_draw_sprite(t_cub *cl, int x) + ft_draw_sprite(t_cub *cl, int x) { int ver_it;/*stripe*/ int hor_it;/*y*/ - int tex_x; - int tex_y; int d; + int tex_y; ver_it = cl->sp_list.s_start_x; - ver_it = (ver_it < 0) ? -ver_it : ver_it ; - while (ver_it < cl->sp_list.s_end_x - 1) + hor_it = cl->sp_list.s_start_y; + while (hor_it < cl->sp_list.s_end_y) { - tex_x = (int)(256 * (ver_it - (-cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x)) * cl->tlist[4].img_w / cl->sp_list.s_w) / 256; - hor_it = cl->sp_list.s_start_y; - while (hor_it < cl->sp_list.s_end_y - 1) - { - d = (hor_it) * 256 - cl->wlist->y_size * 128 + cl->sp_list.s_h * 128; - tex_y = ((d * cl->tlist[4].img_w) / cl->sp_list.s_h) / 256; - ft_draw_verline_sprite(cl, x, hor_it, tex_y); - hor_it++; - printf("hor_it : %d ver it : %d", hor_it, ver_it); - } - ver_it++; + d = (hor_it) * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; + d = (d <= 0) ? (-d) : (d); + tex_y = ((d * cl->tlist[4].img_h) / cl->rlist.line_h) / 256; + ft_draw_verline_sprite(cl, x, hor_it, tex_y); + hor_it++; } } diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index b902e33..aa7017f 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -46,8 +46,8 @@ int { (*fun_ptr[cl->key_input[i]])(cl); ft_collision(old_y, old_x, cl->plist, cl->mlist); - ft_draw_scene(cl); i++; } + ft_draw_scene(cl); return (0); } -- cgit v1.2.3 From 6a56c9beea934597431643994f85479bc1792466 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 24 Feb 2020 19:01:52 +0100 Subject: oy --- src/ft_draw_sprite.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 5f7fd31..c90c9ac 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -8,9 +8,7 @@ void ft_draw_verline_sprite(t_cub *cl, int x, int y, int tex_y) { - if (cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * - cl->tlist[4].img_h * tex_y] != 0) - { + if (cl->tlist[4].tex_x) cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = (char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * cl->tlist[4].img_h * tex_y]; @@ -21,28 +19,22 @@ ft_draw_verline_sprite(t_cub *cl, int x, int y, int tex_y) (char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 * cl->tlist[4].img_h * tex_y + 2]; cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)0; - } - else - { - cl->img.ptr[x * 4 + cl->wlist->x_size * y + 3] = (char)255; - } } void ft_draw_sprite(t_cub *cl, int x) { - int ver_it;/*stripe*/ int hor_it;/*y*/ int d; int tex_y; - ver_it = cl->sp_list.s_start_x; hor_it = cl->sp_list.s_start_y; while (hor_it < cl->sp_list.s_end_y) { - d = (hor_it) * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; - d = (d <= 0) ? (-d) : (d); + d = hor_it * 256 - cl->wlist->y_size * 128 + cl->rlist.line_h * 128; + d = (d <= 0) ? (-d) : (d); tex_y = ((d * cl->tlist[4].img_h) / cl->rlist.line_h) / 256; + (tex_y < 0) ? (tex_y = 0) : 0; ft_draw_verline_sprite(cl, x, hor_it, tex_y); hor_it++; } -- cgit v1.2.3