diff options
author | salaaad2 <arthurdurant263@gmail.com> | 2020-03-09 17:50:45 +0100 |
---|---|---|
committer | salaaad2 <arthurdurant263@gmail.com> | 2020-03-09 17:50:45 +0100 |
commit | 7d50a78eed9c6cfce3288c471b9f3e6367bfe040 (patch) | |
tree | dc53123db1690b93a1b2e00c842ff16251662937 /src | |
parent | sprites ont des jambes (diff) | |
download | 42-cub3d-7d50a78eed9c6cfce3288c471b9f3e6367bfe040.tar.gz 42-cub3d-7d50a78eed9c6cfce3288c471b9f3e6367bfe040.tar.bz2 42-cub3d-7d50a78eed9c6cfce3288c471b9f3e6367bfe040.tar.xz 42-cub3d-7d50a78eed9c6cfce3288c471b9f3e6367bfe040.tar.zst 42-cub3d-7d50a78eed9c6cfce3288c471b9f3e6367bfe040.zip |
gang
Diffstat (limited to 'src')
-rw-r--r-- | src/ft_draw_sprite.c | 10 | ||||
-rw-r--r-- | src/ft_raycasting.c | 8 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index e412998..ffc2d50 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -82,8 +82,8 @@ void while (i < cl->mlist->sprite_nbr) { sprite = cl->sprites[i]; - sprite.spritey = sprite.s_pos_x - cl->plist->pos_x; - sprite.spritex = sprite.s_pos_y - cl->plist->pos_y; + sprite.spritey = sprite.s_pos_x - (cl->plist->pos_x - 0.5); + sprite.spritex = sprite.s_pos_y - (cl->plist->pos_y - 0.5); sprite.invdet = 1.0 / (cl->plist->plane_x * cl->plist->dir_y - cl->plist->dir_x * cl->plist->plane_y); sprite.transformx = sprite.invdet * (cl->plist->dir_y * sprite.spritex- cl->plist->dir_x* sprite.spritey); sprite.transformy = sprite.invdet * (-cl->plist->plane_y* sprite.spritex + cl->plist->plane_x * sprite.spritey); @@ -101,7 +101,6 @@ void int32_t d; sprite->x = sprite->drawstartx; - printf("y : [%d] [%d] x : [%d] [%d] x : [%f] y : [%f]\n", sprite->drawstarty, sprite->drawendy, sprite->drawstartx, sprite->drawendx, cl->plist->dir_x, cl->plist->dir_y); while (sprite->x < sprite->drawendx) { sprite->tex_x = (int32_t)((sprite->x - (-sprite->spritewidth / 2 + @@ -114,7 +113,7 @@ void sprite->tex_y = ((d * cl->tlist[4].img_h / 2) / sprite->spriteheight) / 128; if (cl->tlist[4].ptr[sprite->tex_x * 4 + 4 * cl->tlist[4].img_h * sprite->tex_y] - && cl->rlist.wall_dist_tab[sprite->x] > cl->rlist.wall_dist) + && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy) { cl->img.ptr[sprite->x * 4 + (sprite->y * cl->img.sizeline)] = cl->tlist[4].ptr[sprite->tex_x * 4 + 4 * cl->tlist[4].img_h * sprite->tex_y]; @@ -130,6 +129,3 @@ void sprite->x++; } } - - -/* printf("[%f] [%f] x [%f] y [%f] [%d]\n", sprite.spritex, sprite.spritey, sprite.transformx, sprite.transformy, i); */ diff --git a/src/ft_raycasting.c b/src/ft_raycasting.c index 2c4b05c..464eb95 100644 --- a/src/ft_raycasting.c +++ b/src/ft_raycasting.c @@ -71,7 +71,12 @@ ft_castray(t_cub *cl) { uint16_t i; t_win *wl; + float *dist_tab; + if (!(dist_tab = malloc(sizeof(float) * cl->wlist->x_size))) + return ; + if (!(cl->rlist.wall_dist_tab = malloc(sizeof(float) * cl->wlist->x_size))) + return ; i = 0; wl = cl->wlist; while (i < wl->x_size) @@ -87,7 +92,8 @@ ft_castray(t_cub *cl) ft_choose_tex(cl); ft_calc_tex(cl); ft_draw_verline(cl, i, cl->rlist.wall_t, cl->rlist.wall_b); - cl->rlist.wall_dist_tab[i] = cl->rlist.wall_dist; + dist_tab[i] = cl->rlist.wall_dist; + cl->rlist.wall_dist_tab = dist_tab; i++; } } |