Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Extract pinch gesture constants
  • Loading branch information
cesmoak committed Oct 4, 2020
commit cd0e7a2b875c77d0ced33a29bc292beaa0efd387
14 changes: 9 additions & 5 deletions src/components/hand-tracking-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ var BONE_MAPPING = [
'pinky_null'
];

var PINCH_START_DISTANCE = 0.015;
var PINCH_END_DISTANCE = 0.03;
var PINCH_POSITION_INTERPOLATION = 0.5;

/**
* Controls for hand tracking
*/
Expand Down Expand Up @@ -217,22 +221,22 @@ module.exports.Component = registerComponent('hand-tracking-controls', {

var distance = indexTipPosition.distanceTo(thumbTipPosition);

if (distance < 0.015 && this.isPinched === false) {
if (distance < PINCH_START_DISTANCE && this.isPinched === false) {
this.isPinched = true;
this.pinchEventDetail.position.copy(indexTipPosition).lerp(thumbTipPosition, 0.5);
this.pinchEventDetail.position.copy(indexTipPosition).lerp(thumbTipPosition, PINCH_POSITION_INTERPOLATION);
this.pinchEventDetail.position.y += 1.5;
this.el.emit('pinchstarted', this.pinchEventDetail);
}

if (distance > 0.03 && this.isPinched === true) {
if (distance > PINCH_END_DISTANCE && this.isPinched === true) {
this.isPinched = false;
this.pinchEventDetail.position.copy(indexTipPosition).lerp(thumbTipPosition, 0.5);
this.pinchEventDetail.position.copy(indexTipPosition).lerp(thumbTipPosition, PINCH_POSITION_INTERPOLATION);
this.pinchEventDetail.position.y += 1.5;
this.el.emit('pinchended', this.pinchEventDetail);
}

if (this.isPinched) {
this.pinchEventDetail.position.copy(indexTipPosition).lerp(thumbTipPosition, 0.5);
this.pinchEventDetail.position.copy(indexTipPosition).lerp(thumbTipPosition, PINCH_POSITION_INTERPOLATION);
this.pinchEventDetail.position.y += 1.5;
this.el.emit('pinchmoved', this.pinchEventDetail);
}
Expand Down