diff options
author | Rudy Bousset <rbousset@z2r4p3.le-101.fr> | 2020-02-17 20:49:12 +0100 |
---|---|---|
committer | Rudy Bousset <rbousset@z2r4p3.le-101.fr> | 2020-02-17 20:49:12 +0100 |
commit | aa092dbabd6b1e66b8b52e7ecfc897f7c23be37a (patch) | |
tree | 098ad2f761c5f8c67bfa99c1111639aa96b7c0eb /src/ft_raycasting.c | |
parent | sex (diff) | |
parent | Read to merge (diff) | |
download | 42-cub3d-aa092dbabd6b1e66b8b52e7ecfc897f7c23be37a.tar.gz 42-cub3d-aa092dbabd6b1e66b8b52e7ecfc897f7c23be37a.tar.bz2 42-cub3d-aa092dbabd6b1e66b8b52e7ecfc897f7c23be37a.tar.xz 42-cub3d-aa092dbabd6b1e66b8b52e7ecfc897f7c23be37a.tar.zst 42-cub3d-aa092dbabd6b1e66b8b52e7ecfc897f7c23be37a.zip |
Merge branch 'textures_continued'
Diffstat (limited to 'src/ft_raycasting.c')
-rw-r--r-- | src/ft_raycasting.c | 16 |
1 files changed, 15 insertions, 1 deletions
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); |