-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.c
More file actions
95 lines (85 loc) · 2.79 KB
/
Copy pathrender.c
File metadata and controls
95 lines (85 loc) · 2.79 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* render.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dbarba-v <dbarba-v@student.42madrid.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/13 11:33:22 by gamorcil #+# #+# */
/* Updated: 2026/01/19 10:48:45 by dbarba-v ### ########.fr */
/* */
/* ************************************************************************** */
#include "MLX42/MLX42.h"
#include "cub3d.h"
#include "game.h"
#include "libft.h"
#include <malloc.h>
static void set_draw_range(int wall_size, int *draw_range)
{
draw_range[0] = -wall_size / 2 + WIN_HEIGHT / 2;
if (draw_range[0] < 0)
draw_range[0] = 0;
draw_range[1] = wall_size / 2 + WIN_HEIGHT / 2;
if (draw_range[1] >= WIN_HEIGHT)
draw_range[1] = WIN_HEIGHT - 1;
}
static void paint_pixels(t_render *render_info, t_game *game, int x)
{
t_paint aux;
aux.tex = get_current_texture(render_info, game);
aux.tex_x = calculate_tex_x(render_info, game, aux.tex);
aux.step = 1.0 * aux.tex->height / render_info->wall_size;
aux.texture_position = (render_info->draw_range[0] - WIN_HEIGHT / 2
+ render_info->wall_size / 2) * aux.step;
aux.y = render_info->draw_range[0];
while (aux.y <= render_info->draw_range[1])
{
aux.tex_y = (int)aux.texture_position & (aux.tex->height - 1);
aux.texture_position += aux.step;
mlx_put_pixel(game->resources.walls, x, aux.y,
get_texture_pixel(aux.tex, aux.tex_x, aux.tex_y));
aux.y++;
}
}
static void draw_column(t_render *render_info, t_game *game, int x)
{
int *range;
range = render_info->draw_range;
render_info->perp_wall_dist = fix_eye(render_info);
render_info->wall_size = (int)(WIN_HEIGHT / render_info->perp_wall_dist);
set_draw_range(render_info->wall_size, range);
paint_pixels(render_info, game, x);
}
void clean_walls(mlx_image_t *wall)
{
int x;
int y;
y = -1;
while (++y < WIN_HEIGHT)
{
x = -1;
while (++x < WIN_WIDTH)
{
mlx_put_pixel(wall, x, y, 0x00000000);
}
}
}
void render(void *param)
{
t_game *game;
t_render render_info;
int x;
x = 0;
game = param;
ft_bzero(&render_info, sizeof(t_render));
init_plane(&render_info, game);
clean_walls(game->resources.walls);
while (x < WIN_WIDTH)
{
ray_dir_calc(&render_info, game, x);
setup_dda(&render_info, game);
dda(&render_info, game);
draw_column(&render_info, game, x);
x++;
}
}