-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeometric_utils.c
107 lines (97 loc) · 2.77 KB
/
geometric_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* geometric_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: pnoutere <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/04 18:27:36 by pnoutere #+# #+# */
/* Updated: 2022/04/06 13:32:10 by pnoutere ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
void draw(t_data *utils, t_xyz coord1, t_xyz coord2)
{
if (!utils->parallel)
{
isometric(&coord1.x, &coord1.y, coord1.z, utils);
isometric(&coord2.x, &coord2.y, coord2.z, utils);
}
else
{
coord1.x = coord1.x + utils->start_x;
coord1.y = coord1.y + utils->start_y;
coord2.x = coord2.x + utils->start_x;
coord2.y = coord2.y + utils->start_y;
}
if ((ft_abs(coord2.y - coord1.y)) < (ft_abs(coord2.x - coord1.x)))
drawer_1(utils, coord1, coord2);
else
drawer_2(utils, coord1, coord2);
}
void my_mlx_pixel_put(t_data *data, int x, int y, int color)
{
char *dst;
if (x >= 0 && x < 1920 && y >= 0 && y < 1080)
{
dst = data->addr + (y * data->line_length
+ x * (data->bits_per_pixel / 8));
*(unsigned int *)dst = color;
}
}
void isometric(int *x, int *y, int z, t_data *utils)
{
float x_1;
float y_1;
x_1 = (*x - *y) * cos(0.8);
y_1 = (*x + *y) * sin(utils->rotation) - (z * utils->z);
*x = (int)x_1 + utils->start_x;
*y = (int)y_1 + utils->start_y;
}
void calculate_center(t_data *utils, int *start_x, int *start_y)
{
int x1;
int x2;
int y1;
int y2;
x1 = utils->coords[0][0].x;
x2 = utils->coords[utils->rows - 1][utils->count -1].x;
y1 = utils->coords[0][0].y;
y2 = utils->coords[utils->rows - 1][utils->count -1].y;
if (!utils->parallel)
{
isometric(&x1, &y1, utils->coords[0][0].z, utils);
isometric(&x2, &y2,
utils->coords[utils->rows - 1][utils->count -1].z, utils);
}
*start_x = (x1 + x2) / 2;
*start_y = (y1 + y2) / 2;
*start_x = 960 - (*start_x - x1);
*start_y = 540 - (*start_y - y1);
}
void check_variance(int number, int *variant)
{
static int init;
static int init_2;
static int temp;
static int differ;
number = ft_abs(number);
if (!init)
{
temp = number;
init = 1;
return ;
}
if (number != temp)
{
if (!init_2)
{
differ = number;
*variant += 1;
init_2 = 1;
return ;
}
if (number != differ)
*variant += 1;
}
}