From 7a12a4d58e2045d6f8053f28f73215d0a092b31e Mon Sep 17 00:00:00 2001 From: Eric Levin Date: Thu, 14 May 2015 17:00:40 -0700 Subject: [PATCH] added support for both right and left hydras for hydra scripts, and made picking accurate --- examples/controllers/hydra/hydraGrab.js | 8 ++++++-- examples/example/games/hydraGrabHockey.js | 10 +++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/examples/controllers/hydra/hydraGrab.js b/examples/controllers/hydra/hydraGrab.js index 9e49838d88..34484eb9e8 100644 --- a/examples/controllers/hydra/hydraGrab.js +++ b/examples/controllers/hydra/hydraGrab.js @@ -18,6 +18,7 @@ var entityProps, currentPosition, currentVelocity, currentRotation, distanceToTarget, velocityTowardTarget, desiredVelocity; var addedVelocity, newVelocity, angularVelocity, dT, cameraEntityDistance; +var LEFT = 0; var RIGHT = 1; var LASER_WIDTH = 3; var LASER_COLOR = { @@ -50,7 +51,7 @@ var grabSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/s var releaseSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/ReleaseClamp.wav"); function getRayIntersection(pickRay) { - var intersection = Entities.findRayIntersection(pickRay); + var intersection = Entities.findRayIntersection(pickRay, true); return intersection; } @@ -194,7 +195,7 @@ function controller(side) { origin: this.palmPosition, direction: Vec3.normalize(Vec3.subtract(this.tipPosition, this.palmPosition)) }; - var intersection = getRayIntersection(pickRay); + var intersection = getRayIntersection(pickRay, true); if (intersection.intersects && intersection.properties.collisionsWillMove) { this.laserWasHovered = true; if (this.triggerHeld && !this.grabbing) { @@ -286,10 +287,12 @@ function controller(side) { function update(deltaTime) { rightController.update(deltaTime); + leftController.update(deltaTime); } function scriptEnding() { rightController.cleanup(); + leftController.cleanup(); } function vectorIsZero(v) { @@ -297,6 +300,7 @@ function vectorIsZero(v) { } var rightController = new controller(RIGHT); +var leftController = new controller(LEFT); Script.update.connect(update); diff --git a/examples/example/games/hydraGrabHockey.js b/examples/example/games/hydraGrabHockey.js index 9834dbad9f..b9f760fa08 100644 --- a/examples/example/games/hydraGrabHockey.js +++ b/examples/example/games/hydraGrabHockey.js @@ -16,8 +16,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // - var addedVelocity, newVelocity, angularVelocity, dT, cameraEntityDistance; +var LEFT = 0; var RIGHT = 1; var LASER_WIDTH = 3; var LASER_COLOR = { @@ -50,10 +50,11 @@ var grabSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/s var releaseSound = SoundCache.getSound("https://hifi-public.s3.amazonaws.com/eric/sounds/ReleaseClamp.wav"); function getRayIntersection(pickRay) { - var intersection = Entities.findRayIntersection(pickRay); + var intersection = Entities.findRayIntersection(pickRay, true); return intersection; } + function controller(side) { this.triggerHeld = false; this.triggerThreshold = 0.9; @@ -190,7 +191,7 @@ function controller(side) { origin: this.palmPosition, direction: Vec3.normalize(Vec3.subtract(this.tipPosition, this.palmPosition)) }; - var intersection = getRayIntersection(pickRay); + var intersection = getRayIntersection(pickRay, true); if (intersection.intersects && intersection.properties.collisionsWillMove) { this.laserWasHovered = true; if (this.triggerHeld && !this.grabbing) { @@ -282,10 +283,12 @@ function controller(side) { function update(deltaTime) { rightController.update(deltaTime); + leftController.update(deltaTime); } function scriptEnding() { rightController.cleanup(); + leftController.cleanup(); } function vectorIsZero(v) { @@ -293,6 +296,7 @@ function vectorIsZero(v) { } var rightController = new controller(RIGHT); +var leftController = new controller(LEFT); Script.update.connect(update);