-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfdf.c
More file actions
84 lines (76 loc) · 2.4 KB
/
Copy pathfdf.c
File metadata and controls
84 lines (76 loc) · 2.4 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fdf.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: revan-wy <revan-wy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/07/16 08:05:45 by revan-wy #+# #+# */
/* Updated: 2018/08/10 17:17:26 by revan-wy ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
void set_unit_origin_y(t_arr arr, t_env *env)
{
float posx;
float posy;
posx = 0;
posy = 0;
while (posx * (arr.rowmax + arr.colmax) / tan(30 * 0.0174533) + 400 <
env->winx)
posx += 0.1;
posx -= 0.1;
while (posy * (arr.rowmax + arr.colmax) + 400 < env->winy)
posy += 0.1;
posy -= 0.1;
if (posy < posx)
env->unit = posy;
else
env->unit = posx;
env->origin_y = env->winy / 2 - env->unit * (arr.rowmax - arr.colmax) / 2;
}
void check_argc(int argc)
{
if (argc != 2)
{
write(1, "Enter name of one map file\n", 27);
exit(0);
}
}
void set_env(t_env *env, char **argv)
{
env->winx = 2560;
env->winy = 1315;
env->gsci = mlx_init();
env->window = mlx_new_window(env->gsci, env->winx, env->winy, argv[1]);
}
void set_pron(t_env *env, t_arr *arr)
{
env->pron = 0;
while ((env->origin_y + (arr->max_z * env->pron * (env->unit / 100))) <
(env->winy - 100) && (env->origin_y + (arr->max_z * env->pron *
(env->unit / 100))) > 400)
env->pron++;
env->pron--;
}
int main(int argc, char **argv)
{
t_arr arr;
int **map;
t_env env;
t_index index;
check_argc(argc);
get_size_of_map(&arr, argv);
set_env(&env, argv);
index.i = 0;
map = (int **)ft_memalloc(sizeof(int*) * arr.rowmax);
map[0] = (int *)ft_memalloc(sizeof(int) * arr.rowmax * arr.colmax);
while (index.i < arr.rowmax)
map[index.i] = (*map + arr.colmax * index.i++);
read_map(map, argv, &arr, &env);
set_unit_origin_y(arr, &env);
set_pron(&env, &arr);
print_map(&arr, map, &env);
mlx_key_hook(env.window, key_event, 0);
mlx_loop(env.gsci);
}