-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dataset.pde
52 lines (41 loc) · 1.43 KB
/
Dataset.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
// Object containing the spacial information of one frame
class Dataset {
boolean tracked;
int time;
int id;
PVector position = new PVector();
float distance;
float distanceXY;
String movementX;
String movementY;
float velocity;
float velocityXY;
Dataset(boolean _leap_hand_isset, int _id, int _time, float _posX, float _posY, float _posZ) {
this.tracked = _leap_hand_isset;
this.id = _id;
this.time = _time;
this.position.set(_posX, _posY, _posZ);
if (datasets.size() > 0 && datasetPrev.tracked) {
// Get the distance from the last tracked position
distance = PVector.dist(this.position, datasetPrev.position);
distanceXY = dist(this.position.x, this.position.y, datasetPrev.position.x, datasetPrev.position.y);
// Get the direction of the movement
float differenceX = datasetPrev.position.x - this.position.x;
float differenceY = datasetPrev.position.y - this.position.y;
if (differenceX > 2) {
movementX = "left";
} else if (differenceX < -2) {
movementX = "right";
}
if (differenceY > 2) {
movementY = "up";
} else if (differenceY < -2) {
movementY = "down";
}
// Get the velocity of the movement
int timeSinceLastDataset = this.time - datasetPrev.time;
this.velocity = this.distance / timeSinceLastDataset;
this.velocityXY = this.distanceXY / timeSinceLastDataset;
}
}
}