-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouseInteractionMethods.js
More file actions
45 lines (38 loc) · 894 Bytes
/
mouseInteractionMethods.js
File metadata and controls
45 lines (38 loc) · 894 Bytes
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
function mouseMoved() {
attractor.handleHover(mouseX, mouseY);
}
function mousePressed() {
attractor.handlePress(mouseX, mouseY);
}
function mouseDragged() {
attractor.handleHover(mouseX, mouseY);
attractor.handleDrag(mouseX, mouseY);
}
function mouseReleased() {
attractor.stopDragging();
}
handlePress(mx, my) {
let d = dist(mx, my, this.position.x, this.position.y);
if (d < this.mass) {
this.dragging = true;
this.dragOffset.x = this.position.x - mx;
this.dragOffset.y = this.position.y - my;
}
}
handleHover(mx, my) {
let d = dist(mx, my, this.position.x, this.position.y);
if (d < this.mass) {
this.rollover = true;
} else {
this.rollover = false;
}
}
stopDragging() {
this.dragging = false;
}
handleDrag(mx, my) {
if (this.dragging) {
this.position.x = mx + this.dragOffset.x;
this.position.y = my + this.dragOffset.y;
}
}