-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhand-tracking-gestures.js
43 lines (37 loc) · 1.47 KB
/
hand-tracking-gestures.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
AFRAME.registerComponent('hand-tracking-gestures', {
dependencies: ['hand-tracking'],
init: function() {
this.handTracking = this.el.components['hand-tracking'];
this.isPinched = false;
},
tick: function() {
if (this.handTracking.hand != null) {
if (this.pinchCheck(this.handTracking.hand)) {
if (this.isPinched == false) {
this.isPinched = true;
this.el.emit('started-pinch', {
joint: this.handTracking.hand[XRHand.INDEX_PHALANX_TIP].object3D
});
}
}
if (this.pinchReleaseCheck(this.handTracking.hand)) {
if (this.isPinched == true) {
this.isPinched = false;
this.el.emit('ended-pinch')
}
}
}
},
pinchCheck: function (hand) {
const indexTip = hand[XRHand.INDEX_PHALANX_TIP].object3D;
const thumbTip = hand[XRHand.THUMB_PHALANX_TIP].object3D;
const distance = indexTip.position.distanceTo(thumbTip.position);
return distance < 0.01;
},
pinchReleaseCheck: function (hand) {
const indexTip = hand[XRHand.INDEX_PHALANX_TIP].object3D;
const thumbTip = hand[XRHand.THUMB_PHALANX_TIP].object3D;
const distance = indexTip.position.distanceTo(thumbTip.position);
return distance > 0.03;
},
});