wall grows proportionally

This commit is contained in:
hugogogo
2022-04-25 09:13:10 +02:00
parent 03f61d989b
commit 0d9e5879c0
4 changed files with 25 additions and 16 deletions

View File

@@ -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)

View File

@@ -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;