wip several test to avoid buble effects, one wihtout doubles

This commit is contained in:
hugogogo
2022-04-28 20:27:46 +02:00
parent 285f6f3c55
commit 6640c9e6d3
6 changed files with 44 additions and 53 deletions

View File

@@ -30,67 +30,70 @@
}
// tmp end
static void wall_length(t_rcast *rcast, t_wall *wall)
static void wall_length(t_rcast *rcast)
{
int length;
int len;
wall->pos.start.x = rcast->ray_nb;
wall->pos.end.x = rcast->ray_nb;
rcast->wall.start.x = rcast->ray_nb;
rcast->wall.end.x = rcast->ray_nb;
// len = sqrt(pow(ray->end.x - ray->start.x, 2) + pow(ray->end.y - ray->start.y, 2));
if (rcast->is_x == 1)
{
length = rcast->next_x - rcast->ray_step_x;
len = 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;
len /= ft_abs(rcast->slope_y);
// len = (double)len * (double)rcast->screen_dist.end.y / (double)rcast->slope_x;
// len = rcast->screen_dist * len / (rcast->slope_x);
}
else if (rcast->is_x == 0)
{
length = rcast->next_y - rcast->ray_step_y;
len = 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;
len /= ft_abs(rcast->slope_x);
// len = (double)len * (double)rcast->screen_dist.end.y / (double)rcast->slope_y;
// len = rcast->screen_dist * len / (rcast->slope_y);
}
rcast->ray_len = ft_abs(length);
rcast->ray_len = ft_abs(len);
}
static void wall_height(t_rcast *rcast, t_wall *wall)
static void wall_height(t_rcast *rcast)
{
int height;
height = wall->height - rcast->ray_len;
height = rcast->screen_height * (rcast->hor - rcast->ray_len) / rcast->hor;
if (height < 0)
height = 0;
if (height > rcast->screen_height)
height = rcast->screen_height;
wall->pos.start.y = rcast->screen_height / 2 + height / 2;
wall->pos.end.y = rcast->screen_height / 2 - height / 2;
rcast->wall.start.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_wall *wall)
void draw_column(t_game *game, t_rcast *rcast)
{
t_vec plane;
t_vec plan;
int color;
plane.start.x = rcast->ray_nb;
plane.end.x = rcast->ray_nb;
if (wall->pos.start.y > 0)
plan.start.x = rcast->ray_nb;
plan.end.x = rcast->ray_nb;
if (rcast->wall.start.y > 0)
{
plane.start.y = rcast->screen_height;
plane.end.y = wall->pos.start.y;
draw_line(&game->img, &plane, 0x00FF0000);
plan.start.y = rcast->screen_height;
plan.end.y = rcast->wall.start.y;
draw_line(&game->img, &plan, 0x00FF0000);
}
if (wall->pos.start.y < rcast->screen_height)
if (rcast->wall.start.y < rcast->screen_height)
{
plane.start.y = wall->pos.end.y;
plane.end.y = 0;
draw_line(&game->img, &plane, 0x000000FF);
plan.start.y = rcast->wall.end.y;
plan.end.y = 0;
draw_line(&game->img, &plan, 0x000000FF);
}
color = 0x00FF00FF;
if (rcast->is_x)
color = 0x00EE00EE;
draw_line(&game->img, &wall->pos, color);
draw_line(&game->img, &rcast->wall, color);
}
void raycast(t_game *game, t_rcast *rcast)
@@ -108,9 +111,9 @@ void raycast(t_game *game, t_rcast *rcast)
// tmp end
wall_length(rcast, &game->wall);
wall_height(rcast, &game->wall);
draw_column(game, rcast, &game->wall);
wall_length(rcast);
wall_height(rcast);
draw_column(game, rcast);
(rcast->ray_nb)++;
}
}