diff options
Diffstat (limited to '')
-rw-r--r-- | inc/cub3d_structs.h | 4 | ||||
-rw-r--r-- | map/map_one.cub | 3 | ||||
-rw-r--r-- | src/ft_draw_textures.c | 8 | ||||
-rw-r--r-- | src/ft_draw_verline.c | 2 | ||||
-rw-r--r-- | src/ft_raycasting.c | 16 |
5 files changed, 24 insertions, 9 deletions
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h index 83b38a7..908b007 100644 --- a/inc/cub3d_structs.h +++ b/inc/cub3d_structs.h @@ -36,8 +36,6 @@ typedef struct s_img int endian; int img_w; int img_h; - int tex_x; - int tex_y; } t_img; typedef struct s_rgb @@ -85,6 +83,8 @@ typedef struct s_ray size_t sqy; uint8_t hit; double wall_hit_x; + int tex_x; + int tex_y; } t_ray; typedef struct s_map diff --git a/map/map_one.cub b/map/map_one.cub index da39c42..fec57b0 100644 --- a/map/map_one.cub +++ b/map/map_one.cub @@ -15,7 +15,8 @@ F 150,150,124 1 0 1 1 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 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 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 +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 diff --git a/src/ft_draw_textures.c b/src/ft_draw_textures.c index 5d02036..46e51d7 100644 --- a/src/ft_draw_textures.c +++ b/src/ft_draw_textures.c @@ -24,11 +24,11 @@ void ft_choose_tex(t_cub *clist) { if (clist->rlist.side == 0 && clist->rlist.x_ray_dir < 0) - clist->w_side = 0; - else if (clist->rlist.side == 0 && clist->rlist.x_ray_dir > 0) clist->w_side = 1; + else if (clist->rlist.side == 0 && clist->rlist.x_ray_dir > 0) + clist->w_side = 0; else if (clist->rlist.side == 1 && clist->rlist.y_ray_dir > 0) - clist->w_side = 2; - else clist->w_side = 3; + else + clist->w_side = 2; } diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index bcddbc7..0fad33a 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -60,7 +60,7 @@ int8_t ft_choose_tex(cl); while (y <= y2) { - *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = 0x0000ffaa; + *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = (cl->rlist.side) ? 0x0000eeaa : 0x0000ffaa; y++; } ft_draw_floor(cl, y, x); diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index e1d3223..ff73893 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -10,18 +10,29 @@ /* */ /* ************************************************************************** */ +#include <libft.h> #include <cub3d.h> #include <stdint.h> +#include <math.h> void ft_calc_tex(t_cub *clist) { - if (clist->rlist.side == 1) + if (clist->rlist.side == 0) clist->rlist.wall_hit_x = clist->plist->pos_y + clist->rlist.wall_dist * clist->rlist.y_ray_dir; else clist->rlist.wall_hit_x = clist->plist->pos_x + clist->rlist.wall_dist * clist->rlist.x_ray_dir; + clist->rlist.wall_hit_x -= floor(clist->rlist.wall_hit_x); + clist->rlist.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) + clist->rlist.tex_x = clist->tlist[clist->w_side].img_w + - clist->rlist.tex_x - 1; + if (clist->rlist.side == 1 && clist->rlist.y_ray_dir < 0) + clist->rlist.tex_x = clist->tlist[clist->w_side].img_w + - clist->rlist.tex_x - 1; } static void @@ -43,8 +54,10 @@ static void cl->rlist.sqy = (int16_t)cl->rlist.y_ray_pos; ft_detect(cl); 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; + } else cl->rlist.wall_dist = (cl->rlist.sqy - cl->rlist.y_ray_pos + (1 - cl->mlist->y_step) / 2) / cl->rlist.y_ray_dir; @@ -58,6 +71,7 @@ void i = 0; wl = cl->wlist; + ft_wall_tex_init(cl); while (i < wl->x_size) { ft_initray(cl, i); |