From a3db9ae726efe37e4da4e7909a702ca107c37801 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Fri, 30 Jun 2017 15:40:42 +0100 Subject: [PATCH 01/11] Begin Rocket Hands branch --- scripts/developer/rockethands.js | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 scripts/developer/rockethands.js diff --git a/scripts/developer/rockethands.js b/scripts/developer/rockethands.js new file mode 100644 index 0000000000..b68d6cc9c6 --- /dev/null +++ b/scripts/developer/rockethands.js @@ -0,0 +1,35 @@ +"use strict"; + +// +// rockethands.js +// system +// +// Created by Cain Kilgore on 30/06/2017 +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +(function() { + function logToConsole(message) { + console.log("[rockethands.js] " + message); + } + + logToConsole("Rockethands.js script is now active."); + + Script.setInterval(function() { + if(Controller.Hardware.Vive) { + var rightHand = Controller.getPoseValue(Controller.Hardware.Vive.RightHand).rotation.y; + + // logToConsole("Y VALUE: " + rightHand); + if(rightHand < -0.1 && rightHand > -0.4) { + logToConsole("Pointing down.. eye position: " + Camera.getOrientation().x + ", " + Camera.getOrientation().y + ", " + Camera.getOrientation().z + " - we have liftoff - I think!"); + MyAvatar.motorReferenceFrame = "world"; + // MyAvatar.motorVelocity = {x: Camera.getOrientation().x, y: Camera.getOrientation().y*3, z: Camera.getOrientation().z}; + MyAvatar.motorVelocity = Camera.getOrientation()*3; + MyAvatar.motorTimescale = 1.0; + } + } + }, 1000); +}()); From e0120ebf3011a3d5cb477c437ba076d8e9d983b2 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Sun, 2 Jul 2017 03:20:07 +0100 Subject: [PATCH 02/11] Rocket Hands --- .../marketplace/rocketHands/rockethands.js | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 unpublishedScripts/marketplace/rocketHands/rockethands.js diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js new file mode 100644 index 0000000000..678e51565d --- /dev/null +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -0,0 +1,43 @@ +"use strict"; + +/* + rockethands.js + system + + Created by Cain Kilgore on 30/06/2017 + Copyright 2017 High Fidelity, Inc. + + Distributed under the Apache License, Version 2.0. + See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +*/ + +(function() { + var isRocketing = false; + + Script.setInterval(function() { + if (Controller.Hardware.Vive) { + var rightHand = Controller.getPoseValue(Controller.Hardware.Vive.RightHand); + var getHip = MyAvatar.getJointPosition("Hips"); + var worldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); + + if ((worldControllerPos.y > (getHip.y - 0.1)) && (worldControllerPos.y < (getHip.y + 0.1))) { + if (rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) { + isRocketing = true; + Controller.triggerHapticPulse(0.1, 120, 2); + MyAvatar.motorReferenceFrame = "world"; + var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); + if(!MyAvatar.isFlying()) { + moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); + } + MyAvatar.motorVelocity = moveVector; + MyAvatar.motorTimescale = 1.0; + } else { + if (isRocketing) { + MyAvatar.motorVelocity = 0; + isRocketing = false; + } + } + } + } + }, 100); +}()); \ No newline at end of file From a693a61ec891dd3f44fcd2f1d9e06eabb7353f04 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Sun, 2 Jul 2017 03:20:54 +0100 Subject: [PATCH 03/11] Cleanup --- scripts/developer/rockethands.js | 35 -------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 scripts/developer/rockethands.js diff --git a/scripts/developer/rockethands.js b/scripts/developer/rockethands.js deleted file mode 100644 index b68d6cc9c6..0000000000 --- a/scripts/developer/rockethands.js +++ /dev/null @@ -1,35 +0,0 @@ -"use strict"; - -// -// rockethands.js -// system -// -// Created by Cain Kilgore on 30/06/2017 -// Copyright 2017 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -(function() { - function logToConsole(message) { - console.log("[rockethands.js] " + message); - } - - logToConsole("Rockethands.js script is now active."); - - Script.setInterval(function() { - if(Controller.Hardware.Vive) { - var rightHand = Controller.getPoseValue(Controller.Hardware.Vive.RightHand).rotation.y; - - // logToConsole("Y VALUE: " + rightHand); - if(rightHand < -0.1 && rightHand > -0.4) { - logToConsole("Pointing down.. eye position: " + Camera.getOrientation().x + ", " + Camera.getOrientation().y + ", " + Camera.getOrientation().z + " - we have liftoff - I think!"); - MyAvatar.motorReferenceFrame = "world"; - // MyAvatar.motorVelocity = {x: Camera.getOrientation().x, y: Camera.getOrientation().y*3, z: Camera.getOrientation().z}; - MyAvatar.motorVelocity = Camera.getOrientation()*3; - MyAvatar.motorTimescale = 1.0; - } - } - }, 1000); -}()); From 44f0b8bd6043484d9aadb14e2e5c2171e1935f98 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Sun, 2 Jul 2017 11:41:33 +0100 Subject: [PATCH 04/11] Support for Oculus & Vive - cleaned up some code, using Script.connect instead of setInterval --- .../marketplace/rocketHands/rockethands.js | 40 ++++++++++++------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index 678e51565d..a4a4cf777c 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -13,15 +13,18 @@ (function() { var isRocketing = false; + MyAvatar.motorVelocity = 0; - Script.setInterval(function() { - if (Controller.Hardware.Vive) { - var rightHand = Controller.getPoseValue(Controller.Hardware.Vive.RightHand); - var getHip = MyAvatar.getJointPosition("Hips"); - var worldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); - - if ((worldControllerPos.y > (getHip.y - 0.1)) && (worldControllerPos.y < (getHip.y + 0.1))) { - if (rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) { + function checkRocketting() { + if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) { + var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand); + var rightHand = Controller.getPoseValue(Controller.Standard.RightHand); + var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); + var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); + var hipPosition = MyAvatar.getJointPosition("Hips"); + + if ((leftWorldControllerPos.y > (hipPosition.y - 0.1)) && (leftWorldControllerPos.y < (hipPosition.y + 0.1)) && rightWorldControllerPos.y > (hipPosition.y - 0.1) && (rightWorldControllerPos.y < (hipPosition.y + 0.1))) { + if (leftHand.rotation.y < 0.25 && leftHand.rotation.y > -0.25 && rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) { isRocketing = true; Controller.triggerHapticPulse(0.1, 120, 2); MyAvatar.motorReferenceFrame = "world"; @@ -31,13 +34,20 @@ } MyAvatar.motorVelocity = moveVector; MyAvatar.motorTimescale = 1.0; - } else { - if (isRocketing) { - MyAvatar.motorVelocity = 0; - isRocketing = false; - } - } + } else { + if (isRocketing) { + MyAvatar.motorVelocity = 0; + isRocketing = false; + } + } + } else { + if (isRocketing) { + MyAvatar.motorVelocity = 0; + isRocketing = false; + } } } - }, 100); + }; + + Script.update.connect(checkRocketting); }()); \ No newline at end of file From 7d382d9da0bbd70dc3e726fff4ef52cc1e0af85d Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 17:47:54 +0100 Subject: [PATCH 05/11] Fixed spelling, added is in HMD Check, removed Haptic Feedback as it wasn't part of the WL --- .../marketplace/rocketHands/rockethands.js | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index a4a4cf777c..0e8746add1 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -12,39 +12,45 @@ */ (function() { - var isRocketing = false; + var isRocketting = false; MyAvatar.motorVelocity = 0; function checkRocketting() { - if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) { - var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand); - var rightHand = Controller.getPoseValue(Controller.Standard.RightHand); - var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); - var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); - var hipPosition = MyAvatar.getJointPosition("Hips"); - - if ((leftWorldControllerPos.y > (hipPosition.y - 0.1)) && (leftWorldControllerPos.y < (hipPosition.y + 0.1)) && rightWorldControllerPos.y > (hipPosition.y - 0.1) && (rightWorldControllerPos.y < (hipPosition.y + 0.1))) { - if (leftHand.rotation.y < 0.25 && leftHand.rotation.y > -0.25 && rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) { - isRocketing = true; - Controller.triggerHapticPulse(0.1, 120, 2); - MyAvatar.motorReferenceFrame = "world"; - var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); - if(!MyAvatar.isFlying()) { - moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); + if (HMD.active) { + if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) { + var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand); + var rightHand = Controller.getPoseValue(Controller.Standard.RightHand); + var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); + var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); + var hipPosition = MyAvatar.getJointPosition("Hips"); + + if ((leftWorldControllerPos.y > (hipPosition.y - 0.1)) && (leftWorldControllerPos.y < (hipPosition.y + 0.1)) && rightWorldControllerPos.y > (hipPosition.y - 0.1) && (rightWorldControllerPos.y < (hipPosition.y + 0.1))) { + if (leftHand.rotation.y < 0.25 && leftHand.rotation.y > -0.25 && rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) { + isRocketting = true; + MyAvatar.motorReferenceFrame = "world"; + var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); + if(!MyAvatar.isFlying()) { + moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); + } + MyAvatar.motorVelocity = moveVector; + MyAvatar.motorTimescale = 1.0; + } else { + if (isRocketting) { + MyAvatar.motorVelocity = 0; + isRocketting = false; + } } - MyAvatar.motorVelocity = moveVector; - MyAvatar.motorTimescale = 1.0; } else { - if (isRocketing) { + if (isRocketting) { MyAvatar.motorVelocity = 0; - isRocketing = false; + isRocketting = false; } } - } else { - if (isRocketing) { - MyAvatar.motorVelocity = 0; - isRocketing = false; - } + } + } else { + if(isRocketting) { + MyAvatar.motorVelocity = 0; + isRocketting = false; } } }; From 2c53b5b372312ea7ec800a1d4721ec48a2b1c7d7 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 19:09:54 +0100 Subject: [PATCH 06/11] QA Cleanup --- .../marketplace/rocketHands/rockethands.js | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index 0e8746add1..f8a22be579 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -12,10 +12,9 @@ */ (function() { - var isRocketting = false; - MyAvatar.motorVelocity = 0; + var isRocketing = false; - function checkRocketting() { + function checkRocketing() { if (HMD.active) { if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) { var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand); @@ -23,37 +22,36 @@ var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); var hipPosition = MyAvatar.getJointPosition("Hips"); + var controllerHipThreshold = 0.1; + var controllerRotationThreshold = 0.25; - if ((leftWorldControllerPos.y > (hipPosition.y - 0.1)) && (leftWorldControllerPos.y < (hipPosition.y + 0.1)) && rightWorldControllerPos.y > (hipPosition.y - 0.1) && (rightWorldControllerPos.y < (hipPosition.y + 0.1))) { - if (leftHand.rotation.y < 0.25 && leftHand.rotation.y > -0.25 && rightHand.rotation.y < 0.25 && rightHand.rotation.y > -0.25) { - isRocketting = true; + if ((leftWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && (leftWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) && rightWorldControllerPos.y > (hipPosition.y - controllerHipThreshold) && (rightWorldControllerPos.y < (hipPosition.y + controllerHipThreshold))) { + if (leftHand.rotation.y < controllerRotationThreshold && leftHand.rotation.y > -controllerRotationThreshold && rightHand.rotation.y < controllerRotationThreshold && rightHand.rotation.y > -controllerRotationThreshold) { + isRocketing = true; MyAvatar.motorReferenceFrame = "world"; var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); - if(!MyAvatar.isFlying()) { + if (!MyAvatar.isFlying()) { moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); } MyAvatar.motorVelocity = moveVector; MyAvatar.motorTimescale = 1.0; } else { - if (isRocketting) { - MyAvatar.motorVelocity = 0; - isRocketting = false; - } + checkCanStopRocketing(); } } else { - if (isRocketting) { - MyAvatar.motorVelocity = 0; - isRocketting = false; - } + checkCanStopRocketing(); } } } else { - if(isRocketting) { - MyAvatar.motorVelocity = 0; - isRocketting = false; - } + checkCanStopRocketing(); } }; - Script.update.connect(checkRocketting); + function checkCanStopRocketing() { + if(isRocketing) { + MyAvatar.motorVelocity = 0; + isRocketing = false; + } + } + Script.update.connect(checkRocketing); }()); \ No newline at end of file From 44624c5fab70acde0af6e94c95f2b2bcf5465e58 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 19:11:57 +0100 Subject: [PATCH 07/11] space --- unpublishedScripts/marketplace/rocketHands/rockethands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index f8a22be579..e7d60d47a6 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -48,7 +48,7 @@ }; function checkCanStopRocketing() { - if(isRocketing) { + if (isRocketing) { MyAvatar.motorVelocity = 0; isRocketing = false; } From 5f600b4ea96b01efed573ec319f6a225988b5362 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 19:31:41 +0100 Subject: [PATCH 08/11] Cleanup again --- .../marketplace/rocketHands/rockethands.js | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index e7d60d47a6..da80a84432 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -22,28 +22,34 @@ var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); var hipPosition = MyAvatar.getJointPosition("Hips"); - var controllerHipThreshold = 0.1; - var controllerRotationThreshold = 0.25; + var controllerHipThreshold = 0.1; // In Meters. Experimentally determined. Used to figure out if user's hands are "close enough" to their hips. + var controllerRotationThreshold = 0.25; // In Radians. Experimentally determined. Used to figure out if user's hands are within a rotation threshold. - if ((leftWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && (leftWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) && rightWorldControllerPos.y > (hipPosition.y - controllerHipThreshold) && (rightWorldControllerPos.y < (hipPosition.y + controllerHipThreshold))) { - if (leftHand.rotation.y < controllerRotationThreshold && leftHand.rotation.y > -controllerRotationThreshold && rightHand.rotation.y < controllerRotationThreshold && rightHand.rotation.y > -controllerRotationThreshold) { - isRocketing = true; - MyAvatar.motorReferenceFrame = "world"; - var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); - if (!MyAvatar.isFlying()) { - moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); + if ((leftWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && + (leftWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) && + (rightWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && + (rightWorldControllerPos.y < (hipPosition.y + controllerHipThreshold))) { + if ((leftHand.rotation.y < controllerRotationThreshold) && + (leftHand.rotation.y > -controllerRotationThreshold) && + (rightHand.rotation.y < controllerRotationThreshold) && + (rightHand.rotation.y > -controllerRotationThreshold)) { + isRocketing = true; + MyAvatar.motorReferenceFrame = "world"; + var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); + if (!MyAvatar.isFlying()) { + moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); + } + MyAvatar.motorVelocity = moveVector; + MyAvatar.motorTimescale = 1.0; + } else { + checkCanStopRocketing(); } - MyAvatar.motorVelocity = moveVector; - MyAvatar.motorTimescale = 1.0; } else { checkCanStopRocketing(); } - } else { - checkCanStopRocketing(); } - } - } else { - checkCanStopRocketing(); + } else { + checkCanStopRocketing(); } }; From bfcddcf3b7ecaf1b95361ebd44b4831a18f40194 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 19:53:29 +0100 Subject: [PATCH 09/11] Cleaned up the code, created a function to check if the hands are in the right position. --- .../marketplace/rocketHands/rockethands.js | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index da80a84432..d5dfe48ea0 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -17,39 +17,23 @@ function checkRocketing() { if (HMD.active) { if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) { - var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand); - var rightHand = Controller.getPoseValue(Controller.Standard.RightHand); - var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); - var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); - var hipPosition = MyAvatar.getJointPosition("Hips"); - var controllerHipThreshold = 0.1; // In Meters. Experimentally determined. Used to figure out if user's hands are "close enough" to their hips. - var controllerRotationThreshold = 0.25; // In Radians. Experimentally determined. Used to figure out if user's hands are within a rotation threshold. - - if ((leftWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && - (leftWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) && - (rightWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && - (rightWorldControllerPos.y < (hipPosition.y + controllerHipThreshold))) { - if ((leftHand.rotation.y < controllerRotationThreshold) && - (leftHand.rotation.y > -controllerRotationThreshold) && - (rightHand.rotation.y < controllerRotationThreshold) && - (rightHand.rotation.y > -controllerRotationThreshold)) { - isRocketing = true; - MyAvatar.motorReferenceFrame = "world"; - var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); - if (!MyAvatar.isFlying()) { - moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); - } - MyAvatar.motorVelocity = moveVector; - MyAvatar.motorTimescale = 1.0; - } else { - checkCanStopRocketing(); - } - } else { - checkCanStopRocketing(); + if (canRocket()) { + isRocketing = true; + MyAvatar.motorReferenceFrame = "world"; + var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); + if (!MyAvatar.isFlying()) { + moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); } + MyAvatar.motorVelocity = moveVector; + MyAvatar.motorTimescale = 1.0; + } else { + checkCanStopRocketing(); } } else { checkCanStopRocketing(); + } + } else { + checkCanStopRocketing(); } }; @@ -59,5 +43,25 @@ isRocketing = false; } } + + function canRocket() { + var leftHand = Controller.getPoseValue(Controller.Standard.LeftHand); + var rightHand = Controller.getPoseValue(Controller.Standard.RightHand); + var leftWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, leftHand.translation)); + var rightWorldControllerPos = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, rightHand.translation)); + var hipPosition = MyAvatar.getJointPosition("Hips"); + var controllerHipThreshold = 0.1; // In Meters. Experimentally determined. Used to figure out if user's hands are "close enough" to their hips. + var controllerRotationThreshold = 0.25; // In Radians. Experimentally determined. Used to figure out if user's hands are within a rotation threshold. + + return ((leftWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && + (leftWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) && + (rightWorldControllerPos.y > (hipPosition.y - controllerHipThreshold)) && + (rightWorldControllerPos.y < (hipPosition.y + controllerHipThreshold)) && + leftHand.rotation.y < controllerRotationThreshold && + leftHand.rotation.y > -controllerRotationThreshold && + rightHand.rotation.y < controllerRotationThreshold && + rightHand.rotation.y > -controllerRotationThreshold); + } + Script.update.connect(checkRocketing); }()); \ No newline at end of file From 1c5923914b4cf5bd99388e8a7a39fb459bd77a2d Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 19:58:26 +0100 Subject: [PATCH 10/11] Combining three if statements into one! --- .../marketplace/rocketHands/rockethands.js | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index d5dfe48ea0..1025dcb0aa 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -15,23 +15,15 @@ var isRocketing = false; function checkRocketing() { - if (HMD.active) { - if (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) { - if (canRocket()) { - isRocketing = true; - MyAvatar.motorReferenceFrame = "world"; - var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); - if (!MyAvatar.isFlying()) { - moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); - } - MyAvatar.motorVelocity = moveVector; - MyAvatar.motorTimescale = 1.0; - } else { - checkCanStopRocketing(); - } - } else { - checkCanStopRocketing(); + if (HMD.active && (Controller.Hardware.Vive || Controller.Hardware.OculusTouch) && canRocket()) { + isRocketing = true; + MyAvatar.motorReferenceFrame = "world"; + var moveVector = Vec3.multiply(Quat.getFront(Camera.getOrientation()), 10); + if (!MyAvatar.isFlying()) { + moveVector = Vec3.sum(moveVector, {x: 0, y: 1, z: 0}); } + MyAvatar.motorVelocity = moveVector; + MyAvatar.motorTimescale = 1.0; } else { checkCanStopRocketing(); } From eddb7a349c18334c56a27f24d90d609ff258cb00 Mon Sep 17 00:00:00 2001 From: Cain Kilgore Date: Mon, 3 Jul 2017 20:01:01 +0100 Subject: [PATCH 11/11] Boilerplate --- unpublishedScripts/marketplace/rocketHands/rockethands.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unpublishedScripts/marketplace/rocketHands/rockethands.js b/unpublishedScripts/marketplace/rocketHands/rockethands.js index 1025dcb0aa..672dcf2540 100644 --- a/unpublishedScripts/marketplace/rocketHands/rockethands.js +++ b/unpublishedScripts/marketplace/rocketHands/rockethands.js @@ -2,7 +2,7 @@ /* rockethands.js - system + unpublishedScripts/marketplace/rocketHands/rockethands.js Created by Cain Kilgore on 30/06/2017 Copyright 2017 High Fidelity, Inc.