resolve wall distorsion and lag

This commit is contained in:
hugogogo
2022-05-03 18:10:41 +02:00
parent f882f57396
commit 9b28e20199
5 changed files with 28 additions and 28 deletions

View File

@@ -51,32 +51,24 @@ static int get_texture(t_img *img, int imgx, int j, int height)
y = (j * img->height) / height;
position = y * img->szl + imgx * (img->bpp / 8);
color = img->data + position;
return (*(int*)color);
return (*(int *)color);
}
static void draw_txt_column(t_img *img, t_rcast *rcast, t_wall *wall, t_img *txt_img)
static void draw_txt_column(t_game *game, t_wall *wall, t_img *txt_img)
{
int color;
int col;
int img_x;
int i;
int j;
int limit;
img_x = (wall->posx * txt_img->width) / rcast->cell;
limit = (wall->height - rcast->screen_height) / 2;
if (limit < 0)
limit = 0;
img_x = (wall->posx * txt_img->width) / game->rcast.cell;
j = wall->limit;
i = 0;
j = 0;
while (i < wall->height - limit)
while (j < wall->height - wall->limit)
{
if (i > limit)
{
color = get_texture(txt_img, img_x, i, wall->height);
draw_pixel(img, wall->vec.start.x, wall->vec.end.y + j, color);
j++;
}
col = get_texture(txt_img, img_x, j, wall->height);
draw_pixel(&game->img, wall->vec.start.x, wall->vec.end.y + i, col);
j++;
i++;
}
}
@@ -85,11 +77,11 @@ void draw_column(t_game *game, t_rcast *rcast, t_wall *wall, t_txt *txt)
{
draw_floor_ceiling(game, rcast, txt);
if (!rcast->is_x && rcast->slope_y > 0)
draw_txt_column(&game->img, rcast, wall, &txt->img_n);
draw_txt_column(game, wall, &txt->img_n);
else if (!rcast->is_x && rcast->slope_y < 0)
draw_txt_column(&game->img, rcast, wall, &txt->img_s);
draw_txt_column(game, wall, &txt->img_s);
else if (rcast->is_x && rcast->slope_x > 0)
draw_txt_column(&game->img, rcast, wall, &txt->img_e);
draw_txt_column(game, wall, &txt->img_e);
else if (rcast->is_x && rcast->slope_x < 0)
draw_txt_column(&game->img, rcast, wall, &txt->img_w);
draw_txt_column(game, wall, &txt->img_w);
}