resolve wall distorsion and lag
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -18,12 +18,19 @@ static void calcul_img_column(t_game *game, t_rcast *rcast, t_wall *wall)
|
||||
}
|
||||
}
|
||||
|
||||
static void fill_wall_vector(t_rcast *rcast, int height)
|
||||
static void fill_wall_vector(t_rcast *rcast, t_wall *wall)
|
||||
{
|
||||
int height;
|
||||
|
||||
height = wall->height;
|
||||
if (height < 0)
|
||||
height = 0;
|
||||
wall->limit = 0;
|
||||
if (height > rcast->screen_height)
|
||||
{
|
||||
wall->limit = (height - rcast->screen_height) / 2;
|
||||
height = rcast->screen_height;
|
||||
}
|
||||
rcast->wall.vec.start.y = rcast->screen_height / 2 + height / 2;
|
||||
rcast->wall.vec.end.y = rcast->screen_height / 2 - height / 2;
|
||||
}
|
||||
@@ -46,7 +53,7 @@ static void calcul_wall(t_rcast *rcast)
|
||||
if (rcast->wall.delta && rcast->screen_dist)
|
||||
height /= (rcast->wall.delta * rcast->screen_dist);
|
||||
rcast->wall.height = ft_abs(height);
|
||||
fill_wall_vector(rcast, rcast->wall.height);
|
||||
fill_wall_vector(rcast, &rcast->wall);
|
||||
}
|
||||
|
||||
void raycast(t_game *game, t_rcast *rcast)
|
||||
|
||||
Reference in New Issue
Block a user