From fe145d4c59886b857b0966f8e9b673cfacc0695f Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 24 Feb 2020 22:20:33 +0100 Subject: found 2 infinit loops hehe --- src/ft_raycasting.c | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'src/ft_raycasting.c') diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index d51b77f..626ced4 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -13,34 +13,17 @@ #include #include #include +#include #include #include -static void - ft_calc_sprite_norme(t_cub *cl) -{ - 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 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.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_y + - cl->plist->dir_x * 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); @@ -52,10 +35,32 @@ static void / cl->sp_list.sprite_transform_y)); cl->sp_list.s_h = abs((int)(cl->wlist->y_size * cl->sp_list.sprite_transform_y)); - cl->sp_list.s_start_y = -cl->sp_list.s_h / 2 + cl->wlist->y_size / 2; ft_calc_sprite_norme(cl); } +void + ft_calc_sprite_norme(t_cub *cl) +{ + 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; + /*ft_printf("start x: %d\nstart y : %d\n", cl->sp_list.s_start_x, cl->sp_list.s_start_y);*/ + /*ft_printf("end x: %d\nend y : %d\n", cl->sp_list.s_end_x, cl->sp_list.s_end_y);*/ + /*ft_draw_sprite(cl);*/ +} + + void ft_calc_tex(t_cub *clist) { @@ -112,6 +117,7 @@ void i = 0; wl = cl->wlist; + ft_calc_sprite(cl); while (i < wl->x_size) { ft_initray(cl, i); @@ -124,8 +130,6 @@ void cl->rlist.wall_b = wl->y_size - 1; 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 3363be36b7ffe90fc335e07ebb1dae14366216e8 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 24 Feb 2020 23:14:16 +0100 Subject: gang --- src/ft_raycasting.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/ft_raycasting.c') diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 626ced4..5bf0785 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -17,7 +17,7 @@ #include #include -static void +void ft_calc_sprite(t_cub *cl) { cl->sp_list.s_x = cl->sp_list.s_pos_x - cl->plist->pos_x; @@ -57,7 +57,7 @@ void cl->sp_list.s_end_x = cl->wlist->x_size - 1; /*ft_printf("start x: %d\nstart y : %d\n", cl->sp_list.s_start_x, cl->sp_list.s_start_y);*/ /*ft_printf("end x: %d\nend y : %d\n", cl->sp_list.s_end_x, cl->sp_list.s_end_y);*/ - /*ft_draw_sprite(cl);*/ + ft_draw_sprite(cl); } @@ -117,7 +117,6 @@ void i = 0; wl = cl->wlist; - ft_calc_sprite(cl); while (i < wl->x_size) { ft_initray(cl, i); -- cgit v1.2.3 From cc85b0a701b558e18299822f7091fc2fd137b14b Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Tue, 25 Feb 2020 16:43:54 +0100 Subject: bunch of garbage --- src/ft_raycasting.c | 63 +++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'src/ft_raycasting.c') diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 5bf0785..be4a815 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -20,44 +20,45 @@ 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_y + cl->sprites.s_x = cl->sprites.s_pos_x - cl->plist->pos_x; + cl->sprites.s_y = cl->sprites.s_pos_y - cl->plist->pos_y; + cl->sprites.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_y - cl->plist->dir_x * 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)); + cl->sprites.sprite_transform_x = cl->sprites.inv_c_m + * (cl->plist->dir_y * cl->sprites.s_x + - cl->plist->dir_x * cl->sprites.s_y); + cl->sprites.sprite_transform_y = cl->sprites.inv_c_m + * (-cl->plist->plane_y * cl->sprites.s_x + + cl->plist->plane_x * cl->sprites.s_y); + cl->sprites.s_screen_x = (int)((cl->wlist->x_size / 2) + * (1 + cl->sprites.sprite_transform_x + / cl->sprites.sprite_transform_y)); + cl->sprites.s_h = + abs((int)(cl->wlist->y_size * cl->sprites.sprite_transform_y)); ft_calc_sprite_norme(cl); } void ft_calc_sprite_norme(t_cub *cl) { - 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; - /*ft_printf("start x: %d\nstart y : %d\n", cl->sp_list.s_start_x, cl->sp_list.s_start_y);*/ - /*ft_printf("end x: %d\nend y : %d\n", cl->sp_list.s_end_x, cl->sp_list.s_end_y);*/ - ft_draw_sprite(cl); + cl->sprites.s_start_y = -cl->sprites.s_h / 2 + cl->wlist->y_size / 2; + if (cl->sprites.s_start_y < 0) + cl->sprites.s_start_y = 0; + cl->sprites.s_end_y = cl->sprites.s_h / 2 + cl->wlist->y_size / 2; + if (cl->sprites.s_end_y > (int)cl->wlist->y_size) + cl->sprites.s_end_y = cl->wlist->y_size - 1; + cl->sprites.s_w = abs((int)(cl->wlist->y_size + / cl->sprites.sprite_transform_y)); /*sprite width*/ + cl->sprites.s_start_x = -cl->sprites.s_w / 2 + cl->sprites.s_screen_x; + if (cl->sprites.s_start_x < 0) + cl->sprites.s_start_x = 0; + cl->sprites.s_end_x = cl->sprites.s_w / 2 + cl->sprites.s_screen_x; + printf("%d\n", cl->sprites.s_w); + if (cl->sprites.s_end_x > (int)cl->wlist->x_size) + cl->sprites.s_end_x = cl->wlist->x_size - 1; + /*ft_printf("start x: %d\nend x : %d\n", cl->sprites.s_start_x, cl->sprites.s_end_x);*/ + /*ft_printf("start y: %d\nend y : %d\n", cl->sprites.s_start_y, cl->sprites.s_end_y);*/ + /*ft_draw_sprite(cl);*/ } -- cgit v1.2.3 From 51dd3734caadd0c3b943da3410772c65558280cc Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Tue, 25 Feb 2020 17:33:15 +0100 Subject: ??? --- src/ft_raycasting.c | 85 +++++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 42 deletions(-) (limited to 'src/ft_raycasting.c') diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index be4a815..d97c231 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -18,49 +18,49 @@ #include void - ft_calc_sprite(t_cub *cl) + ft_sprite_height(t_cub *cl, t_sprite *sprite) { - cl->sprites.s_x = cl->sprites.s_pos_x - cl->plist->pos_x; - cl->sprites.s_y = cl->sprites.s_pos_y - cl->plist->pos_y; - cl->sprites.inv_c_m = 1.0 / (cl->plist->plane_x * cl->plist->dir_y - - cl->plist->dir_x * cl->plist->plane_y); - cl->sprites.sprite_transform_x = cl->sprites.inv_c_m - * (cl->plist->dir_y * cl->sprites.s_x - - cl->plist->dir_x * cl->sprites.s_y); - cl->sprites.sprite_transform_y = cl->sprites.inv_c_m - * (-cl->plist->plane_y * cl->sprites.s_x - + cl->plist->plane_x * cl->sprites.s_y); - cl->sprites.s_screen_x = (int)((cl->wlist->x_size / 2) - * (1 + cl->sprites.sprite_transform_x - / cl->sprites.sprite_transform_y)); - cl->sprites.s_h = - abs((int)(cl->wlist->y_size * cl->sprites.sprite_transform_y)); - ft_calc_sprite_norme(cl); + sprite->spriteheight = abs((int)(cl->wlist->y_size / (sprite->transformy))); + sprite->drawstarty = -sprite->spriteheight / 2 + cl->wlist->y_size / 2; + if (sprite->drawstarty < 0) + sprite->drawstarty = 0; + sprite->drawendy = sprite->spriteheight / 2 + cl->wlist->y_size / 2; + if (sprite->drawendy >= (int)cl->wlist->y_size) + sprite->drawendy = cl->wlist->y_size; } void - ft_calc_sprite_norme(t_cub *cl) + ft_sprite_width(t_cub *cl, t_sprite *sprite) { - cl->sprites.s_start_y = -cl->sprites.s_h / 2 + cl->wlist->y_size / 2; - if (cl->sprites.s_start_y < 0) - cl->sprites.s_start_y = 0; - cl->sprites.s_end_y = cl->sprites.s_h / 2 + cl->wlist->y_size / 2; - if (cl->sprites.s_end_y > (int)cl->wlist->y_size) - cl->sprites.s_end_y = cl->wlist->y_size - 1; - cl->sprites.s_w = abs((int)(cl->wlist->y_size - / cl->sprites.sprite_transform_y)); /*sprite width*/ - cl->sprites.s_start_x = -cl->sprites.s_w / 2 + cl->sprites.s_screen_x; - if (cl->sprites.s_start_x < 0) - cl->sprites.s_start_x = 0; - cl->sprites.s_end_x = cl->sprites.s_w / 2 + cl->sprites.s_screen_x; - printf("%d\n", cl->sprites.s_w); - if (cl->sprites.s_end_x > (int)cl->wlist->x_size) - cl->sprites.s_end_x = cl->wlist->x_size - 1; - /*ft_printf("start x: %d\nend x : %d\n", cl->sprites.s_start_x, cl->sprites.s_end_x);*/ - /*ft_printf("start y: %d\nend y : %d\n", cl->sprites.s_start_y, cl->sprites.s_end_y);*/ - /*ft_draw_sprite(cl);*/ + sprite->spritewidth = abs((int)(cl->wlist->x_size / (sprite->transformy))); + sprite->drawstartx = -sprite->spritewidth / 2 + sprite->spritescreenx; + if (sprite->drawstartx < 0) + sprite->drawstartx = 0; + sprite->drawendx = sprite->spritewidth / 2 + sprite->spritescreenx; + if (sprite->drawendx >= (int)cl->wlist->x_size) + sprite->drawendx = cl->wlist->x_size; } +void + ft_calc_sprite(t_cub *cl) +{ + t_sprite sprite; + + sprite = cl->sprites; + sprite.spritex = (sprite.spritex + 0.5) - cl->plist->pos_x; + sprite.spritey = (sprite.spritey + 0.5) - cl->plist->pos_y; + sprite.invdet = 1.0 / (cl->plist->plane_x * + cl->plist->dir_y - cl->plist->dir_x * cl->plist->plane_y); + sprite.transformx = sprite.invdet * (cl->plist->dir_y * + sprite.spritex - cl->plist->dir_x * sprite.spritey); + sprite.transformy = sprite.invdet * + (-cl->plist->plane_y * sprite.spritex + cl->plist->plane_x * sprite.spritey); + sprite.spritescreenx = (int)((cl->wlist->x_size / 2) * + (1 + sprite.transformx / sprite.transformy)); + ft_sprite_height(cl, &sprite); + ft_sprite_width(cl, &sprite); + ft_draw_sprite(cl, &sprite); +} void ft_calc_tex(t_cub *clist) @@ -82,8 +82,8 @@ void - clist->tlist[clist->w_side].tex_x - 1; } -static void - ft_initray(t_cub *cl, uint16_t i) + static void +ft_initray(t_cub *cl, uint16_t i) { t_win *wl; t_player *pl; @@ -103,15 +103,15 @@ static void if (cl->rlist.side == 0) { cl->rlist.wall_dist = (cl->rlist.sqx - cl->rlist.x_ray_pos + - (1 - cl->mlist->x_step) / 2) / cl->rlist.x_ray_dir; + (1 - cl->mlist->x_step) / 2) / cl->rlist.x_ray_dir; } else cl->rlist.wall_dist = (cl->rlist.sqy - cl->rlist.y_ray_pos + - (1 - cl->mlist->y_step) / 2) / cl->rlist.y_ray_dir; + (1 - cl->mlist->y_step) / 2) / cl->rlist.y_ray_dir; } -void - ft_castray(t_cub *cl) + void +ft_castray(t_cub *cl) { uint16_t i; t_win *wl; @@ -130,6 +130,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 3f8b598e0a1b60475fdf8aa98c601b4513a24efa Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Tue, 25 Feb 2020 18:09:57 +0100 Subject: gee --- src/ft_raycasting.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src/ft_raycasting.c') diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index d97c231..59021d3 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -130,7 +130,6 @@ ft_castray(t_cub *cl) 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 903fe03f0f6b1f70faa3139b57db24cb6c51b0a6 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Wed, 26 Feb 2020 12:19:10 +0100 Subject: only one floating sprite, one line / 2 correct, start and end seems flawed --- src/ft_raycasting.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/ft_raycasting.c') diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 59021d3..e7cc4ef 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -47,12 +47,12 @@ void t_sprite sprite; sprite = cl->sprites; - sprite.spritex = (sprite.spritex + 0.5) - cl->plist->pos_x; - sprite.spritey = (sprite.spritey + 0.5) - cl->plist->pos_y; + sprite.spritex = (sprite.spritex + 1) - cl->plist->pos_x; + sprite.spritey = (sprite.spritey + 1) - cl->plist->pos_y; sprite.invdet = 1.0 / (cl->plist->plane_x * cl->plist->dir_y - cl->plist->dir_x * cl->plist->plane_y); sprite.transformx = sprite.invdet * (cl->plist->dir_y * - sprite.spritex - cl->plist->dir_x * sprite.spritey); + sprite.spritey - cl->plist->dir_x * sprite.spritex); sprite.transformy = sprite.invdet * (-cl->plist->plane_y * sprite.spritex + cl->plist->plane_x * sprite.spritey); sprite.spritescreenx = (int)((cl->wlist->x_size / 2) * -- cgit v1.2.3 From 8f852afcfa170070b6f0ac2e321546990d87e401 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Fri, 28 Feb 2020 15:30:53 +0100 Subject: gang --- src/ft_raycasting.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/ft_raycasting.c') diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index e7cc4ef..0173fe6 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -49,6 +49,7 @@ void sprite = cl->sprites; sprite.spritex = (sprite.spritex + 1) - cl->plist->pos_x; sprite.spritey = (sprite.spritey + 1) - cl->plist->pos_y; + printf("%f%f\n", sprite.spritex, sprite.spritey); sprite.invdet = 1.0 / (cl->plist->plane_x * cl->plist->dir_y - cl->plist->dir_x * cl->plist->plane_y); sprite.transformx = sprite.invdet * (cl->plist->dir_y * -- cgit v1.2.3 From a1891c76be7688be7f9e213308b6af33e3d3dacf Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Sat, 29 Feb 2020 20:34:02 +0100 Subject: debugging... --- src/ft_raycasting.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/ft_raycasting.c') diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 0173fe6..0cd4cc6 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -45,22 +45,30 @@ void ft_calc_sprite(t_cub *cl) { t_sprite sprite; + static int i = 0; + float tmp_a; + float tmp_b; sprite = cl->sprites; - sprite.spritex = (sprite.spritex + 1) - cl->plist->pos_x; - sprite.spritey = (sprite.spritey + 1) - cl->plist->pos_y; - printf("%f%f\n", sprite.spritex, sprite.spritey); + tmp_a = cl->plist->dir_x; + tmp_b = cl->plist->dir_y; + sprite.spritex = sprite.spritex - (cl->plist->pos_x - 0.5); + sprite.spritey = sprite.spritey - (cl->plist->pos_y - 0.5); + printf("[%f] [%f] x [%f] y [%f] [%d]\n", sprite.spritex, sprite.spritey, cl->plist->dir_x, cl->plist->dir_y, i); sprite.invdet = 1.0 / (cl->plist->plane_x * cl->plist->dir_y - cl->plist->dir_x * cl->plist->plane_y); sprite.transformx = sprite.invdet * (cl->plist->dir_y * sprite.spritey - cl->plist->dir_x * sprite.spritex); sprite.transformy = sprite.invdet * (-cl->plist->plane_y * sprite.spritex + cl->plist->plane_x * sprite.spritey); - sprite.spritescreenx = (int)((cl->wlist->x_size / 2) * + sprite.spritescreenx = (int)((cl->wlist->y_size / 2) * (1 + sprite.transformx / sprite.transformy)); ft_sprite_height(cl, &sprite); ft_sprite_width(cl, &sprite); ft_draw_sprite(cl, &sprite); + cl->plist->dir_x = tmp_a; + cl->plist->dir_y = tmp_b; + i++; } void -- cgit v1.2.3 From 82f823ceb63d76ce052db3bca74842fe37394eb4 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Thu, 5 Mar 2020 22:01:22 +0100 Subject: fuck --- src/ft_raycasting.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/ft_raycasting.c') diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 0cd4cc6..925711f 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -54,7 +54,9 @@ void tmp_b = cl->plist->dir_y; sprite.spritex = sprite.spritex - (cl->plist->pos_x - 0.5); sprite.spritey = sprite.spritey - (cl->plist->pos_y - 0.5); - printf("[%f] [%f] x [%f] y [%f] [%d]\n", sprite.spritex, sprite.spritey, cl->plist->dir_x, cl->plist->dir_y, i); + /* sprite.transformx */ + /* sprite.transformy */ + printf("[%f] [%f] x [%f] y [%f] [%d]\n", sprite.spritex, sprite.spritey, sprite.transformx, sprite.transformy, i); sprite.invdet = 1.0 / (cl->plist->plane_x * cl->plist->dir_y - cl->plist->dir_x * cl->plist->plane_y); sprite.transformx = sprite.invdet * (cl->plist->dir_y * -- cgit v1.2.3 From 04658c5e9a019917c3f8ffeb84562c328da0a885 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Fri, 6 Mar 2020 18:40:56 +0100 Subject: ils se cachent (mal) --- src/ft_raycasting.c | 56 +---------------------------------------------------- 1 file changed, 1 insertion(+), 55 deletions(-) (limited to 'src/ft_raycasting.c') diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 925711f..2c4b05c 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -17,61 +17,6 @@ #include #include -void - ft_sprite_height(t_cub *cl, t_sprite *sprite) -{ - sprite->spriteheight = abs((int)(cl->wlist->y_size / (sprite->transformy))); - sprite->drawstarty = -sprite->spriteheight / 2 + cl->wlist->y_size / 2; - if (sprite->drawstarty < 0) - sprite->drawstarty = 0; - sprite->drawendy = sprite->spriteheight / 2 + cl->wlist->y_size / 2; - if (sprite->drawendy >= (int)cl->wlist->y_size) - sprite->drawendy = cl->wlist->y_size; -} - -void - ft_sprite_width(t_cub *cl, t_sprite *sprite) -{ - sprite->spritewidth = abs((int)(cl->wlist->x_size / (sprite->transformy))); - sprite->drawstartx = -sprite->spritewidth / 2 + sprite->spritescreenx; - if (sprite->drawstartx < 0) - sprite->drawstartx = 0; - sprite->drawendx = sprite->spritewidth / 2 + sprite->spritescreenx; - if (sprite->drawendx >= (int)cl->wlist->x_size) - sprite->drawendx = cl->wlist->x_size; -} - -void - ft_calc_sprite(t_cub *cl) -{ - t_sprite sprite; - static int i = 0; - float tmp_a; - float tmp_b; - - sprite = cl->sprites; - tmp_a = cl->plist->dir_x; - tmp_b = cl->plist->dir_y; - sprite.spritex = sprite.spritex - (cl->plist->pos_x - 0.5); - sprite.spritey = sprite.spritey - (cl->plist->pos_y - 0.5); - /* sprite.transformx */ - /* sprite.transformy */ - printf("[%f] [%f] x [%f] y [%f] [%d]\n", sprite.spritex, sprite.spritey, sprite.transformx, sprite.transformy, i); - sprite.invdet = 1.0 / (cl->plist->plane_x * - cl->plist->dir_y - cl->plist->dir_x * cl->plist->plane_y); - sprite.transformx = sprite.invdet * (cl->plist->dir_y * - sprite.spritey - cl->plist->dir_x * sprite.spritex); - sprite.transformy = sprite.invdet * - (-cl->plist->plane_y * sprite.spritex + cl->plist->plane_x * sprite.spritey); - sprite.spritescreenx = (int)((cl->wlist->y_size / 2) * - (1 + sprite.transformx / sprite.transformy)); - ft_sprite_height(cl, &sprite); - ft_sprite_width(cl, &sprite); - ft_draw_sprite(cl, &sprite); - cl->plist->dir_x = tmp_a; - cl->plist->dir_y = tmp_b; - i++; -} void ft_calc_tex(t_cub *clist) @@ -142,6 +87,7 @@ ft_castray(t_cub *cl) ft_choose_tex(cl); ft_calc_tex(cl); ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); + cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist; i++; } } -- cgit v1.2.3 From 7d50a78eed9c6cfce3288c471b9f3e6367bfe040 Mon Sep 17 00:00:00 2001 From: salaaad2 Date: Mon, 9 Mar 2020 17:50:45 +0100 Subject: gang --- src/ft_raycasting.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/ft_raycasting.c') diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 2c4b05c..464eb95 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -71,7 +71,12 @@ ft_castray(t_cub *cl) { uint16_t i; t_win *wl; + float *dist_tab; + if (!(dist_tab = malloc(sizeof(float) * cl->wlist->x_size))) + return ; + if (!(cl->rlist.wall_dist_tab = malloc(sizeof(float) * cl->wlist->x_size))) + return ; i = 0; wl = cl->wlist; while (i < wl->x_size) @@ -87,7 +92,8 @@ ft_castray(t_cub *cl) ft_choose_tex(cl); ft_calc_tex(cl); ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); - cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist; + dist_tab[i] = cl->rlist.wall_dist; + cl->rlist.wall_dist_tab = dist_tab; i++; } } -- cgit v1.2.3