aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_draw_weapons_extra.c
blob: 04b61eae21ac541aec291db233de7f65aede8dc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_draw_weapons_extra.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 <libft.h>
#include <cub3d.h>
#include <stdint.h>
#include <stdlib.h>

static void
	ft_calc_weapon(uint8_t id, t_cub *cl)
{
	t_sprite	sprite;

	sprite = cl->weaps[id][0];
	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_sprite_h_w(cl, &sprite);
	ft_draw_weapon(cl, &sprite);
}

void
	ft_calc_weaps(t_cub *cl)
{
	ft_calc_weapon(0, cl);
	ft_calc_weapon(1, cl);
}