-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdraw_pixel.c
80 lines (72 loc) · 2.56 KB
/
draw_pixel.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_pixel.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jaemjeon <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/03 11:57:42 by jaesjeon #+# #+# */
/* Updated: 2022/11/13 10:03:01 by jaemjeon ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
void put_pixel_floor(t_game *game, int idx_x)
{
t_img_data *const view_data = &game->view_data;
double const color = game->floor_color;
char *dst;
double gradiant;
int idx_y;
idx_y = game->wall_pixel[idx_x].y;
gradiant = 0.4 + (0.6 - game->ray_data[idx_x].wall_distance * 0.05);
set_range_double(&gradiant, 0, 1);
while (idx_y < game->info.screen_y)
{
dst = view_data->addr + (idx_y * view_data->line_length + \
idx_x * (view_data->bits_per_pixel / 8));
gradiant += (1 - gradiant) * 10 / (game->info.screen_y - idx_y);
*(unsigned int *)dst = create_trgb(game->player.view_trans, \
get_r(color) * gradiant, \
get_g(color) * gradiant, \
get_b(color) * gradiant);
idx_y++;
}
}
void put_pixel_ceiling(t_game *game, int idx_x)
{
t_img_data *const view_data = &game->view_data;
t_vector2_d *const wall_pixel = &game->wall_pixel[idx_x];
char *dst;
int idx_y;
idx_y = 0;
while (idx_y < wall_pixel->x)
{
dst = view_data->addr + (idx_y * view_data->line_length + \
idx_x * (view_data->bits_per_pixel / 8));
*(unsigned int *)dst = game->ceiling_color;
idx_y++;
}
}
t_vector2 get_wall_pixel(t_game *game, t_vector2 *wall_line)
{
t_vector2 ret_vec;
if (wall_line->x < 0)
ret_vec.x = 0;
else if (wall_line->x > game->info.screen_y)
ret_vec.x = game->info.screen_y;
else
ret_vec.x = wall_line->x;
if (wall_line->y > game->info.screen_y)
ret_vec.y = game->info.screen_y;
else if (wall_line->y < 0)
wall_line->y = 0;
else
ret_vec.y = wall_line->y;
return (ret_vec);
}
void draw_line(t_game *game, int idx_x)
{
put_pixel_ceiling(game, idx_x);
put_pixel_wall(game, idx_x);
put_pixel_floor(game, idx_x);
}