diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_darken_rgb.c | 26 | ||||
-rw-r--r-- | src/ft_draw_verline.c | 20 | ||||
-rw-r--r-- | src/ft_floor_cast.c | 37 | ||||
-rw-r--r-- | src/ft_key_loop.c | 3 | ||||
-rw-r--r-- | src/ft_raycasting.c | 1 |
5 files changed, 35 insertions, 52 deletions
diff --git a/src/ft_darken_rgb.c b/src/ft_darken_rgb.c index 7f5e12a..5edfd89 100644 --- a/src/ft_darken_rgb.c +++ b/src/ft_darken_rgb.c @@ -12,23 +12,21 @@ #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; - (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; + 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; return (ft_rgb_to_hex(darker)); } @@ -38,9 +36,13 @@ uint32_t t_rgb darker; float calc; - calc = ((float)(y + (75000.0 / cl->wlist.y_size)) - / (cl->wlist.y_size / 2)) - 1.0; - calc = (calc < 0) ? (0) : (calc); + /* calc = ((float)(y + (75000.0 / cl->wlist.y_size)) */ + /* / (cl->wlist.y_size / 2)) - 1.0; */ + /* calc = (calc < 0) ? (0) : (calc); */ + (void)y; + calc = (cl->rlist.row_dist * 0.4); + calc = (calc >= 255) ? (255) : (calc); + calc = (calc < 1) ? (1) : (calc); darker = rgb; darker.r *= calc; darker.g *= calc; diff --git a/src/ft_draw_verline.c b/src/ft_draw_verline.c index 6fa0d1e..d32ac38 100644 --- a/src/ft_draw_verline.c +++ b/src/ft_draw_verline.c @@ -33,6 +33,7 @@ static void i = 0; while (i <= y) { + ft_floor_cast(i, cl); *(int*)(cl->img.ptr + (x * 4 + (i * cl->img.sizeline))) = ft_darken_ceil(cl->c_rgb, i, cl); @@ -40,18 +41,14 @@ static void } } -#include <stdio.h> -static void - ft_calc_ceil_dist(int32_t y, t_ray *rl, t_cub *cl) -{ - int16_t p; +/* #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); -} +/* printf("%f\n", rl->ceil_dist); */ +/* } */ int8_t ft_draw_verline(t_cub *cl, int32_t x, int32_t y, int32_t y2) @@ -61,7 +58,6 @@ 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 index c82163a..482ee8a 100644 --- a/src/ft_floor_cast.c +++ b/src/ft_floor_cast.c @@ -18,38 +18,23 @@ static void { 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; + 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; - 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; + (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_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; + (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(t_cub *cl) + ft_floor_cast(uint16_t y, 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++; - } + cl->plist.pos_z = 0.5 * cl->wlist.y_size; + ft_initray(y, &cl->rlist, &cl->plist, cl); } diff --git a/src/ft_key_loop.c b/src/ft_key_loop.c index e2e2b5c..1d463bc 100644 --- a/src/ft_key_loop.c +++ b/src/ft_key_loop.c @@ -53,7 +53,8 @@ static void pl = &cl->plist; x = ft_find_x(key, pl); y = ft_find_y(key, pl); - if (cl->mlist.map[y][x] == '1' || cl->mlist.map[y][x] == '2') + if (ft_ischarset(FT_CHRST_COLLISION, cl->mlist.map[y][x]) || + cl->mlist.map[y][x] == '\0') { pl->pos_y = old_y; pl->pos_x = old_x; diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 5bb3649..50bdbf9 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -112,7 +112,6 @@ void i = 0; wl = &cl->wlist; - /* ft_floor_cast(cl); */ while (i < wl->x_size) { ft_initray(cl, i); |