aboutsummaryrefslogtreecommitdiffstats
path: root/src/ft_draw_textures.c
blob: 533564d706f5bf7b3065b40adb762e457a1742cb (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_basic_keys.c                                    :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: fmoenne- <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/14 17:43:55 by fmoenne-          #+#    #+#             */
/*   Updated: 2020/02/14 17:43:56 by fmoenne-         ###   ########lyon.fr   */
/*                                                                            */
/* ************************************************************************** */

#include <libft.h>
#include <cub3d.h>
#include <stdint.h>

/*
** 1 : no
** 0 : so
** 3 : ea
** 4 : we
** 4 : sprite
*/

void
	ft_draw_texture(t_cub *cl, int x, int y, int tex_y)
{
	float	dist;
	t_rgb	rgb;

	if ((dist = cl->rlist.wall_dist_tab[x]) <= 0)
		dist = 0.0001;
	rgb.r =
		(uint8_t)cl->tlist[cl->rlist.w_side_tab[x]].ptr[cl->rlist.tex_x_tab[x]
		* 4 + 4 * cl->tlist[cl->rlist.w_side_tab[x]].img_h * tex_y + 2];
	rgb.g =
		(uint8_t)cl->tlist[cl->rlist.w_side_tab[x]].ptr[cl->rlist.tex_x_tab[x]
		* 4 + 4 * cl->tlist[cl->rlist.w_side_tab[x]].img_h * tex_y + 1];
	rgb.b =
		(uint8_t)cl->tlist[cl->rlist.w_side_tab[x]].ptr[cl->rlist.tex_x_tab[x]
		* 4 + 4 * cl->tlist[cl->rlist.w_side_tab[x]].img_h * tex_y];
	*(int*)(cl->img.ptr + ((uint16_t)x * 4 +
		(y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl);
}

void
	ft_choose_tex(uint16_t x, t_cub *clist)
{
	if (clist->rlist.sqx == clist->mlist.nlx
		&& clist->rlist.sqy == clist->mlist.nly)
	{
		clist->w_side = 5;
	}
	else
	{
		if (clist->rlist.side == 0 && clist->rlist.y_ray_dir < 0)
			clist->w_side = 1;
		else if (clist->rlist.side == 0 && clist->rlist.y_ray_dir > 0)
			clist->w_side = 0;
		else if (clist->rlist.side == 1 && clist->rlist.x_ray_dir > 0)
			clist->w_side = 3;
		else
			clist->w_side = 2;
	}
	clist->rlist.w_side_tab[x] = clist->w_side;
}