-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.c
83 lines (75 loc) · 2.04 KB
/
setup.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
/* ************************************************************************** */
/* */
/* :::::::: */
/* setup.c :+: :+: */
/* +:+ */
/* By: jvan-hal <[email protected]> +#+ */
/* +#+ */
/* Created: 2023/02/23 11:14:07 by jvan-hal #+# #+# */
/* Updated: 2023/03/02 10:40:10 by jvan-hal ######## odam.nl */
/* */
/* ************************************************************************** */
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<errno.h>
#include<fcntl.h>
#include"fdf.h"
void set_start_view(t_fdf *fdf)
{
fdf->rot_x = -25;
fdf->rot_y = 30;
fdf->rot_z = 38;
fdf->zoom = 4;
fdf->trans_x = 150;
fdf->trans_y = 150;
scale_map(fdf, fdf->zoom);
rot_map(fdf, fdf->rot_x, fdf->rot_y, fdf->rot_z);
translate_map(fdf, fdf->trans_x, fdf->trans_y);
}
int get_input(char *file, t_fdf *fdf)
{
int fd;
fd = open(file, O_RDONLY);
if (!parse_input(fd, &(fdf->coords)))
{
errno = ENOMEM;
perror("Error");
exit(EXIT_FAILURE);
}
close(fd);
if (!fdf->coords)
{
write(2, "Error: file not loaded\n", 23);
exit (EXIT_FAILURE);
}
return (1);
}
void hooks(t_fdf *fdf)
{
mlx_loop_hook(fdf->mlx, &keyhook, fdf);
mlx_scroll_hook(fdf->mlx, &scrollhook, fdf);
mlx_loop(fdf->mlx);
}
static void init_map(t_list *coords)
{
t_coord *coord;
while (coords)
{
coord = (t_coord *)(coords->content);
coord->sx = coord->x;
coord->sy = coord->y;
coords = coords->next;
}
}
void start_fdf(t_fdf *fdf)
{
init_map(fdf->coords);
set_start_view(fdf);
fdf->img[0] = generate_image(fdf);
if (!fdf->img[0])
{
(free_fdf(fdf));
exit(EXIT_FAILURE);
}
}