/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_draw_sprite_extra.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: joelecle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/24 20:22:45 by joelecle #+# #+# */ /* Updated: 2020/03/09 18:56:01 by joelecle ### ########lyon.fr */ /* */ /* ************************************************************************** */ #include #include #include #include void ft_sprite_h_w(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; sprite->spritewidth = abs((int)(cl->wlist.x_size / (sprite->transformy))) * 0.8; sprite->drawstartx = -sprite->spritewidth / 2 + sprite->spritescreenx; if (sprite->drawstartx < 0) sprite->drawstartx = 0; sprite->drawendx = sprite->spritewidth / 2 + sprite->spritescreenx; if (sprite->drawendx >= (int)cl->wlist.x_size) 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_x - cl->plist.dir_y * cl->plist.plane_y); sprite->transformx = sprite->invdet * (-cl->plist.dir_x * sprite->spritex - cl->plist.dir_y * 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) { t_sprite sprite; int8_t i; i = -1; ft_sort_sprites(cl, -1, -1); while (++i < cl->big_t_val) { sprite = cl->sprites[(int8_t)cl->big_t[i][2]][(int32_t)cl->big_t[i][3]]; if (((cl->plist.pos_x > sprite.s_pos_x - 0.01 && cl->plist.pos_x < sprite.s_pos_x + 0.99) && (cl->plist.pos_y > sprite.s_pos_y - 0.01 && cl->plist.pos_y < sprite.s_pos_y + 0.99))) return ; if (sprite.s_pos_x != 0) { sprite.current_sprite = (int8_t)cl->big_t[i][1]; sprite.spritey = sprite.s_pos_x - (cl->plist.pos_x - 0.5); sprite.spritex = sprite.s_pos_y - (cl->plist.pos_y - 0.5); ft_init_sprite(cl, &sprite); ft_sprite_h_w(cl, &sprite); ft_draw_sprite(cl, &sprite); } } }