Repository navigation
Expand file tree
/
Copy pathmain.c
More file actions
96 lines (87 loc) · 2.62 KB
/
Copy pathmain.c
File metadata and controls
96 lines (87 loc) · 2.62 KB
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
/* ************************************************************************** */
/* */
/* :::::::: */
/* main.c :+: :+: */
/* +:+ */
/* By: fhignett <fhignett@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2019/03/10 21:11:37 by FlintLouis #+# #+# */
/* Updated: 2019/07/12 17:45:21 by fhignett ######## odam.nl */
/* */
/* ************************************************************************** */
#include "fdf.h"
#include <stdlib.h>
#include "minilibx_macos/mlx.h"
t_point point(int x, int y, int z)
{
t_point p;
p.x = x;
p.y = y;
p.z = z;
p.ogz = z;
return (p);
}
/*
** bzero cleans the screen
*/
static int draw_grid(t_fdf *fdf)
{
int i;
int j;
t_point a;
ft_bzero(fdf->data_addr, HEIGHT * WIDTH * (fdf->bits_per_pixel / 8));
i = 0;
while (i < fdf->map->height)
{
j = 0;
a = point(j, i, fdf->map->map[i][j]);
while (j < fdf->map->width)
{
calculate_line(fdf, a, i, j);
j++;
a = point(j, i, fdf->map->map[i][j]);
}
i++;
}
mlx_put_image_to_window(fdf->mlx, fdf->win, fdf->img, 0, 0);
mlx_string_put(fdf->mlx, fdf->win, 50, 50, 0xFFFFFF, "FDF");
return (0);
}
static void init_fdf(char *file)
{
t_fdf *fdf;
fdf = NEW(t_fdf);
fdf->mlx = mlx_init();
fdf->win = mlx_new_window(fdf->mlx, WIDTH, HEIGHT, "FDF");
fdf->img = mlx_new_image(fdf->mlx, WIDTH, HEIGHT);
fdf->data_addr = mlx_get_data_addr(fdf->img, &(fdf->bits_per_pixel),
&(fdf->size_line), &(fdf->endian));
fdf->map = get_map(file);
fdf->cam = init_cam(fdf);
fdf->gradient = init_gradient(fdf->map);
fdf->conf = NEW(t_conf);
mlx_loop_hook(fdf->mlx, draw_grid, fdf);
mlx_hook(fdf->win, 4, 1L << 2, mouse_press, fdf);
mlx_hook(fdf->win, 5, 1L << 3, mouse_release, fdf);
mlx_hook(fdf->win, 6, 1L << 6, mouse_move, fdf);
mlx_hook(fdf->win, 2, 1L << 0, key_press_conf, fdf);
mlx_hook(fdf->win, 3, 1L << 1, key_release_conf, fdf);
mlx_hook(fdf->win, 17, 1L << 17, close_window, NULL);
mlx_loop(fdf->mlx);
}
int main(int argc, char **argv)
{
if (argc != 2)
{
ft_putendl("Usage: ./fdf <filename> [ case_size z_size ]");
return (0);
}
if (errors(1, argv[1]) == 1)
init_fdf(argv[1]);
else
{
ft_putstr("No file ");
ft_putendl(argv[1]);
}
return (0);
}