From 0a4f74cf9c65d2e358306206cd17bc1bdc8f4746 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 9 Dec 2014 16:29:45 -0800 Subject: [PATCH 1/4] Single reticle in the lobby --- examples/lobby.js | 48 ----------------------------------------------- 1 file changed, 48 deletions(-) diff --git a/examples/lobby.js b/examples/lobby.js index dd011d08a4..6a2d85f64d 100644 --- a/examples/lobby.js +++ b/examples/lobby.js @@ -13,7 +13,6 @@ Script.include("libraries/globals.js"); var panelWall = false; var orbShell = false; -var reticle = false; var descriptionText = false; // used for formating the description text, in meters @@ -23,8 +22,6 @@ var numberOfLines = 2; var textMargin = 0.0625; var lineHeight = (textHeight - (2 * textMargin)) / numberOfLines; -var lastMouseMove = 0; -var IDLE_HOVER_TIME = 2000; // if you haven't moved the mouse in 2 seconds, and in HMD mode, then we use reticle for hover var avatarStickPosition = {}; var orbNaturalExtentsMin = { x: -1.230354, y: -1.22077, z: -1.210487 }; @@ -57,13 +54,6 @@ var elevatorSound = SoundCache.getSound(HIFI_PUBLIC_BUCKET + "sounds/Lobby/eleva var currentMuzakInjector = null; var currentSound = null; -var inOculusMode = false; - -function reticlePosition() { - var RETICLE_DISTANCE = 1; - return Vec3.sum(Camera.position, Vec3.multiply(Quat.getFront(Camera.orientation), RETICLE_DISTANCE)); -} - function textOverlayPosition() { var TEXT_DISTANCE_OUT = 6; var TEXT_DISTANCE_DOWN = -2; @@ -124,22 +114,6 @@ function drawLobby() { panelWall = Overlays.addOverlay("model", panelWallProps); orbShell = Overlays.addOverlay("model", orbShellProps); descriptionText = Overlays.addOverlay("text3d", descriptionTextProps); - - inOculusMode = Menu.isOptionChecked("Enable VR Mode"); - - // for HMD wearers, create a reticle in center of screen - if (inOculusMode) { - var CURSOR_SCALE = 0.025; - - reticle = Overlays.addOverlay("billboard", { - url: HIFI_PUBLIC_BUCKET + "images/cursor.svg", - position: reticlePosition(), - ignoreRayIntersection: true, - isFacingAvatar: true, - alpha: 1.0, - scale: CURSOR_SCALE - }); - } // add an attachment on this avatar so other people see them in the lobby MyAvatar.attach(HELMET_ATTACHMENT_URL, "Neck", {x: 0, y: 0, z: 0}, Quat.fromPitchYawRollDegrees(0, 0, 0), 1.15); @@ -227,14 +201,8 @@ function cleanupLobby() { Overlays.deleteOverlay(orbShell); Overlays.deleteOverlay(descriptionText); - - if (reticle) { - Overlays.deleteOverlay(reticle); - } - panelWall = false; orbShell = false; - reticle = false; Audio.stopInjector(currentDrone); currentDrone = null; @@ -358,20 +326,6 @@ function handleLookAt(pickRay) { function update(deltaTime) { maybeCleanupLobby(); if (panelWall) { - - if (reticle) { - Overlays.editOverlay(reticle, { - position: reticlePosition() - }); - - var nowDate = new Date(); - var now = nowDate.getTime(); - if (now - lastMouseMove > IDLE_HOVER_TIME) { - var pickRay = Camera.computeViewPickRay(0.5, 0.5); - handleLookAt(pickRay); - } - } - Overlays.editOverlay(descriptionText, { position: textOverlayPosition() }); // if the reticle is up then we may need to play the next muzak @@ -383,8 +337,6 @@ function update(deltaTime) { function mouseMoveEvent(event) { if (panelWall) { - var nowDate = new Date(); - lastMouseMove = nowDate.getTime(); var pickRay = Camera.computePickRay(event.x, event.y); handleLookAt(pickRay); } From 8765d9a9b3fb51238c22ae1592d273dfb25784d5 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 9 Dec 2014 16:30:37 -0800 Subject: [PATCH 2/4] Mouse cursor modifications --- interface/src/Application.cpp | 85 ++++++++-------------------- interface/src/Application.h | 7 +-- interface/src/ui/FramelessDialog.cpp | 6 +- 3 files changed, 30 insertions(+), 68 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3824185f52..8a89444734 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -167,8 +167,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : _raiseMirror(0.0f), _lastMouseMove(usecTimestampNow()), _lastMouseMoveWasSimulated(false), - _mouseHidden(false), - _seenMouseMove(false), _touchAvgX(0.0f), _touchAvgY(0.0f), _isTouchPressed(false), @@ -1252,34 +1250,23 @@ void Application::focusOutEvent(QFocusEvent* event) { } void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { - bool showMouse = true; - // Used by application overlay to determine how to draw cursor(s) _lastMouseMoveWasSimulated = deviceID > 0; - - // If this mouse move event is emitted by a controller, dont show the mouse cursor - if (_lastMouseMoveWasSimulated) { - showMouse = false; + if (!_lastMouseMoveWasSimulated) { + _lastMouseMove = usecTimestampNow(); } if (!_aboutToQuit) { - _entities.mouseMoveEvent(event, deviceID); + return; } - + + _entities.mouseMoveEvent(event, deviceID); + _controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts - // if one of our scripts have asked to capture this event, then stop processing it if (_controllerScriptingInterface.isMouseCaptured()) { return; } - - _lastMouseMove = usecTimestampNow(); - - if (_mouseHidden && showMouse && !OculusManager::isConnected() && !TV3DManager::isConnected()) { - getGLWidget()->setCursor(Qt::ArrowCursor); - _mouseHidden = false; - _seenMouseMove = true; - } } void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { @@ -2111,13 +2098,7 @@ void Application::updateMouseRay() { // make sure the frustum is up-to-date loadViewFrustum(_myCamera, _viewFrustum); - // if the mouse pointer isn't visible, act like it's at the center of the screen - float x = 0.5f, y = 0.5f; - if (!_mouseHidden) { - x = getTrueMouseX() / (float)_glWidget->width(); - y = getTrueMouseY() / (float)_glWidget->height(); - } - PickRay pickRay = _myCamera.computeViewPickRay(x, y); + PickRay pickRay = _myCamera.computePickRay(getTrueMouseX(), getTrueMouseY()); _mouseRayOrigin = pickRay.origin; _mouseRayDirection = pickRay.direction; @@ -2313,23 +2294,26 @@ void Application::updateCursor(float deltaTime) { bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::updateCursor()"); - // watch mouse position, if it hasn't moved, hide the cursor + bool hideMouse = false; bool underMouse = _glWidget->underMouse(); - if (!_mouseHidden) { - quint64 now = usecTimestampNow(); - int elapsed = now - _lastMouseMove; - const int HIDE_CURSOR_TIMEOUT = 1 * 1000 * 1000; // 1 second - if (elapsed > HIDE_CURSOR_TIMEOUT && (underMouse || !_seenMouseMove)) { - getGLWidget()->setCursor(Qt::BlankCursor); - _mouseHidden = true; - } + + static const int HIDE_CURSOR_TIMEOUT = 1 * USECS_PER_SECOND; // 1 second + int elapsed = usecTimestampNow() - _lastMouseMove; + if ((elapsed > HIDE_CURSOR_TIMEOUT && underMouse) || + (OculusManager::isConnected() && Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode))) { + hideMouse = true; + } + + if (hideMouse != isMouseHidden()) { + setCursorVisible(!hideMouse); + } +} + +void Application::setCursorVisible(bool visible) { + if (visible) { + _glWidget->setCursor(Qt::ArrowCursor); } else { - // if the mouse is hidden, but we're not inside our window, then consider ourselves to be moving - if (!underMouse && _seenMouseMove) { - _lastMouseMove = usecTimestampNow(); - getGLWidget()->setCursor(Qt::ArrowCursor); - _mouseHidden = false; - } + _glWidget->setCursor(Qt::BlankCursor); } } @@ -2350,17 +2334,6 @@ void Application::update(float deltaTime) { } - static QCursor cursor; - if (OculusManager::isConnected() && - Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)){ - if (_window->cursor().shape() != Qt::BlankCursor) { - cursor = _window->cursor(); - _window->setCursor(QCursor(Qt::BlankCursor)); - } - } else if(_window->cursor().shape() == Qt::BlankCursor) { - _window->setCursor(cursor); - } - // Dispatch input events _controllerScriptingInterface.updateInputControllers(); @@ -4372,14 +4345,6 @@ void Application::skipVersion(QString latestVersion) { skipFile.write(latestVersion.toStdString().c_str()); } -void Application::setCursorVisible(bool visible) { - if (visible) { - restoreOverrideCursor(); - } else { - setOverrideCursor(Qt::BlankCursor); - } -} - void Application::takeSnapshot() { QMediaPlayer* player = new QMediaPlayer(); QFileInfo inf = QFileInfo(Application::resourcesPath() + "sounds/snap.wav"); diff --git a/interface/src/Application.h b/interface/src/Application.h index 58dec1da1f..0f0bd91210 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -211,7 +211,8 @@ public: EntityTreeRenderer* getEntityClipboardRenderer() { return &_entityClipboardRenderer; } Environment* getEnvironment() { return &_environment; } bool isMousePressed() const { return _mousePressed; } - bool isMouseHidden() const { return _mouseHidden; } + bool isMouseHidden() const { return _glWidget->cursor().shape() == Qt::BlankCursor; } + void setCursorVisible(bool visible); const glm::vec3& getMouseRayOrigin() const { return _mouseRayOrigin; } const glm::vec3& getMouseRayDirection() const { return _mouseRayDirection; } bool mouseOnScreen() const; @@ -309,8 +310,6 @@ public: QStringList getRunningScripts() { return _scriptEnginesHash.keys(); } ScriptEngine* getScriptEngine(QString scriptHash) { return _scriptEnginesHash.contains(scriptHash) ? _scriptEnginesHash[scriptHash] : NULL; } - - void setCursorVisible(bool visible); bool isLookingAtMyAvatar(Avatar* avatar); @@ -567,8 +566,6 @@ private: int _mouseDragStartedY; quint64 _lastMouseMove; bool _lastMouseMoveWasSimulated; - bool _mouseHidden; - bool _seenMouseMove; glm::vec3 _mouseRayOrigin; glm::vec3 _mouseRayDirection; diff --git a/interface/src/ui/FramelessDialog.cpp b/interface/src/ui/FramelessDialog.cpp index 22a0233d76..ab997a0a75 100644 --- a/interface/src/ui/FramelessDialog.cpp +++ b/interface/src/ui/FramelessDialog.cpp @@ -122,21 +122,21 @@ void FramelessDialog::mousePressEvent(QMouseEvent* mouseEvent) { if (hitLeft || hitRight) { _isResizing = true; _resizeInitialWidth = size().width(); - QApplication::setOverrideCursor(Qt::SizeHorCursor); + setCursor(Qt::SizeHorCursor); } } else { bool hitTop = (_position == POSITION_TOP) && (abs(mouseEvent->pos().y() - size().height()) < RESIZE_HANDLE_WIDTH); if (hitTop) { _isResizing = true; _resizeInitialWidth = size().height(); - QApplication::setOverrideCursor(Qt::SizeHorCursor); + setCursor(Qt::SizeHorCursor); } } } } void FramelessDialog::mouseReleaseEvent(QMouseEvent* mouseEvent) { - QApplication::restoreOverrideCursor(); + unsetCursor(); _isResizing = false; } From 43dc35d549db1438c8fb927698848ae6841d31f5 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 9 Dec 2014 17:53:23 -0800 Subject: [PATCH 3/4] Use correct mouse coordinate --- interface/src/Application.cpp | 20 ++++++++++---------- interface/src/ui/ApplicationOverlay.cpp | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 8a89444734..4ad8e87204 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1128,7 +1128,8 @@ void Application::keyPressEvent(QKeyEvent* event) { if (!event->isAutoRepeat()) { // this starts an HFActionEvent HFActionEvent startActionEvent(HFActionEvent::startType(), - _myCamera.computeViewPickRay(0.5f, 0.5f)); + _myCamera.computePickRay(getTrueMouseX(), + getTrueMouseY())); sendEvent(this, &startActionEvent); } @@ -1219,10 +1220,11 @@ void Application::keyReleaseEvent(QKeyEvent* event) { case Qt::Key_Space: { if (!event->isAutoRepeat()) { // this ends the HFActionEvent - HFActionEvent endActionEvent(HFActionEvent::endType(), _myCamera.computeViewPickRay(0.5f, 0.5f)); + HFActionEvent endActionEvent(HFActionEvent::endType(), + _myCamera.computePickRay(getTrueMouseX(), + getTrueMouseY())); sendEvent(this, &endActionEvent); } - break; } case Qt::Key_Escape: { @@ -1231,7 +1233,6 @@ void Application::keyReleaseEvent(QKeyEvent* event) { HFBackEvent endBackEvent(HFBackEvent::endType()); sendEvent(this, &endBackEvent); } - break; } default: @@ -1256,7 +1257,7 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { _lastMouseMove = usecTimestampNow(); } - if (!_aboutToQuit) { + if (_aboutToQuit) { return; } @@ -1267,6 +1268,7 @@ void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { if (_controllerScriptingInterface.isMouseCaptured()) { return; } + } void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { @@ -2297,21 +2299,19 @@ void Application::updateCursor(float deltaTime) { bool hideMouse = false; bool underMouse = _glWidget->underMouse(); - static const int HIDE_CURSOR_TIMEOUT = 1 * USECS_PER_SECOND; // 1 second + static const int HIDE_CURSOR_TIMEOUT = 3 * USECS_PER_SECOND; // 3 second int elapsed = usecTimestampNow() - _lastMouseMove; if ((elapsed > HIDE_CURSOR_TIMEOUT && underMouse) || (OculusManager::isConnected() && Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode))) { hideMouse = true; } - if (hideMouse != isMouseHidden()) { - setCursorVisible(!hideMouse); - } + setCursorVisible(!hideMouse); } void Application::setCursorVisible(bool visible) { if (visible) { - _glWidget->setCursor(Qt::ArrowCursor); + _glWidget->unsetCursor(); } else { _glWidget->setCursor(Qt::BlankCursor); } diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 602e99ac31..f4e0c9769d 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -536,7 +536,7 @@ void ApplicationOverlay::renderPointers() { glm::vec2 screenPos = sphericalToScreen(glm::vec2(yaw, -pitch)); position = QPoint(screenPos.x, screenPos.y); - QCursor::setPos(application->getGLWidget()->mapToGlobal(position)); + application->getGLWidget()->cursor().setPos(application->getGLWidget()->mapToGlobal(position)); } _reticlePosition[MOUSE] = position; From dc4c9cd545db08fccfeaaa9f18f98d4cba123bff Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 9 Dec 2014 18:00:14 -0800 Subject: [PATCH 4/4] Correctly Hide/Show cursor --- interface/src/Application.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4ad8e87204..facdeb59ec 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2311,9 +2311,15 @@ void Application::updateCursor(float deltaTime) { void Application::setCursorVisible(bool visible) { if (visible) { - _glWidget->unsetCursor(); + if (overrideCursor() != NULL) { + restoreOverrideCursor(); + } } else { - _glWidget->setCursor(Qt::BlankCursor); + if (overrideCursor() != NULL) { + changeOverrideCursor(Qt::BlankCursor); + } else { + setOverrideCursor(Qt::BlankCursor); + } } }