From d1e1067e5a2c8245aa600cab777b5ae70a1b585b Mon Sep 17 00:00:00 2001 From: Brad Hefta-Gaub Date: Thu, 18 Feb 2016 22:30:31 -0800 Subject: [PATCH] allow hydra mouse to know the correct size of screen to target --- examples/controllers/reticleHandRotationTest.js | 5 +++-- interface/src/ui/ApplicationCompositor.cpp | 14 +++++++++++++- interface/src/ui/ApplicationCompositor.h | 12 +++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/examples/controllers/reticleHandRotationTest.js b/examples/controllers/reticleHandRotationTest.js index 0f684a37f0..631486d1a3 100644 --- a/examples/controllers/reticleHandRotationTest.js +++ b/examples/controllers/reticleHandRotationTest.js @@ -53,8 +53,9 @@ Script.update.connect(function(deltaTime) { var poseLeft = Controller.getPoseValue(Controller.Standard.LeftHand); // NOTE: hack for now - var screenSizeX = 1920; - var screenSizeY = 1080; + var screenSize = Reticle.maximumPosition; + var screenSizeX = screenSize.x; + var screenSizeY = screenSize.y; var rotatedRight = Vec3.multiplyQbyV(poseRight.rotation, Vec3.UNIT_NEG_Y); var rotatedLeft = Vec3.multiplyQbyV(poseLeft.rotation, Vec3.UNIT_NEG_Y); diff --git a/interface/src/ui/ApplicationCompositor.cpp b/interface/src/ui/ApplicationCompositor.cpp index 370a5d91fd..a083dbf15f 100644 --- a/interface/src/ui/ApplicationCompositor.cpp +++ b/interface/src/ui/ApplicationCompositor.cpp @@ -401,6 +401,18 @@ void ApplicationCompositor::setReticlePosition(glm::vec2 position, bool sendFake } } +#include + +glm::vec2 ApplicationCompositor::getReticleMaximumPosition() const { + glm::vec2 result; + if (qApp->isHMDMode()) { + result = glm::vec2(VIRTUAL_SCREEN_SIZE_X, VIRTUAL_SCREEN_SIZE_Y); + } else { + QRect rec = QApplication::desktop()->screenGeometry(); + result = glm::vec2(rec.right(), rec.bottom()); + } + return result; +} // FIXME - this probably is hella buggy and probably doesn't work correctly // we should kill it asap. @@ -571,7 +583,7 @@ glm::vec2 ApplicationCompositor::screenToSpherical(const glm::vec2& screenPos) { } glm::vec2 ApplicationCompositor::sphericalToScreen(const glm::vec2& sphericalPos) { - glm::uvec2 screenSize { VIRTUAL_SCREEN_SIZE_X, VIRTUAL_SCREEN_SIZE_Y }; // = qApp->getCanvasSize(); + glm::uvec2 screenSize { VIRTUAL_SCREEN_SIZE_X, VIRTUAL_SCREEN_SIZE_Y }; glm::vec2 result = sphericalPos; result.x *= -1.0f; result /= MOUSE_RANGE; diff --git a/interface/src/ui/ApplicationCompositor.h b/interface/src/ui/ApplicationCompositor.h index c706d123f2..ff5477e30d 100644 --- a/interface/src/ui/ApplicationCompositor.h +++ b/interface/src/ui/ApplicationCompositor.h @@ -96,6 +96,8 @@ public: Q_INVOKABLE glm::vec2 getReticlePosition(); Q_INVOKABLE void setReticlePosition(glm::vec2 position, bool sendFakeEvent = true); + Q_INVOKABLE glm::vec2 getReticleMaximumPosition() const; + ReticleInterface* getReticleInterface() { return _reticleInterface; } /// return value - true means the caller should not process the event further @@ -160,9 +162,11 @@ private: // Scripting interface available to control the Reticle class ReticleInterface : public QObject { Q_OBJECT - Q_PROPERTY(glm::vec2 position READ getPosition WRITE setPosition) - Q_PROPERTY(bool visible READ getVisible WRITE setVisible) - Q_PROPERTY(float depth READ getDepth WRITE setDepth) + Q_PROPERTY(glm::vec2 position READ getPosition WRITE setPosition) + Q_PROPERTY(bool visible READ getVisible WRITE setVisible) + Q_PROPERTY(float depth READ getDepth WRITE setDepth) + Q_PROPERTY(glm::vec2 maximumPosition READ getMaximumPosition) + public: ReticleInterface(ApplicationCompositor* outer) : QObject(outer), _compositor(outer) {} @@ -174,6 +178,8 @@ public: Q_INVOKABLE glm::vec2 getPosition() { return _compositor->getReticlePosition(); } Q_INVOKABLE void setPosition(glm::vec2 position) { _compositor->setReticlePosition(position); } + + Q_INVOKABLE glm::vec2 getMaximumPosition() { return _compositor->getReticleMaximumPosition(); } private: ApplicationCompositor* _compositor; };