-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoving_hook_bonus.c
83 lines (76 loc) · 2.18 KB
/
moving_hook_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* moving_hook_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: junyojeo <junyojeo@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/19 00:56:37 by junyojeo #+# #+# */
/* Updated: 2023/05/19 02:12:42 by junyojeo ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf_bonus.h"
static void projection_key(t_mlx *mlx)
{
int num;
num = mlx->projection + 1;
mlx->projection = num % 2;
draw(mlx);
}
static void zoom_key(int key, t_mlx *mlx)
{
if (key == KEY_EQUAL)
{
if (mlx->zoom == INT_MAX)
return ;
mlx->zoom++;
}
else if (key == KEY_MINUS)
{
if (mlx->zoom == 1)
return ;
mlx->zoom--;
}
draw(mlx);
}
static void rotate_key(int key, t_mlx *mlx)
{
if (key == KEY_U)
mlx->alpha += 0.05;
else if (key == KEY_J)
mlx->alpha -= 0.05;
else if (key == KEY_I)
mlx->beta += 0.05;
else if (key == KEY_K)
mlx->beta -= 0.05;
else if (key == KEY_O)
mlx->gamma += 0.05;
else if (key == KEY_L)
mlx->gamma -= 0.05;
draw(mlx);
}
static void move_key(int key, t_mlx *mlx)
{
if (key == KEY_W)
mlx->offset_y -= 10;
else if (key == KEY_S)
mlx->offset_y += 10;
else if (key == KEY_A)
mlx->offset_x -= 10;
else if (key == KEY_D)
mlx->offset_x += 10;
draw(mlx);
}
int my_key_hook(int key, t_mlx *mlx)
{
if (key == KEY_W || key == KEY_A || key == KEY_S || key == KEY_D)
move_key(key, mlx);
else if (key == KEY_U || key == KEY_J || key == KEY_I || \
key == KEY_K || key == KEY_O || key == KEY_L)
rotate_key(key, mlx);
else if (key == KEY_EQUAL || key == KEY_MINUS)
zoom_key(key, mlx);
else if (key == KEY_SPACE)
projection_key(mlx);
return (0);
}