From 2d6c51ac773e0a2c850d5111d34e6e508697dd5a Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 10 Mar 2015 13:32:56 -0700 Subject: [PATCH 1/2] Detect moving objects before catching them --- examples/controllers/hydra/toyball.js | 49 ++++++++++++++------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/examples/controllers/hydra/toyball.js b/examples/controllers/hydra/toyball.js index 89085fad19..57ad7d8fb0 100644 --- a/examples/controllers/hydra/toyball.js +++ b/examples/controllers/hydra/toyball.js @@ -48,10 +48,10 @@ var rightHandEntity = false; var newSound = SoundCache.getSound("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/throw.raw"); var catchSound = SoundCache.getSound("https://dl.dropboxusercontent.com/u/1864924/hifi-sounds/catch.raw"); var throwSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Switches%20and%20sliders/slider%20-%20whoosh1.raw"); -var targetRadius = 1.0; +var targetRadius = 0.25; -var wantDebugging = false; +var wantDebugging = true; function debugPrint(message) { if (wantDebugging) { print(message); @@ -120,30 +120,33 @@ function checkControllerSide(whichSide) { var closestEntity = Entities.findClosestEntity(palmPosition, targetRadius); if (closestEntity.isKnownID) { + var foundProperties = Entities.getEntityProperties(closestEntity); + if (Vec3.length(foundProperties.velocity) > 0.0) { - debugPrint(handMessage + " HAND- CAUGHT SOMETHING!!"); + debugPrint(handMessage + " - Catching a moving object!"); - if (whichSide == LEFT_PALM) { - leftBallAlreadyInHand = true; - leftHandEntity = closestEntity; - } else { - rightBallAlreadyInHand = true; - rightHandEntity = closestEntity; + if (whichSide == LEFT_PALM) { + leftBallAlreadyInHand = true; + leftHandEntity = closestEntity; + } else { + rightBallAlreadyInHand = true; + rightHandEntity = closestEntity; + } + var ballPosition = getBallHoldPosition(whichSide); + var properties = { position: { x: ballPosition.x, + y: ballPosition.y, + z: ballPosition.z }, + rotation: palmRotation, + color: HELD_COLOR, + velocity : { x: 0, y: 0, z: 0}, + gravity: { x: 0, y: 0, z: 0} + }; + Entities.editEntity(closestEntity, properties); + + Audio.playSound(catchSound, { position: ballPosition }); + + return; // exit early } - var ballPosition = getBallHoldPosition(whichSide); - var properties = { position: { x: ballPosition.x, - y: ballPosition.y, - z: ballPosition.z }, - rotation: palmRotation, - color: HELD_COLOR, - velocity : { x: 0, y: 0, z: 0}, - gravity: { x: 0, y: 0, z: 0} - }; - Entities.editEntity(closestEntity, properties); - - Audio.playSound(catchSound, { position: ballPosition }); - - return; // exit early } } From 182a1a726dfde2b759ecb9ada3a1f9ff2857a2f8 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 10 Mar 2015 13:34:16 -0700 Subject: [PATCH 2/2] remove debug --- examples/controllers/hydra/toyball.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/controllers/hydra/toyball.js b/examples/controllers/hydra/toyball.js index 57ad7d8fb0..83dcf2937d 100644 --- a/examples/controllers/hydra/toyball.js +++ b/examples/controllers/hydra/toyball.js @@ -51,7 +51,7 @@ var throwSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Switches%20and var targetRadius = 0.25; -var wantDebugging = true; +var wantDebugging = false; function debugPrint(message) { if (wantDebugging) { print(message);