From 43bbac2457e997b23559409fc283f98acee78e0e Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 21 Dec 2016 13:01:48 -0800 Subject: [PATCH] Update position that the arrow is held at --- .../Toybox/towerDefense/bow/bow.js | 73 +++++++++++++++++++ .../Toybox/towerDefense/bow/spawnBow.js | 2 +- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/bow.js b/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/bow.js index 818960e335..069ca53832 100644 --- a/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/bow.js +++ b/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/bow.js @@ -1,4 +1,76 @@ // +// Created by Seth Alves on 2016-9-7 +// Copyright 2016 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 +/* global MyAvatar, Vec3, Controller, Quat */ + +var GRAB_COMMUNICATIONS_SETTING = "io.highfidelity.isFarGrabbing"; +setGrabCommunications = function setFarGrabCommunications(on) { + Settings.setValue(GRAB_COMMUNICATIONS_SETTING, on ? "on" : ""); +} +getGrabCommunications = function getFarGrabCommunications() { + return !!Settings.getValue(GRAB_COMMUNICATIONS_SETTING, ""); +} + +// this offset needs to match the one in libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp:378 +var GRAB_POINT_SPHERE_OFFSET = { x: 0.04, y: 0.13, z: 0.039 }; // x = upward, y = forward, z = lateral + +getGrabPointSphereOffset = function(handController) { + if (handController === Controller.Standard.RightHand) { + return GRAB_POINT_SPHERE_OFFSET; + } + return { + x: GRAB_POINT_SPHERE_OFFSET.x * -1, + y: GRAB_POINT_SPHERE_OFFSET.y, + z: GRAB_POINT_SPHERE_OFFSET.z + }; +}; + +// controllerWorldLocation is where the controller would be, in-world, with an added offset +getControllerWorldLocation = function (handController, doOffset) { + var orientation; + var position; + var pose = Controller.getPoseValue(handController); + var valid = pose.valid; + var controllerJointIndex; + if (pose.valid) { + if (handController === Controller.Standard.RightHand) { + controllerJointIndex = MyAvatar.getJointIndex("_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND"); + } else { + controllerJointIndex = MyAvatar.getJointIndex("_CAMERA_RELATIVE_CONTROLLER_LEFTHAND"); + } + orientation = Quat.multiply(MyAvatar.orientation, MyAvatar.getAbsoluteJointRotationInObjectFrame(controllerJointIndex)); + position = Vec3.sum(MyAvatar.position, Vec3.multiplyQbyV(MyAvatar.orientation, MyAvatar.getAbsoluteJointTranslationInObjectFrame(controllerJointIndex))); + + // add to the real position so the grab-point is out in front of the hand, a bit + if (doOffset) { + var offset = getGrabPointSphereOffset(handController); + position = Vec3.sum(position, Vec3.multiplyQbyV(orientation, offset)); + } + + } else if (!HMD.isHandControllerAvailable()) { + // NOTE: keep this offset in sync with scripts/system/controllers/handControllerPointer.js:493 + var VERTICAL_HEAD_LASER_OFFSET = 0.1; + position = Vec3.sum(Camera.position, Vec3.multiplyQbyV(Camera.orientation, {x: 0, y: VERTICAL_HEAD_LASER_OFFSET, z: 0})); + orientation = Quat.multiply(Camera.orientation, Quat.angleAxis(-90, { x: 1, y: 0, z: 0 })); + valid = true; + } + + return {position: position, + translation: position, + orientation: orientation, + rotation: orientation, + valid: valid}; +}; + +// +// +// +// +// +// // bow.js // // This script attaches to a bow that you can pick up with a hand controller. @@ -331,6 +403,7 @@ getControllerLocation: function (controllerHand) { var standardControllerValue = (controllerHand === "right") ? Controller.Standard.RightHand : Controller.Standard.LeftHand; + return getControllerWorldLocation(standardControllerValue, true); var pose = Controller.getPoseValue(standardControllerValue); var orientation = Quat.multiply(MyAvatar.orientation, pose.rotation); var position = Vec3.sum(Vec3.multiplyQbyV(MyAvatar.orientation, pose.translation), MyAvatar.position); diff --git a/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/spawnBow.js b/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/spawnBow.js index 332144fa11..a81fcc12d6 100644 --- a/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/spawnBow.js +++ b/unpublishedScripts/DomainContent/Toybox/towerDefense/bow/spawnBow.js @@ -14,7 +14,7 @@ Entities.addEntity({ "y": -1, "z": 0 }, - "modelURL": "http://hifi-content.s3.amazonaws.com/alan/dev/newarrow_textured.fbx", + "modelURL": Script.resolvePath("bow-deadly.fbx"), "name": "Hifi-Bow", "rotation": { "w": 0.9718012809753418,