/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_floor_cast.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: rbousset +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/14 17:22:57 by rbousset #+# #+# */ /* Updated: 2020/02/14 17:23:42 by rbousset ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include static void ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x) { *(int*)(cl->img.ptr + (x * 4 + (y * cl->img.sizeline))) = ft_darken(rgb, cl); } static void ft_draw_extra_tex(uint8_t tid, uint16_t y, uint16_t x, t_cub *cl) { float dist; float calc; if ((dist = cl->rlist.row_dist) <= 0) dist = 0.0001; calc = (dist * 0.1 * cl->mlist.darklvl); calc = (calc >= 255) ? (255) : (calc); calc = (calc < 1) ? (1) : (calc); calc = (cl->mlist.darklvl > 0) ? (calc) : (1); cl->img.ptr[x * 4 + (cl->img.sizeline * y)] = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y] / calc; cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 1] = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 1] / calc; cl->img.ptr[x * 4 + (cl->img.sizeline * y) + 2] = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x * 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 2] / calc; cl->img.ptr[x * 4 + cl->wlist.x_size * y + 3] = (char)0; } static void ft_set_tex_xy(uint8_t tid, t_ray *rl, t_cub *cl) { cl->tlist[tid].tex_y = (int32_t)(cl->tlist[tid].img_w * (rl->x_floor - rl->x_cell)) % (cl->tlist[tid].img_w); cl->tlist[tid].tex_x = (int32_t)(cl->tlist[tid].img_h * (rl->y_floor - rl->y_cell)) % (cl->tlist[tid].img_h); cl->tlist[tid].tex_x = (cl->tlist[tid].tex_x > 0) ? (cl->tlist[tid].tex_x) : (-cl->tlist[tid].tex_x); cl->tlist[tid].tex_y = (cl->tlist[tid].tex_y > 0) ? (cl->tlist[tid].tex_y) : (-cl->tlist[tid].tex_y); } 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); if (cl->mlist.isftex) { ft_set_tex_xy(6, rl, cl); } if (cl->mlist.isctex) { ft_set_tex_xy(7, rl, cl); } if (cl->mlist.isftex) ft_draw_extra_tex(6, y, x, cl); else ft_draw_plain_horizontal(cl->f_rgb, cl, y, x); if (cl->mlist.isctex && !cl->mlist.isskybox) ft_draw_extra_tex(7, cl->wlist.y_size - y - 1, x, cl); else if (!cl->mlist.isctex && !cl->mlist.isskybox) ft_draw_plain_horizontal(cl->c_rgb, cl, cl->wlist.y_size - y - 1, x); } void ft_floor_cast(t_cub *cl) { t_ray *rl; uint16_t x; uint16_t y; rl = &cl->rlist; y = (cl->wlist.y_size / 2) + 1; while (++y < cl->wlist.y_size) { ft_floor_cast_inits(y, rl, cl); x = -1; while (++x < cl->wlist.x_size) { if (cl->rlist.wall_bz[x] <= y) { ft_floor_cast_loop(y, x, rl, cl); } rl->x_floor += cl->mlist.x_floor_step; rl->y_floor += cl->mlist.y_floor_step; } } }