diff options
Diffstat (limited to '')
-rw-r--r-- | src/ft_floor_cast.c | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c index 482ee8a..9077b9b 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -13,28 +13,32 @@ #include <cub3d.h> #include <stdint.h> -static void - ft_initray(uint16_t y, t_ray *rl, t_player *pl, t_cub *cl) -{ - int16_t p; - - rl->x_ray_dir_f = pl->dir_x - pl->plane_x; - rl->y_ray_dir_f = pl->dir_y - pl->plane_y; - rl->x_ray_dir_f_bis = pl->dir_x + pl->plane_x; - rl->y_ray_dir_f_bis = pl->dir_y + pl->plane_y; - p = y - cl->wlist.y_size / 2; - rl->row_dist = pl->pos_z / p; - cl->mlist.x_floor_step = rl->row_dist * - (rl->x_ray_dir_f_bis - rl->x_ray_dir_f) / cl->wlist.x_size; - cl->mlist.y_floor_step = rl->row_dist * - (rl->y_ray_dir_f_bis - rl->y_ray_dir_f) / cl->wlist.x_size; - rl->floor_x = pl->pos_x + rl->row_dist * rl->x_ray_dir_f; - rl->floor_y = pl->pos_y + rl->row_dist * rl->y_ray_dir_f; -} - void - ft_floor_cast(uint16_t y, t_cub *cl) + ft_floor_cast(t_cub *cl) { - cl->plist.pos_z = 0.5 * cl->wlist.y_size; - ft_initray(y, &cl->rlist, &cl->plist, cl); + t_ray *rl; + const uint32_t map_x = (uint32_t)&cl->plist.pos_x; + const uint32_t map_y = (uint32_t)&cl->plist.pos_y; + + rl = &cl->rlist; + if (rl->side == 0 && rl->x_ray_dir > 0) + { + rl->floor_x_wall = (double)map_x; + rl->floor_y_wall = (double)map_y + rl->wall_hit_x; + } + else if (rl->side == 0 && rl->x_ray_dir < 0) + { + rl->floor_x_wall = (double)map_x + 1.0; + rl->floor_y_wall = (double)map_y + rl->wall_hit_x; + } + else if (rl->side == 1 && rl->y_ray_dir > 0) + { + rl->floor_x_wall = (double)map_x + rl->wall_hit_x; + rl->floor_y_wall = (double)map_y; + } + else + { + rl->floor_x_wall = (double)map_x + rl->wall_hit_x; + rl->floor_y_wall = (double)map_y + 1.0; + } } |