aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsalaaad2 <arthurdurant263@gmail.com>2020-02-17 18:52:58 +0100
committersalaaad2 <arthurdurant263@gmail.com>2020-02-17 18:52:58 +0100
commit84b6ca845a07421b10b527f3c18a49eabd8fb2f9 (patch)
treec136d58b09353c8efcad74a256f5f7db1c949c0a
parentadd shadows and beginning of wall coordinate hit detection (diff)
download42-cub3d-84b6ca845a07421b10b527f3c18a49eabd8fb2f9.tar.gz
42-cub3d-84b6ca845a07421b10b527f3c18a49eabd8fb2f9.tar.bz2
42-cub3d-84b6ca845a07421b10b527f3c18a49eabd8fb2f9.tar.xz
42-cub3d-84b6ca845a07421b10b527f3c18a49eabd8fb2f9.tar.zst
42-cub3d-84b6ca845a07421b10b527f3c18a49eabd8fb2f9.zip
have correct width and hit zone, supposedly not much left
-rw-r--r--inc/cub3d_structs.h4
-rw-r--r--src/ft_raycasting.c4
-rw-r--r--src/ft_tex_init.c10
3 files changed, 5 insertions, 13 deletions
diff --git a/inc/cub3d_structs.h b/inc/cub3d_structs.h
index 38472a6..00f85d7 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/src/ft_raycasting.c b/src/ft_raycasting.c
index 7ce45d5..26a3ec9 100644
--- a/src/ft_raycasting.c
+++ b/src/ft_raycasting.c
@@ -26,7 +26,8 @@ void
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 * clist->tlist[clist->w_side].img_w);*/
+ clist->rlist.tex_x = (clist->rlist.wall_hit_x * (double)clist->tlist[clist->w_side].img_w);
+ printf("wall_hit_x : %f\ntex_x : %d\nimg_w : %d\n", clist->rlist.wall_hit_x, clist->rlist.tex_x, clist->tlist[clist->w_side].img_w);
}
static void
@@ -65,6 +66,7 @@ void
i = 0;
wl = cl->wlist;
+ ft_wall_tex_init(cl);
while (i < wl->x_size)
{
ft_initray(cl, i);
diff --git a/src/ft_tex_init.c b/src/ft_tex_init.c
index 166f431..724877f 100644
--- a/src/ft_tex_init.c
+++ b/src/ft_tex_init.c
@@ -23,15 +23,6 @@
** 4 : sprite
*/
-void ft_puttex(t_cub *cl)
-{
- int i;
-
- i = 0;
- while (i < cl->tlist[0].img_w)
- i += 4;
-}
-
void ft_wall_tex_init(t_cub *cl)
{
cl->tlist[0].img = mlx_xpm_file_to_image(cl->wlist->wlx,
@@ -54,5 +45,4 @@ void ft_wall_tex_init(t_cub *cl)
cl->mlist->sprite_path, &cl->tlist[4].img_w, &cl->tlist[4].img_h);
cl->tlist[4].ptr = mlx_get_data_addr(cl->tlist[4].img,
&cl->tlist[4].bpp, &cl->tlist[4].sizeline, &cl->tlist[4].endian);
- ft_puttex(cl);
}