diff options
-rw-r--r-- | src/ft_draw_sprite.c | 41 |
1 files changed, 11 insertions, 30 deletions
diff --git a/src/ft_draw_sprite.c b/src/ft_draw_sprite.c index b8d9506..8c1b848 100644 --- a/src/ft_draw_sprite.c +++ b/src/ft_draw_sprite.c @@ -53,25 +53,11 @@ void void ft_sprite_height(t_cub *cl, t_sprite *sprite) { - sprite->spriteheight = abs((int)(cl->wlist->y_size / (sprite->transformy))); - sprite->drawstarty = -sprite->spriteheight / 2 + cl->wlist->y_size / 2; - if (sprite->drawstarty < 0) - sprite->drawstarty = 0; - sprite->drawendy = sprite->spriteheight / 2 + cl->wlist->y_size / 2; - if (sprite->drawendy >= (int)cl->wlist->y_size) - sprite->drawendy = cl->wlist->y_size - 1; } void ft_sprite_width(t_cub *cl, t_sprite *sprite) { - sprite->spritewidth = abs((int)(cl->wlist->y_size / (sprite->transformy))); - sprite->drawstarty = -sprite->spritewidth / 2 + sprite->spritescreenx; - if (sprite->drawstartx < 0) - sprite->drawstartx = 0; - sprite->drawendy = sprite->spritewidth / 2 + sprite->spritescreenx; - if (sprite->drawendx >= (int)cl->wlist->x_size) - sprite->drawendx = cl->wlist->x_size - 1; } void @@ -81,22 +67,17 @@ void int i = 0; while (i < cl->mlist->sprite_nbr) - { - sprite = cl->sprites[i]; - sprite.spritex = sprite.s_pos_x - (cl->plist->pos_x); - sprite.spritey = sprite.s_pos_y - (cl->plist->pos_y); - 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.spritey - cl->plist->dir_x * sprite.spritex); - 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_sprite_height(cl, &sprite); - ft_sprite_width(cl, &sprite); - ft_draw_sprite(cl, &sprite); - i++; + { + sprite = cl->sprites[i]; + sprite.spritex = sprite.s_pos_x - cl->plist->pos_x; + sprite.spritey = sprite.s_pos_y - cl->plist->pos_y; + sprite.invdet = 1.0 / (cl->plist.plane_x * cl->plist->dir_y - cl->plist->dir_x * cl->plist->plane_y); //required for correct matrix multiplication + sprite.transformx = sprite.invdet * (cl->plist->dir_y * sprite.spritex- cl->plist->dir_x* sprite.spritey); + sprite.transformy = invDet * (-cl->plist->plane_y* sprite.spritex + cl->plist->plane_x * sprite.spritey); + ft_sprite_height(cl, &sprite); + ft_sprite_width(cl, &sprite); + ft_draw_sprite(cl, &sprite); + i++; } } |