diff options
author | salaaad2 <arthudurant263@gmail.com> | 2020-02-24 22:20:33 +0100 |
---|---|---|
committer | salaaad2 <arthudurant263@gmail.com> | 2020-02-24 22:20:33 +0100 |
commit | fe145d4c59886b857b0966f8e9b673cfacc0695f (patch) | |
tree | 6f613a668ecd532d185b4b31d7b5fe8122d271de | |
parent | Norme (diff) | |
download | 42-cub3d-fe145d4c59886b857b0966f8e9b673cfacc0695f.tar.gz 42-cub3d-fe145d4c59886b857b0966f8e9b673cfacc0695f.tar.bz2 42-cub3d-fe145d4c59886b857b0966f8e9b673cfacc0695f.tar.xz 42-cub3d-fe145d4c59886b857b0966f8e9b673cfacc0695f.tar.zst 42-cub3d-fe145d4c59886b857b0966f8e9b673cfacc0695f.zip |
found 2 infinit loops hehe
-rw-r--r-- | inc/cub3d.h | 3 | ||||
-rw-r--r-- | map/map_one.cub | 2 | ||||
-rw-r--r-- | src/ft_draw_sprite.c | 47 | ||||
-rw-r--r-- | src/ft_raycasting.c | 50 |
4 files changed, 55 insertions, 47 deletions
diff --git a/inc/cub3d.h b/inc/cub3d.h index 5f1c6f8..c3236a5 100644 --- a/inc/cub3d.h +++ b/inc/cub3d.h @@ -90,6 +90,7 @@ void ft_draw_life_bar(size_t map_w, const int8_t life, t_cub *cl); void ft_music(t_cub *cl); -void ft_draw_sprite(t_cub *cl, int i); +void ft_calc_sprite_norme(t_cub *cl); +void ft_draw_sprite(t_cub *cl); # endif diff --git a/map/map_one.cub b/map/map_one.cub index d135e42..05cb705 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -19,7 +19,7 @@ F 50,190,124 1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 -1 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 1 1 +1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1 diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index 9cd7dae..a3371b4 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -16,38 +16,41 @@ #include <stdio.h> #include <stdlib.h> #include <math.h> - +/* void ft_draw_verline_sprite(t_cub *cl, int x, int y, int tex_y) { 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]; - 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; } - +*/ void - ft_draw_sprite(t_cub *cl, int x) + ft_draw_sprite(t_cub *cl) { - int hor_it; + int itx; + int ity; int d; + int tex_x; int tex_y; - hor_it = cl->sp_list.s_start_y; - while (hor_it < cl->sp_list.s_end_y) + itx = cl->sp_list.s_start_x; + while (itx < cl->sp_list.s_end_x) { - 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++; + tex_x = (int)((itx - (-cl->sp_list.s_w / 2 + cl->sp_list.s_screen_x)) + * cl->tlist[4].img_w / cl->sp_list.s_w); + ity = cl->sp_list.s_start_y; + while (ity < cl->sp_list.s_end_y) + { + d = ity * 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; + if (*(cl->tlist[4].ptr + tex_x + tex_y * cl->tlist[4].sizeline / 4)) + { + /*cl->img.ptr[tex_x * 4 + (cl->img.sizeline * tex_y)] =*/ + /*(char)cl->tlist[4].ptr[cl->tlist[4].tex_x * 4 + 4 **/ + /*cl->tlist[4].img_h * tex_y];*/ + /*puts("qwe");*/ + } + ity++; + } + itx++; } } 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 <libft.h> #include <cub3d.h> #include <stdint.h> +#include <stdio.h> #include <stdlib.h> #include <math.h> 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,11 +35,33 @@ 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) { if (clist->rlist.side == 0) @@ -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++; } |