-
Notifications
You must be signed in to change notification settings - Fork 0
/
not_texture_ray.c
96 lines (88 loc) · 3.13 KB
/
not_texture_ray.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* not_texture_ray.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbrandy <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/02/07 12:14:26 by lbrandy #+# #+# */
/* Updated: 2021/03/22 11:30:33 by lbrandy ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
static void draw_floor(int *j, int end, t_all *all, int i)
{
while (*j < end)
{
my_mlx_pixel_put(all, i, *j, all->textures->f);
(*j)++;
}
}
static void draw_ceil(int *j, int end, t_all *all, int i)
{
while (*j < end)
{
my_mlx_pixel_put(all, i, *j, all->textures->c);
(*j)++;
}
}
void draw_frame(t_all *all)
{
int i;
int j;
i = 0;
mlx_clear_window(all->win->mlx, all->win->win);
while (i < all->textures->x)
{
j = 0;
init_raycast(all->raycast, i, all->textures->x, all->pos);
init_step(all->raycast, all->pos);
calc_dda(all->raycast, all->map, all->pos);
init_draw(all->draw, all->raycast, all, all->pos);
draw_floor(&j, all->draw->start, all, i);
draw_wall(all, all->draw, &j, i);
draw_ceil(&j, all->textures->y, all, i);
all->data_sprite->z_buffer[i] = all->raycast->walldist;
i++;
}
draw_sprites(all);
mlx_put_image_to_window(all->win->mlx, all->win->win, all->win->img, 0, 0);
}
void draw_wall(t_all *all, t_draw *d, int *y, int x)
{
while (*y < d->end)
{
d->tex_y = (int)d->tex_pos & (d->tex_height - 1);
d->tex_pos += d->step;
if (all->raycast->side == 0 && all->raycast->raydir_x < 0)
d->color = (*(int *)(all->so->addr + (d->tex_y * all->so->length + d->tex_x *
/*all->so->width) */ (all->so->bpp / 8)));
if (all->raycast->side == 0 && all->raycast->raydir_x > 0)
d->color = (*(int *)(all->ea->addr + ((d->tex_x + (d->tex_y *
all->ea->width)) * (all->ea->bpp / 8))));
if (all->raycast->side == 1 && all->raycast->raydir_y < 0)
d->color = (*(int *)(all->no->addr + ((d->tex_x + (d->tex_y *
all->no->width)) * (all->no->bpp / 8))));
if (all->raycast->side == 1 && all->raycast->raydir_y > 0)
d->color = (*(int *)(all->we->addr + ((d->tex_x + (d->tex_y *
all->we->width)) * (all->we->bpp / 8))));
my_mlx_pixel_put(all, x, *y, d->color);
(*y)++;
}
}
int raycasting(t_all *all)
{
int i;
i = 0;
all->raycast = (t_raycast *)malloc(sizeof(t_raycast));
all->draw = (t_draw *)malloc(sizeof(t_draw));
if (!all->raycast || !all->draw)
error_handler(3, 1);
all->draw->ms = 0.2;
all->draw->rs = 0.15;
draw_frame(all);
mlx_hook(all->win->win, 2, (1L << 0), &drawing, all);
mlx_hook(all->win->win, 17, (1L << 0), &my_exit_from_game, all);
mlx_loop(all->win->mlx);
return (0);
}