-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.c
139 lines (131 loc) · 3.92 KB
/
draw.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kkalinic <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/04 12:15:57 by kkalinic #+# #+# */
/* Updated: 2021/05/04 12:57:06 by kkalinic ### ########.fr */
/* */
/* ************************************************************************** */
#include "headers/cub_head.h"
void print_back(int drawStart, int drawEnd, int x, t_data *mlx_s)
{
while (drawStart <= drawEnd / 2)
{
my_mlx_pixel_put(mlx_s, x, drawStart, mlx_s->cel);
drawStart++;
}
while (drawStart <= drawEnd)
{
my_mlx_pixel_put(mlx_s, x, drawStart, mlx_s->floor);
drawStart++;
}
}
/*
**static void print_line(t_data *mlx_s, int x, int y, int color)
**{
** int goal_x;
**
** goal_x = x + mlx_s->map_s->width;
** while(x <= goal_x && x < mlx_s->width)
** {
** my_mlx_pixel_put(mlx_s, x, y, color);
** x++;
** }
**
**}
**
**void print_sq(t_data *mlx_s, int x, int y, int color)
**{
** int goal_y;
**
** goal_y = y + mlx_s->map_s->height;
** while(y <= goal_y && y < mlx_s->height)
** {
** print_line(mlx_s, x, y, color);
** y++;
** }
**}
**
** void print_string(t_data *mlx_s, char *s, int y)
**{
** int x;
**
** x = 0;
** while(*s)
** {
** if (*s == '1' || *s == '2')
** print_sq(mlx_s, x, y, 0x0FFF0000);
** else
** print_sq(mlx_s, x, y, 0x0F0000FF);
** s++;
** x += mlx_s->map_s->width;
** }
**}
**
**void print_map(t_data *mlx_s)
**{
** int i;
** int y;
**
** i = 0;
** y = 0;
** while(mlx_s->map_s->map[i])
** {
** print_string(mlx_s, mlx_s->map_s->map[i++], y);
** y += mlx_s->map_s->height;
** }
**}
*/
/*
** Following two functions are texturise my floor and celling.
**
**
*/
static void print_ceiling(t_data *mlx_s, t_floor *floor_s)
{
t_cel cel_s;
unsigned int color;
cel_s.x = -1;
while (++cel_s.x < mlx_s->width)
{
cel_s.cellX = (int)(floor_s->floorX);
cel_s.cellY = (int)(floor_s->floorY);
cel_s.tx = (int)(64 * (floor_s->floorX - cel_s.cellX)) & (64 - 1);
cel_s.ty = (int)(64 * (floor_s->floorY - cel_s.cellY)) & (64 - 1);
floor_s->floorX += floor_s->floorStepX;
floor_s->floorY += floor_s->floorStepY;
mlx_pixel_get(mlx_s->tex->no_side, cel_s.tx, cel_s.ty, &color);
color = (color >> 1) & 8355711;
my_mlx_pixel_put(mlx_s, cel_s.x, floor_s->y, color);
mlx_pixel_get(mlx_s->tex->ea_side, cel_s.tx, cel_s.ty, &color);
color = (color >> 1) & 8355711;
my_mlx_pixel_put(mlx_s, cel_s.x,
(mlx_s->height - floor_s->y - 1), color);
}
}
void print_floor(t_data *mlx_s, t_ray *ray)
{
t_r_dir dir_s;
t_floor floor_s;
floor_s.y = -1;
while (++floor_s.y < mlx_s->height)
{
dir_s.rayDirX0 = ray->dir->x - ray->plane->x;
dir_s.rayDirY0 = ray->dir->y - ray->plane->y;
dir_s.rayDirX1 = ray->dir->x + ray->plane->x;
dir_s.rayDirY1 = ray->dir->y + ray->plane->y;
dir_s.p = floor_s.y - mlx_s->height / 2;
dir_s.posZ = 0.5 * mlx_s->height;
dir_s.rowDistance = dir_s.posZ / dir_s.p;
floor_s.floorStepX = dir_s.rowDistance
* (dir_s.rayDirX1 - dir_s.rayDirX0) / mlx_s->width;
floor_s.floorStepY = dir_s.rowDistance
* (dir_s.rayDirY1 - dir_s.rayDirY0) / mlx_s->width;
floor_s.floorX = ray->pos->x + dir_s.rowDistance * dir_s.rayDirX0;
floor_s.floorY = ray->pos->y + dir_s.rowDistance * dir_s.rayDirY0;
print_ceiling(mlx_s, &floor_s);
}
}