-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdf.c
88 lines (81 loc) · 2.71 KB
/
fdf.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fdf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kmummadi <kmummadi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/29 15:10:12 by kmummadi #+# #+# */
/* Updated: 2024/12/20 15:35:50 by kmummadi ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
void draw_vertical(mlx_image_t *image, t_dim *dim, t_ij ij, t_line pos);
void draw_horizontal(mlx_image_t *image, t_dim *dim, t_ij ij, t_line pos);
int calc_cells(t_dim *dim);
void draw_fdf(mlx_image_t *image, t_dim *dim)
{
t_line pos;
t_ij ij;
ij.i = 0;
ij.j = 0;
dim->cells = calc_cells(dim);
pos.max_z = dim->max_z;
while (ij.i < dim->height)
{
ij.j = 0;
while (ij.j < dim->width)
{
pos.y_start = (ij.i * dim->cells);
pos.x_start = (ij.j * dim->cells);
pos.z_start = (double)dim->values[ij.i][ij.j];
isometric_projection(&pos.x_start, &pos.y_start, pos.z_start, dim);
draw_horizontal(image, dim, ij, pos);
draw_vertical(image, dim, ij, pos);
ij.j++;
}
ij.i++;
}
}
void draw_horizontal(mlx_image_t *image, t_dim *dim, t_ij ij, t_line pos)
{
if (ij.j + 1 < dim->width)
{
pos.x_end = ((ij.j + 1) * dim->cells);
pos.y_end = (ij.i * dim->cells);
pos.z_end = (double)dim->values[ij.i][ij.j + 1];
isometric_projection(&pos.x_end, &pos.y_end, pos.z_end, dim);
if (dim->values[ij.i][ij.j + 1] > dim->min_z
|| dim->values[ij.i][ij.j] > dim->min_z)
draw_line(image, &pos, COLOR2);
else
draw_line(image, &pos, COLOR1);
}
}
void draw_vertical(mlx_image_t *image, t_dim *dim, t_ij ij, t_line pos)
{
if (ij.i + 1 < dim->height)
{
pos.x_end = (ij.j * dim->cells);
pos.y_end = ((ij.i + 1) * dim->cells);
pos.z_end = (double)dim->values[ij.i + 1][ij.j];
isometric_projection(&pos.x_end, &pos.y_end, pos.z_end, dim);
if (dim->values[ij.i + 1][ij.j] > dim->min_z
|| dim->values[ij.i][ij.j] > dim->min_z)
draw_line(image, &pos, COLOR2);
else
draw_line(image, &pos, COLOR1);
}
}
int calc_cells(t_dim *dim)
{
if (dim->height >= 400)
return (2);
else if (dim->height >= 100)
return (5);
else if (dim->height >= 50)
return (10);
else if (dim->height >= 25)
return (20);
return (40);
}