-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.pde
75 lines (66 loc) · 1.79 KB
/
Node.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
69
70
71
72
73
74
75
class Node extends PVector {
// PVector docs: https://processing.org/reference/PVector.html
int[] id; //[x, y]
float initX, initY, initZ;
PVector initVector;
float recoverSpeed = 1;
boolean recovering = false;
Node(int[] id, float x, float y, float z) {
super(x, y, z);
this.id = id;
this.initX = x;
this.initY = y;
this.initZ = z;
initVector = new PVector(initX, initY, initZ);
}
void getVertex() {
vertex(this.x, this.y, this.z);
}
void resetNode() {
this.set(this.initVector);
}
void recover() {
float vx = 0;
float vy = 0;
float vz = 0;
if (this.x != this.initX) {
vx = _getAxisRecoverValue(this.x, this.initX);
}
if (this.y != this.initY) {
vy = _getAxisRecoverValue(this.y, this.initY);
}
if (this.z != this.initZ) {
vz = _getAxisRecoverValue(this.z, this.initZ);
}
PVector v = new PVector(vx, vy, vz);
this.add(v);
if (vx == 0 && vy == 0 && vz == 0) {
this.recovering = false;
}
else {
this.recovering = true;
}
}
float _getAxisRecoverValue(float value, float initValue) {
float distance = value - initValue;
if (distance > 0) {
if (distance >= this.recoverSpeed) {
return -this.recoverSpeed;
}
else {
return distance;
}
}
else{
if (distance <= -this.recoverSpeed) {
return this.recoverSpeed;
}
else {
return -distance;
}
}
}
void changeRecoverSpeed(float speed) {
this.recoverSpeed = speed;
}
}