-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouse.c
77 lines (73 loc) · 2.31 KB
/
mouse.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* input.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jserrano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/17 13:25:20 by jserrano #+# #+# */
/* Updated: 2020/11/04 14:58:48 by jserrano ### ########.fr */
/* */
/* ************************************************************************** */
#include "raymarching.h"
int get_pos(int x, int y, t_data *param)
{
if (param->button == 1)
{
param->reload = 1;
param->crd.x = param->mou.x + x - param->scr.x / 2;
param->crd.y = -(param->mou.y + y - param->scr.y / 2);
if (param->crd.y > 249)
{
param->crd.y = 245;
mlx_mouse_move(param->id, param->win_id, x,
param->scr.y / 2 - param->crd.y);
}
else if (param->crd.y < -249)
{
param->crd.y = -245;
mlx_mouse_move(param->id, param->win_id, x,
param->scr.y / 2 - param->crd.y);
}
calculate_rotation(param);
calculate_vectors(param);
copy_cam(param);
}
return (0);
}
int button_pressed(int button, int x, int y, t_data *param)
{
param->button = button;
if (param->key == KEY_ENT)
param->key = 0;
if (button == 1)
{
mlx_mouse_hide(param->id, param->win_id);
mlx_mouse_move(param->id, param->win_id, param->scr.x / 2,
param->scr.y / 2);
param->crd.aux_x = x;
param->crd.aux_y = y;
}
else if (button == 3)
{
vectors_init(param, param->cam.i);
mouse_init(param);
calculate_rotation(param);
calculate_vectors(param);
copy_cam(param);
}
return (0);
}
int button_released(int button, int x, int y, t_data *param)
{
if (button == 1)
{
param->mou.x += (x - param->scr.x / 2);
param->mou.y += (y - param->scr.y / 2);
mlx_mouse_move(param->id, param->win_id, param->crd.aux_x,
param->crd.aux_y);
mlx_mouse_show(param->id, param->win_id);
}
param->button = 0;
return (0);
}