-
Notifications
You must be signed in to change notification settings - Fork 0
/
grapher2d_inputHandling.js
90 lines (65 loc) · 1.84 KB
/
grapher2d_inputHandling.js
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
function gpInternal_mouseMoveCallback(e) {
var gl = e.target.gpgl;
var posx = e.clientX;
var posy = e.clientY;
var down = e.buttons&1;
var bounds = e.target.getBoundingClientRect();
posx -= bounds.left;
posy -= bounds.top;
if (gl.preMouseX != posx || gl.preMouseY != posy || gl.preMouseDown != down) {
var dx = posx - gl.preMouseX;
var dy = posy - gl.preMouseY;
gl.preMouseX = posx;
gl.preMouseY = posy;
gl.preMouseDown = down;
if ((dx != 0 || dy != 0) && down == 1) {
var width = gl.g_right - gl.g_left;
var percentX = dx / gl.viewportWidth;
var moveX = -width * percentX;
gl.g_left += moveX;
gl.g_right += moveX;
var height = gl.g_up - gl.g_down;
var percentY = dy / gl.viewportHeight;
var moveY = height * percentY;
gl.g_down += moveY;
gl.g_up += moveY;
}
}
gl.needsUpdate = true;
}
function gpInternal_mouseWheelCallback(e) {
var gl = e.target.gpgl;
var scroll = -e.deltaY;
var bounds = e.target.getBoundingClientRect();
var x = e.clientX - bounds.left;
var y = e.clientY - bounds.top;
var x1 = 0;
var y1 = 0;
var x2 = gl.g_right - gl.g_left;
var y2 = gl.g_up - gl.g_down;
var w1 = (x / gl.viewportWidth)*x2;
var w2 = x2 - w1;
if (scroll > 0) {
x1 = 2 * gl.ZOOM_PERCENT*w1;
x2 = x2 - 2 * gl.ZOOM_PERCENT*w2;
} else if (scroll < 0){
x1 = - 2 * gl.ZOOM_PERCENT*w1;
x2 = x2 + 2 * gl.ZOOM_PERCENT*w2;
}
var h1 = ((gl.viewportHeight - y) / gl.viewportHeight)*(y2);
var h2 = y2 - ((gl.viewportHeight - y) / gl.viewportHeight)*(y2);
if (scroll > 0) {
y1 = 2 * gl.ZOOM_PERCENT*h1;
y2 = y2 - 2 * gl.ZOOM_PERCENT*h2;
}
else if (scroll < 0) {
y1 = -2 * gl.ZOOM_PERCENT*h1;
y2 = y2 + 2 * gl.ZOOM_PERCENT*h2;
}
gl.g_right = gl.g_left + x2;
gl.g_left = gl.g_left + x1;
gl.g_up = gl.g_down + y2;
gl.g_down = gl.g_down + y1;
gl.needsUpdate = true;
e.preventDefault();
}