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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_floor_cast.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rbousset <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/14 17:22:57 by rbousset #+# #+# */
/* Updated: 2020/02/14 17:23:42 by rbousset ### ########lyon.fr */
/* */
/* ************************************************************************** */
#include <cub3d.h>
#include <stdint.h>
static void
ft_draw_plain_horizontal(t_rgb rgb, t_cub *cl, int32_t y, int32_t x)
{
float dist;
if ((dist = cl->rlist.row_dist_tab[y]) <= 0)
dist = 0.0001;
*(int*)(cl->img.ptr +
(x * 4 + (y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl);
}
static void
ft_draw_extra_tex(uint8_t tid, uint16_t y, uint16_t x, t_cub *cl)
{
float dist;
t_rgb rgb;
if ((dist = cl->rlist.row_dist_tab[y]) <= 0)
dist = 0.0001;
rgb.b = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x
* 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y];
rgb.g = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x
* 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 1];
rgb.r = (uint8_t)cl->tlist[tid].ptr[cl->tlist[tid].tex_x
* 4 + 4 * cl->tlist[tid].img_h * cl->tlist[tid].tex_y + 2];
*(int*)(cl->img.ptr + ((uint16_t)x * 4 +
(y * cl->img.sizeline))) = ft_rgb_to_hex(dist, rgb, cl);
}
static void
ft_set_tex_xy(uint8_t tid, uint16_t x, t_ray *rl, t_cub *cl)
{
const int32_t x_cell = (int32_t)(rl->x_floor_tab[x]);
const int32_t y_cell = (int32_t)(rl->y_floor_tab[x]);
cl->tlist[tid].tex_x = (int32_t)(cl->tlist[tid].img_h
* (rl->y_floor_tab[x] - y_cell));
cl->tlist[tid].tex_y = (int32_t)(cl->tlist[tid].img_w
* (rl->x_floor_tab[x] - x_cell));
}
static void
ft_floor_cast_loop(uint16_t y, uint16_t x, t_ray *rl, t_cub *cl)
{
if (cl->mlist.isftex)
{
ft_set_tex_xy(6, x, rl, cl);
ft_draw_extra_tex(6, y, x, cl);
}
else
ft_draw_plain_horizontal(cl->f_rgb, cl, y, x);
if (cl->mlist.isctex && !cl->mlist.isskybox)
{
ft_set_tex_xy(7, x, rl, cl);
ft_draw_extra_tex(7, cl->wlist.y_size - y - 1, x, cl);
}
else if (!cl->mlist.isctex && !cl->mlist.isskybox)
ft_draw_plain_horizontal(cl->c_rgb, cl, cl->wlist.y_size - y - 1, x);
}
void
*ft_floor_cast(void *vargp)
{
t_cub *cl;
uint16_t x;
uint16_t y;
cl = (t_cub *)vargp;
y = (cl->wlist.y_size / 2);
while (y < cl->wlist.y_size)
{
x = 0;
while (x < cl->wlist.x_size)
{
if (cl->rlist.wall_bz[x] <= y)
ft_floor_cast_loop(y, x, &cl->rlist, cl);
x++;
}
y++;
}
return (0x0);
}
|