add struct wall
This commit is contained in:
@@ -30,65 +30,67 @@
|
||||
}
|
||||
// tmp end
|
||||
|
||||
static void wall_length(t_rcast *rcast)
|
||||
static void wall_length(t_rcast *rcast, t_wall *wall)
|
||||
{
|
||||
int length;
|
||||
|
||||
rcast->wall.start.x = rcast->ray_nb;
|
||||
rcast->wall.end.x = rcast->ray_nb;
|
||||
wall->pos.start.x = rcast->ray_nb;
|
||||
wall->pos.end.x = rcast->ray_nb;
|
||||
if (rcast->is_x == 1)
|
||||
{
|
||||
length = rcast->next_x - rcast->ray_step_x;
|
||||
if (rcast->slope_y)
|
||||
length /= ft_abs(rcast->slope_y);
|
||||
// length = (double)length * (double)rcast->screen_dist.end.y / (double)rcast->slope_x;
|
||||
length = (double)length * (double)rcast->screen_dist.end.y / (double)rcast->slope_x;
|
||||
}
|
||||
else if (rcast->is_x == 0)
|
||||
{
|
||||
length = rcast->next_y - rcast->ray_step_y;
|
||||
if (rcast->slope_x)
|
||||
length /= ft_abs(rcast->slope_x);
|
||||
// length = (double)length * (double)rcast->screen_dist.end.y / (double)rcast->slope_y;
|
||||
length = (double)length * (double)rcast->screen_dist.end.y / (double)rcast->slope_y;
|
||||
}
|
||||
rcast->ray_len = ft_abs(length);
|
||||
}
|
||||
|
||||
static void wall_height(t_rcast *rcast)
|
||||
static void wall_height(t_rcast *rcast, t_wall *wall)
|
||||
{
|
||||
int height;
|
||||
|
||||
height = rcast->wall_height - rcast->ray_len;
|
||||
height = wall->height - rcast->ray_len;
|
||||
|
||||
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;
|
||||
|
||||
wall->pos.start.y = rcast->screen_height / 2 + height / 2;
|
||||
wall->pos.end.y = rcast->screen_height / 2 - height / 2;
|
||||
}
|
||||
|
||||
void draw_column(t_game *game, t_rcast *rcast)
|
||||
void draw_column(t_game *game, t_rcast *rcast, t_wall *wall)
|
||||
{
|
||||
t_vec plane;
|
||||
int color;
|
||||
|
||||
plane.start.x = rcast->ray_nb;
|
||||
plane.end.x = rcast->ray_nb;
|
||||
if (rcast->wall.start.y > 0)
|
||||
if (wall->pos.start.y > 0)
|
||||
{
|
||||
plane.start.y = rcast->screen_height;
|
||||
plane.end.y = rcast->wall.start.y;
|
||||
plane.end.y = wall->pos.start.y;
|
||||
draw_line(&game->img, &plane, 0x00FF0000);
|
||||
}
|
||||
if (rcast->wall.start.y < rcast->screen_height)
|
||||
if (wall->pos.start.y < rcast->screen_height)
|
||||
{
|
||||
plane.start.y = rcast->wall.end.y;
|
||||
plane.start.y = wall->pos.end.y;
|
||||
plane.end.y = 0;
|
||||
draw_line(&game->img, &plane, 0x000000FF);
|
||||
}
|
||||
color = 0x00FF00FF;
|
||||
if (rcast->is_x)
|
||||
color = 0x00EE00EE;
|
||||
draw_line(&game->img, &rcast->wall, color);
|
||||
draw_line(&game->img, &wall->pos, color);
|
||||
}
|
||||
|
||||
void raycast(t_game *game, t_rcast *rcast)
|
||||
@@ -106,15 +108,9 @@ void raycast(t_game *game, t_rcast *rcast)
|
||||
// tmp end
|
||||
|
||||
|
||||
wall_length(rcast);
|
||||
wall_height(rcast);
|
||||
draw_column(game, rcast);
|
||||
wall_length(rcast, &game->wall);
|
||||
wall_height(rcast, &game->wall);
|
||||
draw_column(game, rcast, &game->wall);
|
||||
(rcast->ray_nb)++;
|
||||
|
||||
// tmp, to draw the map
|
||||
if (rcast->tmp)
|
||||
printf("\n");
|
||||
// tmp end
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,6 @@ 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;
|
||||
@@ -133,5 +132,6 @@ t_game *init_game(void)
|
||||
// raycasting
|
||||
init_raycast(&(game->rcast));
|
||||
game->rcast.cell = game->map.cell;
|
||||
game->wall.height = WALL_HEIGHT;
|
||||
return (game);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user