-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwalls_02.c
78 lines (72 loc) · 2.36 KB
/
walls_02.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* walls_02.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mbalman <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/24 10:09:34 by prranges #+# #+# */
/* Updated: 2022/02/03 16:59:59 by mbalman ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void choose_txtr(t_wall *w)
{
if (w->hit == 2)
w->txtr_num = 4;
else if (w->side == 1 && w->ray_dir_y < 0)
w->txtr_num = 0;
else if (w->side == 1 && w->ray_dir_y >= 0)
w->txtr_num = 1;
else if (w->side == 0 && w->ray_dir_x < 0)
w->txtr_num = 2;
else if (w->side == 0 && w->ray_dir_x >= 0)
w->txtr_num = 3;
}
void choose_pixel(t_data *g, t_wall *w)
{
choose_txtr(w);
if (w->side == 0)
w->wall_x = g->p_pos_y + w->perp_wall_dist * w->ray_dir_y;
else
w->wall_x = g->p_pos_x + w->perp_wall_dist * w->ray_dir_x;
w->wall_x -= floor((w->wall_x));
w->txtr_x = (int)(w->wall_x * (double)TXTR_W);
if (w->side == 0 && w->ray_dir_x > 0)
w->txtr_x = TXTR_W - w->txtr_x - 1;
if (w->side == 1 && w->ray_dir_y < 0)
w->txtr_x = TXTR_W - w->txtr_x - 1;
w->step = 1.0 * TXTR_H / w->line_height;
w->txtr_pos = (w->draw_start - WIN_H / 2 + w->line_height / 2) * w->step;
w->y = w->draw_start;
}
void pixels_to_screen_buf(t_data *g, t_wall *w)
{
while (w->y < w->draw_end)
{
w->txtr_y = (int)w->txtr_pos & (TXTR_H - 1);
w->txtr_pos += w->step;
w->color = g->txtrs[w->txtr_num][TXTR_H * w->txtr_y + w->txtr_x];
if (w->side == 1)
w->color = (w->color >> 1) & 8355711;
g->screen_buf[w->y][w->x] = w->color;
w->y++;
}
}
void floor_and_ceiling(t_data *g)
{
int x;
int y;
y = WIN_H / 2 + 1;
while (y < WIN_H)
{
x = 0;
while (x < WIN_W)
{
g->screen_buf[y][x] = g->map.floor_color;
g->screen_buf[WIN_H - y - 1][x] = g->map.celing_color;
x++;
}
y++;
}
}