-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol_key.c
More file actions
90 lines (82 loc) · 2.81 KB
/
control_key.c
File metadata and controls
90 lines (82 loc) · 2.81 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* control_key.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gemerald <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/23 17:41:12 by gemerald #+# #+# */
/* Updated: 2019/11/23 17:45:10 by gemerald ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
int mouse_press_hook(int key, int x, int y, void *param)
{
t_point *half;
half = ((t_point *)param);
if (key == 1 && x && y)
half->mouse.left_press = 1;
if (key == 4)
half->vizor.zoom += 2;
if (key == 5 && half->vizor.zoom > 2)
half->vizor.zoom -= 2;
if (key == 2)
{
zero_to_vizor(half);
zero_to_rot(&half->rot);
}
ft_bzero(half->img_sourse, 4000000);
draw_point(half);
mlx_put_image_to_window(half->mlx_ptr, half->window, half->map, 0, 0);
return (0);
}
void motion_draw(t_point *half)
{
if (half->mouse.prev_x == half->mouse.x &&
half->mouse.prev_y > half->mouse.y)
half->rot.alpha -= 0.05;
else if (half->mouse.prev_x == half->mouse.x &&
half->mouse.prev_y < half->mouse.y)
half->rot.alpha += 0.05;
else if (half->mouse.prev_x < half->mouse.x &&
half->mouse.prev_y == half->mouse.y)
half->rot.tetta += 0.05;
else if (half->mouse.prev_x > half->mouse.x &&
half->mouse.prev_y == half->mouse.y)
half->rot.tetta -= 0.05;
else if ((half->mouse.prev_x < half->mouse.x &&
half->mouse.prev_y < half->mouse.y) ||
(half->mouse.prev_x > half->mouse.x &&
half->mouse.prev_y < half->mouse.y))
half->rot.beta += 0.05;
else if ((half->mouse.prev_x > half->mouse.x &&
half->mouse.prev_y > half->mouse.y) ||
(half->mouse.prev_x < half->mouse.x &&
half->mouse.prev_y > half->mouse.y))
half->rot.beta -= 0.05;
ft_bzero(half->img_sourse, 4000000);
draw_point(half);
mlx_put_image_to_window(half->mlx_ptr, half->window, half->map, 0, 0);
}
int motion_hook(int x, int y, void *param)
{
t_point *half;
half = ((t_point *)param);
if (half->mouse.left_press)
{
half->mouse.prev_x = half->mouse.x;
half->mouse.prev_y = half->mouse.y;
half->mouse.x = x;
half->mouse.y = y;
motion_draw(half);
}
return (0);
}
int mouse_release_hook(int key, int x, int y, void *param)
{
t_point *half;
half = ((t_point *)param);
if (key == 1 && x && y)
half->mouse.left_press = 0;
return (0);
}