From 762aefbbca611dd51a6c14b7d310738ff50cf8a6 Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 17 Dec 2015 17:38:20 -0800 Subject: [PATCH] add hand driven reticle --- examples/controllers/reticleHandTest.js | 35 +++++++++++++++ examples/controllers/reticleTests.js | 43 ------------------- .../src/controllers/ScriptingInterface.h | 3 ++ 3 files changed, 38 insertions(+), 43 deletions(-) create mode 100644 examples/controllers/reticleHandTest.js diff --git a/examples/controllers/reticleHandTest.js b/examples/controllers/reticleHandTest.js new file mode 100644 index 0000000000..5d0e2f238a --- /dev/null +++ b/examples/controllers/reticleHandTest.js @@ -0,0 +1,35 @@ +// +// reticleTest.js +// examples/controllers +// +// Created by Brad Hefta-Gaub on 2015/12/15 +// Copyright 2015 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 moveReticle(pitch, yaw) { + //print("pitch:" + pitch); + //print("yaw:" + yaw); + + var globalPos = Controller.getReticlePosition(); + globalPos.x += yaw; + globalPos.y += pitch; + Controller.setReticlePosition(globalPos); +} + +var MAPPING_NAME = "com.highfidelity.testing.reticleWithHand"; +var mapping = Controller.newMapping(MAPPING_NAME); +mapping.from(Controller.Standard.RightHand).peek().to(function(pose) { + var angularVelocityEADs = Quat.safeEulerAngles(pose.angularVelocity); // degrees + var yaw = isNaN(angularVelocityEADs.y) ? 0 : (-angularVelocityEADs.y / 10); + var pitch = isNaN(angularVelocityEADs.x) ? 0 : (-angularVelocityEADs.x / 10); + moveReticle(pitch, yaw); +}); +mapping.enable(); + + +Script.scriptEnding.connect(function(){ + mapping.disable(); +}); diff --git a/examples/controllers/reticleTests.js b/examples/controllers/reticleTests.js index 3392d1b7d9..56b2ba413a 100644 --- a/examples/controllers/reticleTests.js +++ b/examples/controllers/reticleTests.js @@ -33,49 +33,6 @@ var mappingJSON = { mapping = Controller.parseMapping(JSON.stringify(mappingJSON)); mapping.enable(); - - -var MAPPING_NAME = "com.highfidelity.testing.reticleWithHand"; -var mapping2 = Controller.newMapping(MAPPING_NAME); -//mapping2.from(Controller.Standard.RightHand).debug(true).to(Controller.Actions.LeftHand); - -/* -mapping2.from(Controller.Standard.RightHand).peek().to(function(pose) { - print("Controller.Standard.RightHand value:" + JSON.stringify(pose)); - }); -*/ - -var translation = { x: 0, y: 0.1, z: 0 }; -var translationDx = 0.01; -var translationDy = 0.01; -var translationDz = 0.01; -var TRANSLATION_LIMIT = 0.5; -var rotation = Quat.fromPitchYawRollDegrees(45, 0, 45); -mapping2.from(function() { - translation.x = translation.x + translationDx; - translation.y = translation.y + translationDy; - translation.z = translation.z + translationDz; - if ((translation.x > TRANSLATION_LIMIT) || (translation.x < (-1 *TRANSLATION_LIMIT))) { - translationDx = translationDx * -1; - } - if ((translation.y > TRANSLATION_LIMIT) || (translation.y < (-1 *TRANSLATION_LIMIT))) { - translationDy = translationDy * -1; - } - if ((translation.z > TRANSLATION_LIMIT) || (translation.z < (-1 *TRANSLATION_LIMIT))) { - translationDz = translationDz * -1; - } - var pose = { - translation: translation, - rotation: rotation, - velocity: { x: 0, y: 0, z: 0 }, - angularVelocity: { x: 0, y: 0, z: 0, w: 1 } - }; - return pose; -}).debug(true).to(Controller.Standard.LeftHand); - -Controller.enableMapping(MAPPING_NAME); - - Script.scriptEnding.connect(function(){ mapping.disable(); }); diff --git a/libraries/controllers/src/controllers/ScriptingInterface.h b/libraries/controllers/src/controllers/ScriptingInterface.h index 9af478e709..9d3942cd55 100644 --- a/libraries/controllers/src/controllers/ScriptingInterface.h +++ b/libraries/controllers/src/controllers/ScriptingInterface.h @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -87,6 +88,8 @@ namespace controller { Q_INVOKABLE QObject* parseMapping(const QString& json); Q_INVOKABLE QObject* loadMapping(const QString& jsonUrl); + Q_INVOKABLE glm::vec2 getReticlePosition() { return toGlm(QCursor::pos()); } + Q_INVOKABLE void setReticlePosition(glm::vec2 position) { QCursor::setPos(position.x, position.y); } //Q_INVOKABLE bool isPrimaryButtonPressed() const; //Q_INVOKABLE glm::vec2 getPrimaryJoystickPosition() const;