diff options
Diffstat (limited to '')
-rw-r--r-- | src/ft_draw_sprite_extra.c | 31 | ||||
-rw-r--r-- | src/ft_get_sprite.c | 19 |
2 files changed, 25 insertions, 25 deletions
diff --git a/src/ft_draw_sprite_extra.c b/src/ft_draw_sprite_extra.c index 0f923e7..f6a148c 100644 --- a/src/ft_draw_sprite_extra.c +++ b/src/ft_draw_sprite_extra.c @@ -41,6 +41,19 @@ void sprite->drawendx = cl->wlist.x_size - 1; } +static void + ft_init_sprite(t_cub *cl, t_sprite *sprite) +{ + 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); + sprite->spritescreenx = (int)(cl->wlist.x_size / 2) * + (1 + sprite->transformx / sprite->transformy); +} + void ft_calc_sprite(t_cub *cl) { @@ -50,29 +63,15 @@ void i = 0; j = 0; - printf("%d\n", cl->sprites[0][0].s_pos_x); - printf("%d\n", cl->sprites[1][0].s_pos_x); - printf("%d\n", cl->sprites[2][0].s_pos_x); - /* printf("%d\n", cl->sprites[3][0].s_pos_x); */ - /* cl->sprites[2][0].s_pos_x = 4; */ - /* cl->sprites[2][0].s_pos_y = 2; */ - while (j <= cl->mlist.sprite_var) + while (j < cl->mlist.sprite_var - 1) { while (i < cl->mlist.sprite_nbr) { sprite = cl->sprites[j][i]; sprite.current_sprite = (j == 0) ? 4 : j + 7; - /* printf("j :%d curr : %d\n", j, sprite.current_sprite); */ 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); - sprite.spritescreenx = (int)(cl->wlist.x_size / 2) * - (1 + sprite.transformx / sprite.transformy); + ft_init_sprite(cl, &sprite); ft_sprite_height(cl, &sprite); ft_sprite_width(cl, &sprite); ft_draw_sprite(cl, &sprite); diff --git a/src/ft_get_sprite.c b/src/ft_get_sprite.c index 8e22075..a158940 100644 --- a/src/ft_get_sprite.c +++ b/src/ft_get_sprite.c @@ -22,12 +22,12 @@ void size_t y; uint8_t i; - x = 1; - y = 1; + x = 0; + y = 0; i = 0; - while (clist->mlist.map[y]) + while (clist->mlist.map[++y]) { - while (clist->mlist.map[y][x]) + while (clist->mlist.map[y][++x]) { if (clist->mlist.map[y][x] == c) { @@ -35,14 +35,15 @@ void clist->sprites[s_n][i].s_pos_x = x; clist->sprites[s_n][i].s_pos_y = y; i++; - ft_get_next_sprite(clist, s_n++, c + 1); } - x++; } - x = 1; - y++; + x = 0; + } + if (clist->sprites[s_n][i - 1].s_pos_x != 0) + { + ft_get_next_sprite(clist, s_n + 1, c + 1); + clist->mlist.sprite_var++; } - clist->mlist.sprite_var += (clist->sprites[s_n][i].s_pos_x != 0); } void |