diff options
author | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-29 17:34:48 +0200 |
---|---|---|
committer | JozanLeClerc <bousset.rudy@gmail.com> | 2020-03-29 17:34:48 +0200 |
commit | 69ca60b6f989dedc94c2e25ab9927b26d63cbdf8 (patch) | |
tree | 28fb01bf9380925e60c19caaf967cb28685ca3bd /src/ft_draw_weapons.c | |
parent | The greatest (diff) | |
download | 42-cub3d-69ca60b6f989dedc94c2e25ab9927b26d63cbdf8.tar.gz 42-cub3d-69ca60b6f989dedc94c2e25ab9927b26d63cbdf8.tar.bz2 42-cub3d-69ca60b6f989dedc94c2e25ab9927b26d63cbdf8.tar.xz 42-cub3d-69ca60b6f989dedc94c2e25ab9927b26d63cbdf8.tar.zst 42-cub3d-69ca60b6f989dedc94c2e25ab9927b26d63cbdf8.zip |
Norm
Diffstat (limited to 'src/ft_draw_weapons.c')
-rw-r--r-- | src/ft_draw_weapons.c | 111 |
1 files changed, 0 insertions, 111 deletions
diff --git a/src/ft_draw_weapons.c b/src/ft_draw_weapons.c deleted file mode 100644 index c527987..0000000 --- a/src/ft_draw_weapons.c +++ /dev/null @@ -1,111 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_draw_weapons.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2020/02/24 20:22:45 by rbousset #+# #+# */ -/* Updated: 2020/03/09 18:56:01 by rbousset ### ########lyon.fr */ -/* */ -/* ************************************************************************** */ - -#include <cub3d.h> -#include <stdint.h> -#include <math.h> - -static void - ft_sort_weapons_norme(float *dist_tab, int16_t *i, uint16_t j, t_cub *cl) -{ - uint32_t tmp; - uint32_t it; - - it = *i; - tmp = 0; - if (dist_tab[it] < dist_tab[it + 1]) - { - tmp = dist_tab[it]; - dist_tab[it] = dist_tab[it + 1]; - dist_tab[it + 1] = tmp; - tmp = cl->mlist.weaps_order[j][it]; - cl->mlist.weaps_order[j][it] = cl->mlist.weaps_order[j][it + 1]; - cl->mlist.weaps_order[j][it + 1] = tmp; - *i = -1; - } -} - -void - ft_sort_weapons(t_cub *cl, int16_t it, int16_t jt) -{ - float dist_tab[2][1]; - - while (++jt <= cl->mlist.weapon_var) - { - while (++it <= cl->mlist.weaps_nbr[jt]) - { - dist_tab[jt][it] = - ((cl->plist.pos_x - cl->weaps[jt][it].s_pos_x) * - (cl->plist.pos_x - cl->weaps[jt][it].s_pos_x) + - (cl->plist.pos_y - cl->weaps[jt][it].s_pos_y) * - (cl->plist.pos_y - cl->weaps[jt][it].s_pos_y)); - cl->mlist.weaps_order[jt][it] = it; - } - it = -1; - } - it = -1; - jt = -1; - while (++jt < cl->mlist.weapon_var) - { - while (++it < cl->mlist.weaps_nbr[jt] - 1) - ft_sort_weapons_norme(dist_tab[jt], &it, jt, cl); - it = -1; - } -} - -static void - ft_put_weapon(t_sprite *sprite, t_cub *cl) -{ - float dist; - t_rgb rgb; - - if ((dist = sqrtf(powf(cl->plist.pos_x - sprite->s_pos_x, 2) - + powf(cl->plist.pos_y - sprite->s_pos_y, 2))) <= 0) - dist = 0.0001; - rgb.r = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x - * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 2]; - rgb.g = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x - * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y + 1]; - rgb.b = (uint8_t)cl->tlist[sprite->current_sprite].ptr[sprite->tex_x - * 4 + 4 * cl->tlist[sprite->current_sprite].img_h * sprite->tex_y]; - *(int*)(cl->img.ptr + ((uint16_t)sprite->x * 4 + - (sprite->y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl); -} - -void - ft_draw_weapon(t_cub *cl, t_sprite *sprite) -{ - int32_t d; - - sprite->x = sprite->drawstartx; - while (sprite->x < sprite->drawendx) - { - sprite->tex_x = (int32_t)((sprite->x - (-sprite->spritewidth / 2 + - sprite->spritescreenx)) - * cl->tlist[sprite->current_sprite].img_w / sprite->spritewidth); - sprite->y = sprite->drawstarty; - while (sprite->y < sprite->drawendy) - { - d = sprite->y * 256 - cl->wlist.y_size * 128 + - sprite->spriteheight * 128; - sprite->tex_y = ((d * cl->tlist[sprite->current_sprite].img_h / 2) / - sprite->spriteheight) / 128; - if (sprite->transformy > 0 && - cl->tlist[sprite->current_sprite].ptr[sprite->tex_x * 4 + 4 * - cl->tlist[sprite->current_sprite].img_h * sprite->tex_y] - && cl->rlist.wall_dist_tab[sprite->x] > sprite->transformy) - ft_put_weapon(sprite, cl); - sprite->y++; - } - sprite->x++; - } -} |