diff --git a/headers/cube3d_macro.h b/headers/cube3d_macro.h index 1f4d472..477cce1 100644 --- a/headers/cube3d_macro.h +++ b/headers/cube3d_macro.h @@ -17,6 +17,8 @@ # define SCREEN_FOCAL 90 /* size of a cell on the map */ # define CELL 20 +/* height of a wall without perpectiv */ +# define WALL_HEIGHT 300 /* * keys macro diff --git a/headers/cube3d_struct.h b/headers/cube3d_struct.h index 81cf47d..012c6d6 100644 --- a/headers/cube3d_struct.h +++ b/headers/cube3d_struct.h @@ -36,6 +36,7 @@ typedef struct s_rcast t_vec screen_size; t_vec ray; t_vec wall; + int wall_height; int screen_width; int screen_height; int cell; diff --git a/srcs/draw/raycast.c b/srcs/draw/raycast.c index 2115a99..26b0472 100644 --- a/srcs/draw/raycast.c +++ b/srcs/draw/raycast.c @@ -32,42 +32,47 @@ static void calcul_wall(t_rcast *rcast) { + int length; int height; rcast->wall.start.x = rcast->ray_nb; rcast->wall.end.x = rcast->ray_nb; if (rcast->is_x == 1 && rcast->slope_y != 0) - height = (rcast->next_x - rcast->ray_step_x) / ft_abs(rcast->slope_y); + length = (rcast->next_x - rcast->ray_step_x) / ft_abs(rcast->slope_y); if (rcast->is_x == 0 && rcast->slope_x != 0) - height = (rcast->next_y - rcast->ray_step_y) / ft_abs(rcast->slope_x); + length = (rcast->next_y - rcast->ray_step_y) / ft_abs(rcast->slope_x); + height = rcast->wall_height - length; + if (height < 0) + height = 0; if (height > rcast->screen_height) height = rcast->screen_height; rcast->wall.start.y = rcast->screen_height / 2 + height / 2; - rcast->wall.end.y = rcast->screen_height / 2 - height / 2; + rcast->wall.end.y = rcast->screen_height / 2 - height / 2; } void draw_column(t_game *game, t_rcast *rcast) { - t_vec floor; - t_vec ceilling; + t_vec plane; + int color; + plane.start.x = rcast->ray_nb; + plane.end.x = rcast->ray_nb; if (rcast->wall.start.y > 0) { - floor.start.x = rcast->ray_nb; - floor.end.x = rcast->ray_nb; - floor.start.y = rcast->screen_height; - floor.end.y = rcast->wall.start.y; - draw_line(&game->img, &floor, 0x00FF0000); + plane.start.y = rcast->screen_height; + plane.end.y = rcast->wall.start.y; + draw_line(&game->img, &plane, 0x00FF0000); } if (rcast->wall.start.y < rcast->screen_height) { - ceilling.start.x = rcast->ray_nb; - ceilling.end.x = rcast->ray_nb; - ceilling.start.y = rcast->wall.end.y; - ceilling.end.y = 0; - draw_line(&game->img, &ceilling, 0x00FF0000); + plane.start.y = rcast->wall.end.y; + plane.end.y = 0; + draw_line(&game->img, &plane, 0x000000FF); } - draw_line(&game->img, &rcast->wall, 0x00FF00FF); + color = 0x00FF00FF; + if (rcast->is_x) + color = 0x00EE00EE; + draw_line(&game->img, &rcast->wall, color); } void raycast(t_game *game, t_rcast *rcast) diff --git a/srcs/init/init_struct.c b/srcs/init/init_struct.c index d18d01f..5546c5a 100644 --- a/srcs/init/init_struct.c +++ b/srcs/init/init_struct.c @@ -70,6 +70,7 @@ static void init_raycast(t_rcast *rcast) dist = cos(dist) * ((SCREEN_WIDTH / 2) / sin(dist)); rcast->screen_width = SCREEN_WIDTH; rcast->screen_height = SCREEN_HEIGHT; + rcast->wall_height = WALL_HEIGHT; // screen dist rcast->screen_dist.start.x = 0; rcast->screen_dist.start.y = 0;