From 77b47d4b32b2fb8502527ddfd07c572248d7e0f8 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Mon, 5 Nov 2018 17:29:01 -0800 Subject: [PATCH] adding class for creating overlay and lasers --- interface/src/Application.cpp | 122 +++++----- interface/src/Application.h | 4 +- interface/src/LoginPointerManager.cpp | 240 ++++++++++++++++++++ interface/src/LoginPointerManager.h | 43 ++++ interface/src/ui/DialogsManager.cpp | 1 - interface/src/ui/LoginDialog.cpp | 1 + libraries/networking/src/AddressManager.cpp | 7 +- libraries/networking/src/DomainHandler.h | 2 - 8 files changed, 344 insertions(+), 76 deletions(-) create mode 100644 interface/src/LoginPointerManager.cpp create mode 100644 interface/src/LoginPointerManager.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a46d3bce07..6260c9c8b3 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5889,6 +5889,9 @@ void Application::update(float deltaTime) { if (keyboardMousePlugin && keyboardMousePlugin->isActive()) { keyboardMousePlugin->pluginUpdate(deltaTime, calibrationData); } + if (!_loginDialogOverlayID.isNull()) { + _loginPointerManager.update(); + } // Transfer the user inputs to the driveKeys // FIXME can we drop drive keys and just have the avatar read the action states directly? @@ -8517,13 +8520,7 @@ void Application::checkReadyToCreateLoginDialogOverlay() { if (qApp->isHMDMode() && qApp->getActiveDisplayPlugin()->isDisplayVisible() && qApp->getLoginDialogPoppedUp() && _loginDialogOverlayID.isNull()) { createLoginDialogOverlay(); } else if (qApp->getLoginDialogPoppedUp() && !qApp->isHMDMode()) { - auto pointer = DependencyManager::get().data(); - if (_leftLoginPointerID > 0) { - pointer->disablePointer(_leftLoginPointerID); - } - if (_rightLoginPointerID > 0) { - pointer->disablePointer(_rightLoginPointerID); - } + _loginPointerManager.~LoginPointerManager(); } } @@ -8545,61 +8542,62 @@ void Application::createLoginDialogOverlay() { { "dpi", overlayDpi }, { "visible", true } }; - auto pointer = DependencyManager::get().data(); - auto standard = _controllerScriptingInterface->getStandard(); + _loginPointerManager.init(); + //auto pointer = DependencyManager::get().data(); + //auto standard = _controllerScriptingInterface->getStandard(); - glm::vec3 grabPointSphereOffsetLeft { 0.04, 0.13, 0.039 }; // x = upward, y = forward, z = lateral - glm::vec3 grabPointSphereOffsetRight { -0.04, 0.13, 0.039 }; // x = upward, y = forward, z = lateral + //glm::vec3 grabPointSphereOffsetLeft { 0.04, 0.13, 0.039 }; // x = upward, y = forward, z = lateral + //glm::vec3 grabPointSphereOffsetRight { -0.04, 0.13, 0.039 }; // x = upward, y = forward, z = lateral - QList leftPointerTriggerProperties; - QVariantMap ltClick1 { - { "action", controller::StandardButtonChannel::LT_CLICK }, - { "button", "Focus" } - }; - QVariantMap ltClick2 { - { "action", controller::StandardButtonChannel::LT_CLICK }, - { "button", "Primary" } - }; + //QList leftPointerTriggerProperties; + //QVariantMap ltClick1 { + // { "action", controller::StandardButtonChannel::LT_CLICK }, + // { "button", "Focus" } + //}; + //QVariantMap ltClick2 { + // { "action", controller::StandardButtonChannel::LT_CLICK }, + // { "button", "Primary" } + //}; - leftPointerTriggerProperties.append(ltClick1); - leftPointerTriggerProperties.append(ltClick2); - const unsigned int leftHand = 0; - QVariantMap leftPointerProperties { - { "joint", "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND" }, - { "filter", PickFilter::PICK_OVERLAYS }, - { "triggers", leftPointerTriggerProperties }, - { "posOffset", vec3toVariant(grabPointSphereOffsetLeft) }, - { "hover", true }, - { "distanceScaleEnd", true }, - { "hand", leftHand } - }; - _leftLoginPointerID = pointer->createPointer(PickQuery::PickType::Ray, leftPointerProperties); - pointer->setRenderState(_leftLoginPointerID, ""); - pointer->enablePointer(_leftLoginPointerID); - const unsigned int rightHand = 1; - QList rightPointerTriggerProperties; - QVariantMap rtClick1 { - { "action", controller::StandardButtonChannel::RT_CLICK }, - { "button", "Focus" } - }; - QVariantMap rtClick2 { - { "action", controller::StandardButtonChannel::RT_CLICK }, - { "button", "Primary" } - }; - rightPointerTriggerProperties.append(rtClick1); - rightPointerTriggerProperties.append(rtClick2); - QVariantMap rightPointerProperties{ - { "joint", "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND" }, - { "filter", PickFilter::PICK_OVERLAYS }, - { "triggers", rightPointerTriggerProperties }, - { "posOffset", vec3toVariant(grabPointSphereOffsetRight) }, - { "hover", true }, - { "distanceScaleEnd", true }, - { "hand", rightHand } - }; - _rightLoginPointerID = pointer->createPointer(PickQuery::PickType::Ray, rightPointerProperties); - pointer->setRenderState(_rightLoginPointerID, ""); - pointer->enablePointer(_rightLoginPointerID); + //leftPointerTriggerProperties.append(ltClick1); + //leftPointerTriggerProperties.append(ltClick2); + //const unsigned int leftHand = 0; + //QVariantMap leftPointerProperties { + // { "joint", "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND" }, + // { "filter", PickFilter::PICK_OVERLAYS }, + // { "triggers", leftPointerTriggerProperties }, + // { "posOffset", vec3toVariant(grabPointSphereOffsetLeft) }, + // { "hover", true }, + // { "distanceScaleEnd", true }, + // { "hand", leftHand } + //}; + //_leftLoginPointerID = pointer->createPointer(PickQuery::PickType::Ray, leftPointerProperties); + //pointer->setRenderState(_leftLoginPointerID, ""); + //pointer->enablePointer(_leftLoginPointerID); + //const unsigned int rightHand = 1; + //QList rightPointerTriggerProperties; + //QVariantMap rtClick1 { + // { "action", controller::StandardButtonChannel::RT_CLICK }, + // { "button", "Focus" } + //}; + //QVariantMap rtClick2 { + // { "action", controller::StandardButtonChannel::RT_CLICK }, + // { "button", "Primary" } + //}; + //rightPointerTriggerProperties.append(rtClick1); + //rightPointerTriggerProperties.append(rtClick2); + //QVariantMap rightPointerProperties{ + // { "joint", "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND" }, + // { "filter", PickFilter::PICK_OVERLAYS }, + // { "triggers", rightPointerTriggerProperties }, + // { "posOffset", vec3toVariant(grabPointSphereOffsetRight) }, + // { "hover", true }, + // { "distanceScaleEnd", true }, + // { "hand", rightHand } + //}; + //_rightLoginPointerID = pointer->createPointer(PickQuery::PickType::Ray, rightPointerProperties); + //pointer->setRenderState(_rightLoginPointerID, ""); + //pointer->enablePointer(_rightLoginPointerID); _loginDialogOverlayID = overlays.addOverlay("web3d", overlayProperties); } @@ -8613,12 +8611,6 @@ void Application::onDismissedLoginDialog() { qDebug() << "Deleting overlay"; getOverlays().deleteOverlay(_loginDialogOverlayID); } - if (_leftLoginPointerID > 0) { - pointer->disablePointer(_leftLoginPointerID); - } - if (_rightLoginPointerID > 0) { - pointer->disablePointer(_rightLoginPointerID); - } resumeAfterLoginDialogActionTaken(); } diff --git a/interface/src/Application.h b/interface/src/Application.h index 0498a0ee72..6a99eb14a9 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -56,6 +56,7 @@ #include "ConnectionMonitor.h" #include "CursorManager.h" #include "gpu/Context.h" +#include "LoginPointerManager.h" #include "Menu.h" #include "octree/OctreePacketProcessor.h" #include "render/Engine.h" @@ -688,8 +689,7 @@ private: bool _loginDialogPoppedUp = false; OverlayID _loginDialogOverlayID; - unsigned int _leftLoginPointerID { PointerEvent::INVALID_POINTER_ID }; - unsigned int _rightLoginPointerID { PointerEvent::INVALID_POINTER_ID }; + LoginPointerManager _loginPointerManager; quint64 _lastFaceTrackerUpdate; diff --git a/interface/src/LoginPointerManager.cpp b/interface/src/LoginPointerManager.cpp new file mode 100644 index 0000000000..b2f8f46964 --- /dev/null +++ b/interface/src/LoginPointerManager.cpp @@ -0,0 +1,240 @@ +// +// LoginPointerManager.cpp +// interface/src +// +// Created by Wayne Chen on 11/5/18. +// Copyright 2018 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 +// + +#include "LoginPointerManager.h" + +#include +#include + +#include + +#include "controllers/StateController.h" +#include "controllers/UserInputMapper.h" +#include "raypick/PointerScriptingInterface.h" +#include "raypick/PickScriptingInterface.h" +#include "scripting/ControllerScriptingInterface.h" + +static const float SEARCH_SPHERE_SIZE = 0.0132f; +static const QVariantMap SEARCH_SPHERE = {{"x", SEARCH_SPHERE_SIZE}, + {"y", SEARCH_SPHERE_SIZE}, + {"z", SEARCH_SPHERE_SIZE}}; + +static const int DEFAULT_SEARCH_SPHERE_DISTANCE = 1000; // how far from camera to search intersection? + +static const QVariantMap COLORS_GRAB_SEARCHING_HALF_SQUEEZE = {{"red", 10}, + {"green", 10}, + {"blue", 255}}; + +static const QVariantMap COLORS_GRAB_SEARCHING_FULL_SQUEEZE = {{"red", 250}, + {"green", 10}, + {"blue", 10}}; + +static const QVariantMap COLORS_GRAB_DISTANCE_HOLD = {{"red", 238}, + {"green", 75}, + {"blue", 214}}; + + + +LoginPointerManager::~LoginPointerManager() { + auto pointers = DependencyManager::get(); + if (pointers) { + if (leftLoginPointerID() != PointerEvent::INVALID_POINTER_ID) { + pointers->removePointer(leftLoginPointerID()); + } + if (rightLoginPointerID() != PointerEvent::INVALID_POINTER_ID) { + pointers->removePointer(rightLoginPointerID()); + } + } +} + +void LoginPointerManager::init() { + QVariantMap fullPathRenderState { + {"type", "line3d"}, + {"color", COLORS_GRAB_SEARCHING_FULL_SQUEEZE}, + {"visible", true}, + {"alpha", 1.0f}, + {"solid", true}, + {"glow", 1.0f}, + {"ignoreRayIntersection", true}, // always ignore this + {"drawInFront", true}, // Even when burried inside of something, show it. + {"drawHUDLayer", false} + }; + QVariantMap fullEndRenderState { + {"type", "sphere"}, + {"dimensions", SEARCH_SPHERE}, + {"solid", true}, + {"color", COLORS_GRAB_SEARCHING_FULL_SQUEEZE}, + {"alpha", 0.9f}, + {"ignoreRayIntersection", true}, + {"drawInFront", true}, // Even when burried inside of something, show it. + {"drawHUDLayer", false}, + {"visible", true} + }; + QVariantMap halfPathRenderState { + {"type", "line3d"}, + {"color", COLORS_GRAB_SEARCHING_HALF_SQUEEZE}, + {"visible", true}, + {"alpha", 1.0f}, + {"solid", true}, + {"glow", 1.0f}, + {"ignoreRayIntersection", true}, // always ignore this + {"drawInFront", true}, // Even when burried inside of something, show it. + {"drawHUDLayer", false} + }; + QVariantMap halfEndRenderState { + {"type", "sphere"}, + {"dimensions", SEARCH_SPHERE}, + {"solid", true}, + {"color", COLORS_GRAB_SEARCHING_HALF_SQUEEZE}, + {"alpha", 0.9f}, + {"ignoreRayIntersection", true}, + {"drawInFront", true}, // Even when burried inside of something, show it. + {"drawHUDLayer", false}, + {"visible", true} + }; + QVariantMap holdPathRenderState { + {"type", "line3d"}, + {"color", COLORS_GRAB_DISTANCE_HOLD}, + {"visible", true}, + {"alpha", 1.0f}, + {"solid", true}, + {"glow", 1.0f}, + {"ignoreRayIntersection", true}, // always ignore this + {"drawInFront", true}, // Even when burried inside of something, show it. + {"drawHUDLayer", false}, + }; + QVariantMap halfRenderStateIdentifier { + {"name", "half"}, + {"path", halfPathRenderState}, + {"end", halfEndRenderState} + }; + QVariantMap fullRenderStateIdentifier { + {"name", "full"}, + {"path", fullPathRenderState}, + {"end", fullEndRenderState} + }; + QVariantMap holdRenderStateIdentifier { + {"name", "hold"}, + {"path", holdPathRenderState}, + }; + + QVariantMap halfDefaultRenderStateIdentifier { + {"name", "half"}, + {"distance", DEFAULT_SEARCH_SPHERE_DISTANCE}, + {"path", halfPathRenderState} + }; + QVariantMap fullDefaultRenderStateIdentifier { + {"name", "full"}, + {"distance", DEFAULT_SEARCH_SPHERE_DISTANCE}, + {"path", fullPathRenderState} + }; + QVariantMap holdDefaultRenderStateIdentifier { + {"name", "hold"}, + {"distance", DEFAULT_SEARCH_SPHERE_DISTANCE}, + {"path", holdPathRenderState} + }; + + _renderStates = QList({halfRenderStateIdentifier, fullRenderStateIdentifier, holdRenderStateIdentifier}); + _defaultRenderStates = QList({halfDefaultRenderStateIdentifier, fullDefaultRenderStateIdentifier, holdDefaultRenderStateIdentifier}); + + auto pointers = DependencyManager::get().data(); + auto controller = DependencyManager::get().data(); + + glm::vec3 grabPointSphereOffsetLeft { 0.04, 0.13, 0.039 }; // x = upward, y = forward, z = lateral + glm::vec3 grabPointSphereOffsetRight { -0.04, 0.13, 0.039 }; // x = upward, y = forward, z = lateral + + QList leftPointerTriggerProperties; + QVariantMap ltClick1 { + //{ "action", controller::StandardButtonChannel::LT_CLICK }, + { "action", controller->getStandard()["LTClick"] }, + { "button", "Focus" } + }; + QVariantMap ltClick2 { + //{ "action", controller::StandardButtonChannel::LT_CLICK }, + { "action", controller->getStandard()["LTClick"] }, + { "button", "Primary" } + }; + + leftPointerTriggerProperties.append(ltClick1); + leftPointerTriggerProperties.append(ltClick2); + const unsigned int leftHand = 0; + QVariantMap leftPointerProperties { + { "joint", "_CAMERA_RELATIVE_CONTROLLER_LEFTHAND" }, + // { "filter", PickFilter::PICK_OVERLAYS }, + { "filter", PickScriptingInterface::PICK_OVERLAYS() }, + { "triggers", leftPointerTriggerProperties }, + { "posOffset", vec3toVariant(grabPointSphereOffsetLeft) }, + { "hover", true }, + { "scaleWithParent", true }, + { "distanceScaleEnd", true }, + { "hand", leftHand } + }; + leftPointerProperties["renderStates"] = _renderStates; + leftPointerProperties["defaultRenderStates"] = _defaultRenderStates; + withWriteLock([&] { _leftLoginPointerID = pointers->createPointer(PickQuery::PickType::Ray, leftPointerProperties); }); + pointers->setRenderState(leftLoginPointerID(), ""); + pointers->enablePointer(leftLoginPointerID()); + const unsigned int rightHand = 1; + QList rightPointerTriggerProperties; + + QVariantMap rtClick1 { + //{ "action", controller::StandardButtonChannel::RT_CLICK }, + { "action", controller->getStandard()["RTClick"] }, + { "button", "Focus" } + }; + QVariantMap rtClick2 { + //{ "action", controller::StandardButtonChannel::RT_CLICK }, + { "action", controller->getStandard()["RTClick"] }, + { "button", "Primary" } + }; + rightPointerTriggerProperties.append(rtClick1); + rightPointerTriggerProperties.append(rtClick2); + QVariantMap rightPointerProperties{ + { "joint", "_CAMERA_RELATIVE_CONTROLLER_RIGHTHAND" }, + // { "filter", PickFilter::PICK_OVERLAYS }, + { "filter", PickScriptingInterface::PICK_OVERLAYS() }, + { "triggers", rightPointerTriggerProperties }, + { "posOffset", vec3toVariant(grabPointSphereOffsetRight) }, + { "hover", true }, + { "scaleWithParent", true }, + { "distanceScaleEnd", true }, + { "hand", rightHand } + }; + rightPointerProperties["renderStates"] = _renderStates; + rightPointerProperties["defaultRenderStates"] = _defaultRenderStates; + withWriteLock([&] { _rightLoginPointerID = pointers->createPointer(PickQuery::PickType::Ray, rightPointerProperties); }); + pointers->setRenderState(rightLoginPointerID(), ""); + pointers->enablePointer(rightLoginPointerID()); + + +} + +void LoginPointerManager::update() { + auto pointers = DependencyManager::get(); + if (pointers) { + QString mode = ""; + // if (this.visible) { + // if (this.locked) { + // mode = "hold"; + // if (triggerClicks[this.hand]) { + mode = "full"; + // } else if (triggerValues[this.hand] > TRIGGER_ON_VALUE || this.allwaysOn) { + // mode = "half"; + // } + // } + if (leftLoginPointerID() > PointerEvent::INVALID_POINTER_ID) { + pointers->setRenderState(leftLoginPointerID(), mode); + } + if (rightLoginPointerID() > PointerEvent::INVALID_POINTER_ID) { + pointers->setRenderState(rightLoginPointerID(), mode); + } + } +} diff --git a/interface/src/LoginPointerManager.h b/interface/src/LoginPointerManager.h new file mode 100644 index 0000000000..8690f113cf --- /dev/null +++ b/interface/src/LoginPointerManager.h @@ -0,0 +1,43 @@ +// +// LoginPointerManager.h +// interface/src +// +// Created by Wayne Chen on 11/5/18. +// Copyright 2018 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 +// +#ifndef hifi_LoginPointerManager_h +#define hifi_LoginPointerManager_h +#include +#include + +#include + +#include + +class LoginPointerManager : protected ReadWriteLockable { +public: + LoginPointerManager() {} + ~LoginPointerManager(); + + void init(); + + void update(); + + const unsigned int leftLoginPointerID() const { + return resultWithReadLock([&] { return _leftLoginPointerID; }); + } + + const unsigned int rightLoginPointerID() const { + return resultWithReadLock([&] { return _rightLoginPointerID; }); + } + +private: + QList _renderStates {}; + QList _defaultRenderStates {}; + unsigned int _leftLoginPointerID { PointerEvent::INVALID_POINTER_ID }; + unsigned int _rightLoginPointerID { PointerEvent::INVALID_POINTER_ID }; +}; +#endif // hifi_LoginPointerManager_h diff --git a/interface/src/ui/DialogsManager.cpp b/interface/src/ui/DialogsManager.cpp index 98b0483040..d2859a1f79 100644 --- a/interface/src/ui/DialogsManager.cpp +++ b/interface/src/ui/DialogsManager.cpp @@ -25,7 +25,6 @@ #include "HMDToolsDialog.h" #include "LodToolsDialog.h" #include "LoginDialog.h" -#include "LoginScreenDialog.h" #include "OctreeStatsDialog.h" #include "PreferencesDialog.h" #include "UpdateDialog.h" diff --git a/interface/src/ui/LoginDialog.cpp b/interface/src/ui/LoginDialog.cpp index f22cb11f37..93f210cf03 100644 --- a/interface/src/ui/LoginDialog.cpp +++ b/interface/src/ui/LoginDialog.cpp @@ -71,6 +71,7 @@ void LoginDialog::showWithSelection() { tablet->initialScreen(TABLET_LOGIN_DIALOG_URL); } else { // let Application handle creating login dialog overlay. + qApp->checkReadyToCreateLoginDialogOverlay(); } } diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 21f25fd0ca..613e07dc5f 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -162,10 +162,6 @@ void AddressManager::storeCurrentAddress() { // url.scheme() == URL_SCHEME_HTTP || // url.scheme() == URL_SCHEME_HTTPS || bool isInErrorState = DependencyManager::get()->getDomainHandler().isInErrorState(); - bool isInLoginScreenState = DependencyManager::get()->getDomainHandler().isInLoginScreenState(); - if (isInLoginScreenState) { - qCWarning(networking) << "Ignoring attempt to save current address because in login screen domain:" << url; - } if (isConnected()) { if (isInErrorState) { // save the last address visited before the problem url. @@ -829,9 +825,8 @@ bool AddressManager::setDomainInfo(const QUrl& domainURL, LookupTrigger trigger) // Check if domain handler is in error state. always emit host changed if true. bool isInErrorState = DependencyManager::get()->getDomainHandler().isInErrorState(); // Check if domain handler is in login screen state. always emit host changed if true. - bool isInLoginScreenState = DependencyManager::get()->getDomainHandler().isInLoginScreenState(); - if (domainURL != _domainURL || isInErrorState || isInLoginScreenState) { + if (domainURL != _domainURL || isInErrorState) { addCurrentAddressToHistory(trigger); emitHostChanged = true; } diff --git a/libraries/networking/src/DomainHandler.h b/libraries/networking/src/DomainHandler.h index e99875a50c..ddd23339df 100644 --- a/libraries/networking/src/DomainHandler.h +++ b/libraries/networking/src/DomainHandler.h @@ -179,7 +179,6 @@ public slots: void setRedirectErrorState(QUrl errorUrl, QString reasonMessage = "", int reason = -1, const QString& extraInfo = ""); bool isInErrorState() { return _isInErrorState; } - bool isInLoginScreenState() { return _isInLoginScreenState; } private slots: void completedHostnameLookup(const QHostInfo& hostInfo); @@ -228,7 +227,6 @@ private: NetworkPeer _icePeer; bool _isConnected { false }; bool _isInErrorState { false }; - bool _isInLoginScreenState { false }; QJsonObject _settingsObject; QString _pendingPath; QTimer _settingsTimer;