From f7193dbb97c170519bc2e024b1b78a4203cda303 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 15 Sep 2015 16:55:51 -0700 Subject: [PATCH] if the intersection distance is small, use grab-mode rather than distant-grab-mode --- examples/controllers/handControllerGrab.js | 33 ++++++++++++++-------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/examples/controllers/handControllerGrab.js b/examples/controllers/handControllerGrab.js index 82fd847f25..f38d4a1008 100644 --- a/examples/controllers/handControllerGrab.js +++ b/examples/controllers/handControllerGrab.js @@ -97,8 +97,8 @@ function controller(side, triggerAction, pullAction, hand) { controller.prototype.updateLine = function() { if (this.pointer != null) { - if (Entities.getEntityProperties(this.pointer).id != this.poitner) { - this.pointer == null; + if (Entities.getEntityProperties(this.pointer).id != this.pointer) { + this.pointer = null; } } @@ -118,7 +118,6 @@ controller.prototype.updateLine = function() { }); } - var handPosition = this.getHandPosition(); var direction = Quat.getUp(this.getHandRotation()); @@ -172,14 +171,26 @@ controller.prototype.checkForIntersections = function(origin, direction) { if (intersection.intersects && intersection.properties.collisionsWillMove === 1) { var handPosition = Controller.getSpatialControlPosition(this.palm); this.distanceToEntity = Vec3.distance(handPosition, intersection.properties.position); - Entities.editEntity(this.pointer, { - linePoints: [ - ZERO_VEC, - Vec3.multiply(direction, this.distanceToEntity) - ] - }); - this.grabbedEntity = intersection.entityID; - return true; + var intersectionDistance = Vec3.distance(handPosition, intersection.intersection); + + if (intersectionDistance < 0.6) { + //We are grabbing an entity, so let it know we've grabbed it + this.grabbedEntity = intersection.entityID; + this.activateEntity(this.grabbedEntity); + this.hidePointer(); + this.shouldDisplayLine = false; + this.grabEntity(); + return true; + } else { + Entities.editEntity(this.pointer, { + linePoints: [ + ZERO_VEC, + Vec3.multiply(direction, this.distanceToEntity) + ] + }); + this.grabbedEntity = intersection.entityID; + return true; + } } return false; }