blob: c82163a59aea06ee461fe868696997172f6ba258 (
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_raycasting.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_initray(uint16_t y, t_ray *rl, t_player *pl, t_cub *cl)
{
int16_t p;
rl->x_ray_dir = pl->dir_x - pl->plane_x;
rl->y_ray_dir = pl->dir_y - pl->plane_y;
rl->x_ray_dir_bis = pl->dir_x + pl->plane_x;
rl->y_ray_dir_bis = pl->dir_y + pl->plane_y;
p = y - cl->wlist.y_size / 2;
pl->pos_z = 0.5 * cl->wlist.y_size;
rl->row_dist = pl->pos_z / p;
cl->mlist.x_floor_step = rl->row_dist *
(rl->x_ray_dir_bis - rl->x_ray_dir) / cl->wlist.x_size;
cl->mlist.y_floor_step = rl->row_dist *
(rl->y_ray_dir_bis - rl->y_ray_dir) / cl->wlist.x_size;
rl->floor_x = pl->pos_x + rl->row_dist * rl->x_ray_dir;
rl->floor_y = pl->pos_y + rl->row_dist * rl->y_ray_dir;
}
void
ft_floor_cast(t_cub *cl)
{
uint16_t y;
uint16_t x;
y = 0;
while (y < cl->wlist.y_size)
{
ft_initray(y, &cl->rlist, &cl->plist, cl);
x = 1;
while (x < cl->wlist.x_size)
{
cl->rlist.ceil_x = (int16_t)cl->rlist.floor_x;
cl->rlist.ceil_y = (int16_t)cl->rlist.floor_y;
x++;
}
y++;
}
}
|