From 088caacd77c673fe9e18a416aebe70172bf50da8 Mon Sep 17 00:00:00 2001 From: JozanLeClerc Date: Mon, 9 Mar 2020 00:46:44 +0100 Subject: FeelsAlmostGoodMan --- src/ft_floor_cast.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index 1d98e03..9b8ab59 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -13,10 +13,40 @@ #include #include +static void + ft_put_floor_tex(uint16_t y, uint16_t x, t_cub *cl) +{ + cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = + (uint8_t)cl->tlist[6].ptr[cl->tlist[6].tex_x * 4 + 4 * + cl->tlist[6].img_h * cl->tlist[6].tex_y]; + cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = + (uint8_t)cl->tlist[6].ptr[cl->tlist[6].tex_x * 4 + 4 * + cl->tlist[6].img_h * cl->tlist[6].tex_y + 1]; + cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = + (uint8_t)cl->tlist[6].ptr[cl->tlist[6].tex_x * 4 + 4 * + cl->tlist[6].img_h * cl->tlist[6].tex_y + 2]; + cl->img.ptr[x * 4 + cl->wlist.x_size * y + 3] = (char)0; +} + +static void + ft_floor_cast_loop(uint16_t y, uint16_t x, t_ray *rl, t_cub *cl) +{ + rl->x_cell = (int32_t)(rl->x_floor); + rl->y_cell = (int32_t)(rl->y_floor); + cl->tlist[6].tex_x = (int32_t)(cl->tlist[6].img_w + * (rl->x_floor - rl->x_cell)) & (cl->tlist[6].img_w - 1); + cl->tlist[6].tex_y = (int32_t)(cl->tlist[6].img_h + * (rl->y_floor - rl->y_cell)) & (cl->tlist[6].img_h - 1); + rl->x_floor += cl->mlist.x_floor_step; + rl->y_floor += cl->mlist.y_floor_step; + ft_put_floor_tex(y, x, cl); +} + void ft_floor_cast(uint16_t y, t_cub *cl) { - t_ray *rl; + t_ray *rl; + uint16_t x; rl = &cl->rlist; rl->x_f_ray_dir = cl->plist.dir_x - cl->plist.plane_x; @@ -25,4 +55,16 @@ void rl->y_f_ray_dir_bis = cl->plist.dir_y + cl->plist.plane_y; rl->p = y - cl->wlist.y_size / 2; cl->plist.pos_z = 0.5 * cl->wlist.y_size; + rl->row_dist = cl->plist.pos_z / rl->p; + cl->mlist.x_floor_step = rl->row_dist * + (rl->x_f_ray_dir_bis - rl->x_f_ray_dir) / cl->wlist.x_size; + cl->mlist.y_floor_step = rl->row_dist * + (rl->y_f_ray_dir_bis - rl->y_f_ray_dir) / cl->wlist.x_size; + rl->x_floor = cl->plist.pos_x + rl->row_dist * rl->x_f_ray_dir; + rl->y_floor = cl->plist.pos_y + rl->row_dist * rl->y_f_ray_dir; + x = 0; + while (++x < cl->wlist.x_size) + { + ft_floor_cast_loop(y, x, rl, cl); + } } -- cgit v1.2.3