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

@@ -102,6 +102,7 @@ void draw_line(t_img *img, t_vec *vec, int color)
draw_square(game, pos, 0x00999900, 0x00330033, cell, 1);
}
/*
static void draw_screen(t_game *game, t_rcast *rcast)
{
t_vec screen;
@@ -122,6 +123,7 @@ void draw_line(t_img *img, t_vec *vec, int color)
rotate(&(game->plr), &(screen.end));
draw_line(&game->map_img, &screen, 0x00FFFFFF);
}
*/
// tmp end
void draw(t_game *game)
@@ -133,7 +135,7 @@ void draw(t_game *game)
raycast(game, &(game->rcast));
// tmp, to draw map
draw_screen(game, &(game->rcast));
// draw_screen(game, &(game->rcast));
mlx_put_image_to_window(game->mlx_ptr, game->map_win.ptr, game->map_img.ptr, 0, SCREEN_HEIGHT);
// tmp end

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)++;
}
}

View File

@@ -68,13 +68,10 @@ static void init_raycast(t_rcast *rcast)
dist = (SCREEN_FOCAL / 2) * M_PI / 180;
dist = cos(dist) * ((SCREEN_WIDTH / 2) / sin(dist));
rcast->screen_dist = dist;
rcast->screen_width = SCREEN_WIDTH;
rcast->screen_height = SCREEN_HEIGHT;
// screen dist
rcast->screen_dist.start.x = 0;
rcast->screen_dist.start.y = 0;
rcast->screen_dist.end.x = 0;
rcast->screen_dist.end.y = -dist;
rcast->hor = HORIZON;
// screen size
rcast->screen_size.start.x = -SCREEN_WIDTH / 2;
rcast->screen_size.start.y = -dist;
@@ -132,6 +129,5 @@ t_game *init_game(void)
// raycasting
init_raycast(&(game->rcast));
game->rcast.cell = game->map.cell;
game->wall.height = WALL_HEIGHT;
return (game);
}