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

@@ -27,8 +27,8 @@ SRCS += memorybook.c \
memorybook_utils.c memorybook_utils.c
# init/ # init/
SRCS += init_struct.c \ SRCS += init_struct.c \
init_game.c \ init_textures.c \
init_textures.c init_game.c
# gnl/ # gnl/
SRCS += get_next_line.c \ SRCS += get_next_line.c \
get_next_line_utils.c get_next_line_utils.c
@@ -79,7 +79,7 @@ RM_OBJS = rm -rf $(D_OBJS)
# flags # flags
CFLAGS = -Wall -Wextra -Werror $(INCLUDES) CFLAGS = -Wall -Wextra -Werror $(INCLUDES)
CFLAGS += -g3 CFLAGS += -g3
LFLAGS = -L$(D_LFT) -lft LFLAGS = -L$(D_LFT) -lft
LFLAGS += -L$(D_LMLX) -lm -lmlx -lXext -lX11 LFLAGS += -L$(D_LMLX) -lm -lmlx -lXext -lX11

View File

@@ -34,6 +34,7 @@ typedef struct s_wall
{ {
t_vec vec; t_vec vec;
int height; int height;
int limit;
int delta; int delta;
int posx; int posx;
int imgx; int imgx;

View File

@@ -8,10 +8,10 @@ F 220 , 100, 30
C 225 , 30 , 0 C 225 , 30 , 0
1111111111111111111111111111 1111111111111111111111111111
1000000000000000011100000001 1000000000000000N11100000001
1111000000000000100000110001 1111000000000000100000110001
1111001000000000000110000111 1111001000000000000110000111
100000000N000000010101000001 1000000000000000010101000001
1111110000000000000000001111 1111110000000000000000001111
1000000000000000000000000001 1000000000000000000000000001
1000000000000000000000000001 1000000000000000000000000001

View File

@@ -51,32 +51,24 @@ static int get_texture(t_img *img, int imgx, int j, int height)
y = (j * img->height) / height; y = (j * img->height) / height;
position = y * img->szl + imgx * (img->bpp / 8); position = y * img->szl + imgx * (img->bpp / 8);
color = img->data + position; 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 col;
int color;
int img_x; int img_x;
int i; int i;
int j; int j;
int limit;
img_x = (wall->posx * txt_img->width) / rcast->cell; img_x = (wall->posx * txt_img->width) / game->rcast.cell;
limit = (wall->height - rcast->screen_height) / 2; j = wall->limit;
if (limit < 0)
limit = 0;
i = 0; i = 0;
j = 0; while (j < wall->height - wall->limit)
while (i < wall->height - limit)
{ {
if (i > limit) col = get_texture(txt_img, img_x, j, wall->height);
{ draw_pixel(&game->img, wall->vec.start.x, wall->vec.end.y + i, col);
color = get_texture(txt_img, img_x, i, wall->height); j++;
draw_pixel(img, wall->vec.start.x, wall->vec.end.y + j, color);
j++;
}
i++; 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); draw_floor_ceiling(game, rcast, txt);
if (!rcast->is_x && rcast->slope_y > 0) 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) 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) 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) 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);
} }

View File

@@ -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) if (height < 0)
height = 0; height = 0;
wall->limit = 0;
if (height > rcast->screen_height) if (height > rcast->screen_height)
{
wall->limit = (height - rcast->screen_height) / 2;
height = rcast->screen_height; height = rcast->screen_height;
}
rcast->wall.vec.start.y = rcast->screen_height / 2 + height / 2; rcast->wall.vec.start.y = rcast->screen_height / 2 + height / 2;
rcast->wall.vec.end.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) if (rcast->wall.delta && rcast->screen_dist)
height /= (rcast->wall.delta * rcast->screen_dist); height /= (rcast->wall.delta * rcast->screen_dist);
rcast->wall.height = ft_abs(height); 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) void raycast(t_game *game, t_rcast *rcast)