-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmouse_oper.c
81 lines (72 loc) · 2.51 KB
/
mouse_oper.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mouse_oper.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mabbas <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/08 19:23:34 by mabbas #+# #+# */
/* Updated: 2022/12/10 22:50:38 by mabbas ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/fractol.h"
/** I am using lerp algorithm where start and end value don't change during
* interpolation. The interpolation value changes which is a percentage
* ranging from 0.0 to 1.0 --> distance betn two given points.
* An extra check is there for the coeff value range.
**/
// double lerp(double start, double end, double inter_coeff)
// {
// if (inter_coeff <= 0.0)
// return (start);
// if (inter_coeff >= 1.0)
// return (end);
// return ((1 - inter_coeff) * start + inter_coeff * end);
// }
double lerp(double start, double end, double inter_coeff)
{
return (start + ((end - start) * inter_coeff));
}
int ctrl_mouse(int key, int x, int y, t_mlx *mlx)
{
t_oper mouse;
double zoom;
if (key == 1)
mlx->press = 1;
mouse.r = (mlx->min.r + x * ((mlx->max.r - mlx->min.r)
/ (WIDTH)));
mouse.i = (mlx->max.i - y * ((mlx->max.i - mlx->min.i)
/ (HEIGHT)));
if (key == 5)
zoom = 1.20;
else if (key == 4)
zoom = 0.80;
else
zoom = 1.0;
mlx->min.r = lerp(mouse.r, mlx->min.r, zoom);
mlx->min.i = lerp(mouse.i, mlx->min.i, zoom);
mlx->max.r = lerp(mouse.r, mlx->max.r, zoom);
mlx->max.i = lerp(mouse.i, mlx->max.i, zoom);
render_fractal(mlx);
return (0);
}
/** this two functions are specifically for julia set
* one is key press and the other is changing iteration **/
int julia_key_press(int key, int x, int y, t_mlx *mlx)
{
(void) x;
(void) y;
if (key == 1)
mlx->press = 0;
return (0);
}
int change_julia(int x, int y, t_mlx *mlx)
{
if (mlx->press == 1)
{
mlx->k = complex_init(4 * ((double)x / WIDTH - 0.5), \
4 * ((double)(HEIGHT - y) / HEIGHT - 0.5));
render_fractal(mlx);
}
return (0);
}