-
Notifications
You must be signed in to change notification settings - Fork 0
/
Translate.pde
68 lines (60 loc) · 2.03 KB
/
Translate.pde
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
class Translate {
// Vector objects to keep track of translation, mouse movement, and start position
Vector translation;
Vector mouseStart;
Vector mouseEnd;
Vector mouseChange;
Vector translationStart;
// boolean variable to check if the object is currently moving
boolean moving;
// constructor to initialize the class variables
Translate() {
translation = new Vector(width/2, height/2);
mouseStart = new Vector(0, 0);
mouseEnd = new Vector(0, 0);
mouseChange = new Vector(0, 0);
translationStart = new Vector( 0, 0);
moving = false;
}
// method to update the translation based on the mouse movement
void update() {
mouseEnd.setVector(mouseX, mouseY);
if (moving) {
mouseChange = new Vector(mouseStart.x - mouseEnd.x, mouseStart.y - mouseEnd.y);
translation.setVector(translationStart.x - mouseChange.x, translationStart.y - mouseChange.y);
}
}
// method to check if the left mouse button is pressed
void mousePressedLogic() {
if (keyPressed && !moving) {
moving = true;
startMoving();
}
}
// method to check if the left mouse button is released
void mouseReleasedLogic() {
moving = false;
}
// method to check if the control key and left mouse button are pressed
void keyPressedLogic(Integer kCode) {
if (mousePressed && !moving && (kCode == 157 || kCode == 17)) {
moving = true;
startMoving();
}
}
// method to check if the control key is released
void keyReleasedLogic(Integer kCode) {
if (moving && (kCode == 157 || kCode == 17)) {
moving = false;
}
}
// method to set the start position of the mouse and translation when moving starts
void startMoving() {
showTrails = false; //stop showing the trails
for(sObject o : particles) { //for every particle
o.history.clear(); //clear the history
}
mouseStart.setVector(mouseX, mouseY);
translationStart.setVector(t.translation.getX(), t.translation.getY());
}
}