diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_darken_rgb.c | 16 | ||||
-rw-r--r-- | src/ft_draw_verline.c | 14 | ||||
-rw-r--r-- | src/ft_floor_cast.c | 55 | ||||
-rw-r--r-- | src/ft_init_lists.c | 1 | ||||
-rw-r--r-- | src/ft_init_map.c | 2 | ||||
-rw-r--r-- | src/ft_raycasting.c | 1 | ||||
-rw-r--r-- | src/ft_warp_level.c | 1 |
7 files changed, 83 insertions, 7 deletions
diff --git a/src/ft_darken_rgb.c b/src/ft_darken_rgb.c index 564dfbd..7f5e12a 100644 --- a/src/ft_darken_rgb.c +++ b/src/ft_darken_rgb.c @@ -12,21 +12,23 @@ #include <cub3d.h> #include <stdint.h> -#include <stdio.h> uint32_t ft_darken_ceil(t_rgb rgb, int32_t y, t_cub *cl) { t_rgb darker; + float dist; float calc; darker = rgb; - calc = ((float)(y - (75000.0 / cl->wlist.y_size)) - / (cl->wlist.y_size / 2)); - calc = (calc < 0) ? (0) : (calc); - darker.r *= 1 - calc; - darker.g *= 1 - calc; - darker.b *= 1 - calc; + (void)y; + dist = (cl->rlist.ceil_dist > 0) ? (cl->rlist.ceil_dist) : (0.0001); + calc = dist * 0.4; + calc = (calc >= 255) ? (255) : (calc); + calc = (calc < 1) ? (1) : (calc); + darker.r /= calc; + darker.g /= calc; + darker.b /= calc; return (ft_rgb_to_hex(darker)); } diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index 18f7cfe..6fa0d1e 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -40,6 +40,19 @@ static void } } +#include <stdio.h> +static void + ft_calc_ceil_dist(int32_t y, t_ray *rl, t_cub *cl) +{ + int16_t p; + + p = y - cl->wlist.y_size / 2; + cl->plist.pos_z = 0.5 * cl->wlist.y_size; + rl->ceil_dist = cl->plist.pos_z / p; + rl->ceil_dist = (rl->ceil_dist > 0) ? (rl->ceil_dist) : (-rl->ceil_dist); + printf("%f\n", rl->ceil_dist); +} + int8_t ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2) { @@ -48,6 +61,7 @@ int8_t (y < 0) ? (y = 0) : 0; (y2 < 0) ? (y2 = 0) : 0; + ft_calc_ceil_dist(y, &cl->rlist, cl); ft_draw_ceil(cl, y, x); (cl->rlist.line_h <= 0) ? (cl->rlist.line_h = 1) : 0; while (y < y2) diff --git a/src/ft_floor_cast.c b/src/ft_floor_cast.c new file mode 100644 index 0000000..c82163a --- /dev/null +++ b/src/ft_floor_cast.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_raycasting.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2020/02/14 17:22:57 by rbousset #+# #+# */ +/* Updated: 2020/02/14 17:23:42 by rbousset ### ########lyon.fr */ +/* */ +/* ************************************************************************** */ + +#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 = pl->dir_x - pl->plane_x; + rl->y_ray_dir = pl->dir_y - pl->plane_y; + rl->x_ray_dir_bis = pl->dir_x + pl->plane_x; + rl->y_ray_dir_bis = pl->dir_y + pl->plane_y; + p = y - cl->wlist.y_size / 2; + pl->pos_z = 0.5 * cl->wlist.y_size; + rl->row_dist = pl->pos_z / p; + cl->mlist.x_floor_step = rl->row_dist * + (rl->x_ray_dir_bis - rl->x_ray_dir) / cl->wlist.x_size; + cl->mlist.y_floor_step = rl->row_dist * + (rl->y_ray_dir_bis - rl->y_ray_dir) / cl->wlist.x_size; + rl->floor_x = pl->pos_x + rl->row_dist * rl->x_ray_dir; + rl->floor_y = pl->pos_y + rl->row_dist * rl->y_ray_dir; +} + +void + ft_floor_cast(t_cub *cl) +{ + uint16_t y; + uint16_t x; + + y = 0; + while (y < cl->wlist.y_size) + { + ft_initray(y, &cl->rlist, &cl->plist, cl); + x = 1; + while (x < cl->wlist.x_size) + { + cl->rlist.ceil_x = (int16_t)cl->rlist.floor_x; + cl->rlist.ceil_y = (int16_t)cl->rlist.floor_y; + x++; + } + y++; + } +} diff --git a/src/ft_init_lists.c b/src/ft_init_lists.c index 5bd4d06..e4eb72d 100644 --- a/src/ft_init_lists.c +++ b/src/ft_init_lists.c @@ -35,6 +35,7 @@ static t_player plist.pos_x = 0; plist.pos_y = 0; + plist.pos_z = 0; plist.start_x = 0; plist.start_y = 0; plist.cam_x = 0; diff --git a/src/ft_init_map.c b/src/ft_init_map.c index 1c12189..965bf8e 100644 --- a/src/ft_init_map.c +++ b/src/ft_init_map.c @@ -49,6 +49,8 @@ int8_t mlist->mapl_len = 0; mlist->x_step = 0; mlist->y_step = 0; + mlist->x_floor_step = 0; + mlist->y_floor_step = 0; mlist->line_chk = 0; mlist->map_start = 0; mlist->isspawn = 0; diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 50bdbf9..5bb3649 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -112,6 +112,7 @@ void i = 0; wl = &cl->wlist; + /* ft_floor_cast(cl); */ while (i < wl->x_size) { ft_initray(cl, i); diff --git a/src/ft_warp_level.c b/src/ft_warp_level.c index 37789a5..09fbc7c 100644 --- a/src/ft_warp_level.c +++ b/src/ft_warp_level.c @@ -45,6 +45,7 @@ static void cl->plist.pos_x = 0; cl->plist.pos_y = 0; + cl->plist.pos_z = 0; cl->plist.start_x = 0; cl->plist.start_y = 0; cl->plist.cam_x = 0; |