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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_floor_cast_inits.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>
void
ft_set_fc_tex_xy(uint8_t tid, uint16_t x, uint16_t y, t_cub *cl)
{
const int32_t x_cell = (int32_t)(cl->rlist.x_floor);
const int32_t y_cell = (int32_t)(cl->rlist.y_floor);
cl->tlist[tid].tex_x = (int32_t)(cl->tlist[tid].img_h
* (cl->rlist.y_floor - y_cell));
cl->tlist[tid].tex_y = (int32_t)(cl->tlist[tid].img_w
* (cl->rlist.x_floor - x_cell));
cl->rlist.fc_tex_x_tab[tid - 6][y][x] = (cl->tlist[tid].tex_x >= 0) ?
(cl->tlist[tid].tex_x) : (-cl->tlist[tid].tex_x);
cl->rlist.fc_tex_y_tab[tid - 6][y][x] = (cl->tlist[tid].tex_y >= 0) ?
(cl->tlist[tid].tex_y) : (-cl->tlist[tid].tex_y);
}
void
ft_floor_cast_inits(uint16_t y, t_ray *rl, t_cub *cl)
{
rl->x_f_ray_dir = cl->plist.dir_y + cl->plist.plane_x;
rl->y_f_ray_dir = cl->plist.dir_x - cl->plist.plane_y;
rl->x_f_ray_dir_bis = cl->plist.dir_y - cl->plist.plane_x;
rl->y_f_ray_dir_bis = cl->plist.dir_x + cl->plist.plane_y;
rl->p = y - cl->wlist.y_size / 2;
cl->plist.pos_z = 0.5 * cl->wlist.y_size;
rl->row_dist = cl->plist.pos_z / rl->p;
cl->mlist.x_floor_step = rl->row_dist *
(rl->x_f_ray_dir_bis - rl->x_f_ray_dir) / cl->wlist.x_size;
cl->mlist.y_floor_step = rl->row_dist *
(rl->y_f_ray_dir_bis - rl->y_f_ray_dir) / cl->wlist.x_size;
rl->x_floor = -cl->plist.pos_y + rl->row_dist * rl->x_f_ray_dir;
rl->y_floor = cl->plist.pos_x + rl->row_dist * rl->y_f_ray_dir;
}
void
ft_floor_loop(uint16_t y, t_cub *cl)
{
uint16_t x;
x = 0;
ft_floor_cast_inits(y, &cl->rlist, cl);
while (x < cl->wlist.x_size)
{
if (cl->rlist.wall_b_tab[x] <= y)
{
if (cl->mlist.isftex)
ft_set_fc_tex_xy(6, x, y, cl);
if (cl->mlist.isctex)
ft_set_fc_tex_xy(7, x, cl->wlist.y_size - y - 1, cl);
}
cl->rlist.x_floor += cl->mlist.x_floor_step;
cl->rlist.y_floor += cl->mlist.y_floor_step;
x++;
}
cl->rlist.row_dist_tab[y] = cl->rlist.row_dist;
cl->rlist.row_dist_tab[cl->wlist.y_size - y] = cl->rlist.row_dist;
}
|