From f40e46957bea804287ca1925de2df531976e90dc Mon Sep 17 00:00:00 2001 From: AlessandroSigna Date: Tue, 10 Nov 2015 17:18:34 -0800 Subject: [PATCH 1/2] handControlledHead.js added --- .../avatarcontrol/handControlledHead.js | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 examples/example/avatarcontrol/handControlledHead.js diff --git a/examples/example/avatarcontrol/handControlledHead.js b/examples/example/avatarcontrol/handControlledHead.js new file mode 100644 index 0000000000..87c24e9a7e --- /dev/null +++ b/examples/example/avatarcontrol/handControlledHead.js @@ -0,0 +1,65 @@ +// handControlledHead.js + +//This script allows you to look around, driving the rotation of the avatar's head by the right hand orientation. + +const YAW_MULTIPLIER = 20000; +const PITCH_MULTIPLIER = 15000; +const EPSILON = 0.001; +var firstPress = true; +var handPreviousVerticalRotation = 0.0; +var handCurrentVerticalRotation = 0.0; +var handPreviousHorizontalRotation = 0.0; +var handCurrentHorizontalRotation = 0.0; +var rotatedHandPosition; +var rotatedTipPosition; + +function update(deltaTime) { + if(Controller.getValue(Controller.Standard.RightPrimaryThumb)){ + pitchManager(deltaTime); + }else if(!firstPress){ + firstPress = true; + } + if(firstPress && MyAvatar.headYaw){ + MyAvatar.headYaw -= MyAvatar.headYaw/10; + } + +} + +function pitchManager(deltaTime){ + + rotatedHandPosition = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, -MyAvatar.bodyYaw, 0), MyAvatar.getRightHandPosition()); + rotatedTipPosition = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, -MyAvatar.bodyYaw, 0), MyAvatar.getRightHandTipPosition()); + + handCurrentVerticalRotation = Vec3.subtract(rotatedTipPosition, rotatedHandPosition).y; + handCurrentHorizontalRotation = Vec3.subtract(rotatedTipPosition, rotatedHandPosition).x; + + var handCurrentHorizontalRotationFiltered = handCurrentHorizontalRotation; + + //to avoid yaw drift + if((handCurrentHorizontalRotation - handPreviousHorizontalRotation) < EPSILON && (handCurrentHorizontalRotation - handPreviousHorizontalRotation) > -EPSILON){ + handCurrentHorizontalRotationFiltered = handPreviousHorizontalRotation; + } + + if(firstPress){ + handPreviousVerticalRotation = handCurrentVerticalRotation; + handPreviousHorizontalRotation = handCurrentHorizontalRotation; + firstPress = false; + } + + MyAvatar.headPitch += (handCurrentVerticalRotation - handPreviousVerticalRotation)*PITCH_MULTIPLIER*deltaTime; + MyAvatar.headYaw -= (handCurrentHorizontalRotationFiltered - handPreviousHorizontalRotation)*YAW_MULTIPLIER*deltaTime; + + + handPreviousVerticalRotation = handCurrentVerticalRotation; + handPreviousHorizontalRotation = handCurrentHorizontalRotationFiltered; + + +} + +function clean(){ + MyAvatar.headYaw = 0.0; +} + + +Script.update.connect(update); +Script.scriptEnding.connect(clean); \ No newline at end of file From e4b1b54e005384e5bc072824278e1a3bb9bebb46 Mon Sep 17 00:00:00 2001 From: AlessandroSigna Date: Wed, 11 Nov 2015 12:07:54 -0800 Subject: [PATCH 2/2] added header --- .../example/avatarcontrol/handControlledHead.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/examples/example/avatarcontrol/handControlledHead.js b/examples/example/avatarcontrol/handControlledHead.js index 87c24e9a7e..95ad1655ab 100644 --- a/examples/example/avatarcontrol/handControlledHead.js +++ b/examples/example/avatarcontrol/handControlledHead.js @@ -1,6 +1,14 @@ -// handControlledHead.js - -//This script allows you to look around, driving the rotation of the avatar's head by the right hand orientation. +// +// handControlledHead.js +// examples +// +// Created by Alessandro Signa on 10/11/15. +// Copyright 2015 High Fidelity, Inc. +// +// This script allows you to look around, driving the rotation of the avatar's head by the right hand orientation. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html const YAW_MULTIPLIER = 20000; const PITCH_MULTIPLIER = 15000;