Mouse pick improvments
Showing the changes to interface/src/Application.cpp (1 of 5 files). Show all
Unified · Split
| @@ -167,8 +167,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 166 unmodified lines | ||
| 167 | 167 | _raiseMirror(0.0f), |
| 168 | 168 | _lastMouseMove(usecTimestampNow()), |
| 169 | 169 | _lastMouseMoveWasSimulated(false), |
| 170 | − _mouseHidden(false), | |
| 171 | − _seenMouseMove(false), | |
| 172 | 170 | _touchAvgX(0.0f), |
| 173 | 171 | _touchAvgY(0.0f), |
| 174 | 172 | _isTouchPressed(false), |
| @@ -1130,7 +1128,8 @@ void Application::keyPressEvent(QKeyEvent* event) { · 955 unmodified lines | ||
| 1130 | 1128 | if (!event->isAutoRepeat()) { |
| 1131 | 1129 | // this starts an HFActionEvent |
| 1132 | 1130 | HFActionEvent startActionEvent(HFActionEvent::startType(), |
| 1133 | − _myCamera.computeViewPickRay(0.5f, 0.5f)); | |
| 1131 | + _myCamera.computePickRay(getTrueMouseX(), | |
| 1132 | + getTrueMouseY())); | |
| 1134 | 1133 | sendEvent(this, &startActionEvent); |
| 1135 | 1134 | } |
| 1136 | 1135 | |
| @@ -1221,10 +1220,11 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 84 unmodified lines | ||
| 1221 | 1220 | case Qt::Key_Space: { |
| 1222 | 1221 | if (!event->isAutoRepeat()) { |
| 1223 | 1222 | // this ends the HFActionEvent |
| 1224 | − HFActionEvent endActionEvent(HFActionEvent::endType(), _myCamera.computeViewPickRay(0.5f, 0.5f)); | |
| 1223 | + HFActionEvent endActionEvent(HFActionEvent::endType(), | |
| 1224 | + _myCamera.computePickRay(getTrueMouseX(), | |
| 1225 | + getTrueMouseY())); | |
| 1225 | 1226 | sendEvent(this, &endActionEvent); |
| 1226 | 1227 | } |
| 1227 | − | |
| 1228 | 1228 | break; |
| 1229 | 1229 | } |
| 1230 | 1230 | case Qt::Key_Escape: { |
| @@ -1233,7 +1233,6 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 2 unmodified lines | ||
| 1233 | 1233 | HFBackEvent endBackEvent(HFBackEvent::endType()); |
| 1234 | 1234 | sendEvent(this, &endBackEvent); |
| 1235 | 1235 | } |
| 1236 | − | |
| 1237 | 1236 | break; |
| 1238 | 1237 | } |
| 1239 | 1238 | default: |
| @@ -1252,34 +1251,24 @@ void Application::focusOutEvent(QFocusEvent* event) { · 12 unmodified lines | ||
| 1252 | 1251 | } |
| 1253 | 1252 | |
| 1254 | 1253 | void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { |
| 1255 | − bool showMouse = true; | |
| 1256 | − | |
| 1257 | 1254 | // Used by application overlay to determine how to draw cursor(s) |
| 1258 | 1255 | _lastMouseMoveWasSimulated = deviceID > 0; |
| 1259 | − | |
| 1260 | − // If this mouse move event is emitted by a controller, dont show the mouse cursor | |
| 1261 | − if (_lastMouseMoveWasSimulated) { | |
| 1262 | − showMouse = false; | |
| 1256 | + if (!_lastMouseMoveWasSimulated) { | |
| 1257 | + _lastMouseMove = usecTimestampNow(); | |
| 1263 | 1258 | } |
| 1264 | 1259 | |
| 1265 | − if (!_aboutToQuit) { | |
| 1266 | − _entities.mouseMoveEvent(event, deviceID); | |
| 1260 | + if (_aboutToQuit) { | |
| 1261 | + return; | |
| 1267 | 1262 | } |
| 1268 | − | |
| 1263 | + | |
| 1264 | + _entities.mouseMoveEvent(event, deviceID); | |
| 1265 | + | |
| 1269 | 1266 | _controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts |
| 1270 | − | |
| 1271 | 1267 | // if one of our scripts have asked to capture this event, then stop processing it |
| 1272 | 1268 | if (_controllerScriptingInterface.isMouseCaptured()) { |
| 1273 | 1269 | return; |
| 1274 | 1270 | } |
| 1275 | − | |
| 1276 | − _lastMouseMove = usecTimestampNow(); | |
| 1277 | − | |
| 1278 | − if (_mouseHidden && showMouse && !OculusManager::isConnected() && !TV3DManager::isConnected()) { | |
| 1279 | − getGLWidget()->setCursor(Qt::ArrowCursor); | |
| 1280 | − _mouseHidden = false; | |
| 1281 | − _seenMouseMove = true; | |
| 1282 | − } | |
| 1271 | + | |
| 1283 | 1272 | } |
| 1284 | 1273 | |
| 1285 | 1274 | void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { |
| @@ -2111,13 +2100,7 @@ void Application::updateMouseRay() { · 825 unmodified lines | ||
| 2111 | 2100 | // make sure the frustum is up-to-date |
| 2112 | 2101 | loadViewFrustum(_myCamera, _viewFrustum); |
| 2113 | 2102 | |
| 2114 | − // if the mouse pointer isn't visible, act like it's at the center of the screen | |
| 2115 | − float x = 0.5f, y = 0.5f; | |
| 2116 | − if (!_mouseHidden) { | |
| 2117 | − x = getTrueMouseX() / (float)_glWidget->width(); | |
| 2118 | − y = getTrueMouseY() / (float)_glWidget->height(); | |
| 2119 | − } | |
| 2120 | − PickRay pickRay = _myCamera.computeViewPickRay(x, y); | |
| 2103 | + PickRay pickRay = _myCamera.computePickRay(getTrueMouseX(), getTrueMouseY()); | |
| 2121 | 2104 | _mouseRayOrigin = pickRay.origin; |
| 2122 | 2105 | _mouseRayDirection = pickRay.direction; |
| 2123 | 2106 | |
| @@ -2313,22 +2296,29 @@ void Application::updateCursor(float deltaTime) { · 189 unmodified lines | ||
| 2313 | 2296 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |
| 2314 | 2297 | PerformanceWarning warn(showWarnings, "Application::updateCursor()"); |
| 2315 | 2298 | |
| 2316 | − // watch mouse position, if it hasn't moved, hide the cursor | |
| 2299 | + bool hideMouse = false; | |
| 2317 | 2300 | bool underMouse = _glWidget->underMouse(); |
| 2318 | − if (!_mouseHidden) { | |
| 2319 | − quint64 now = usecTimestampNow(); | |
| 2320 | − int elapsed = now - _lastMouseMove; | |
| 2321 | − const int HIDE_CURSOR_TIMEOUT = 1 * 1000 * 1000; // 1 second | |
| 2322 | − if (elapsed > HIDE_CURSOR_TIMEOUT && (underMouse || !_seenMouseMove)) { | |
| 2323 | − getGLWidget()->setCursor(Qt::BlankCursor); | |
| 2324 | − _mouseHidden = true; | |
| 2301 | + | |
| 2302 | + static const int HIDE_CURSOR_TIMEOUT = 3 * USECS_PER_SECOND; // 3 second | |
| 2303 | + int elapsed = usecTimestampNow() - _lastMouseMove; | |
| 2304 | + if ((elapsed > HIDE_CURSOR_TIMEOUT && underMouse) || | |
| 2305 | + (OculusManager::isConnected() && Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode))) { | |
| 2306 | + hideMouse = true; | |
| 2307 | + } | |
| 2308 | + | |
| 2309 | + setCursorVisible(!hideMouse); | |
| 2310 | +} | |
| 2311 | + | |
| 2312 | +void Application::setCursorVisible(bool visible) { | |
| 2313 | + if (visible) { | |
| 2314 | + if (overrideCursor() != NULL) { | |
| 2315 | + restoreOverrideCursor(); | |
| 2325 | 2316 | } |
| 2326 | 2317 | } else { |
| 2327 | − // if the mouse is hidden, but we're not inside our window, then consider ourselves to be moving | |
| 2328 | − if (!underMouse && _seenMouseMove) { | |
| 2329 | − _lastMouseMove = usecTimestampNow(); | |
| 2330 | − getGLWidget()->setCursor(Qt::ArrowCursor); | |
| 2331 | − _mouseHidden = false; | |
| 2318 | + if (overrideCursor() != NULL) { | |
| 2319 | + changeOverrideCursor(Qt::BlankCursor); | |
| 2320 | + } else { | |
| 2321 | + setOverrideCursor(Qt::BlankCursor); | |
| 2332 | 2322 | } |
| 2333 | 2323 | } |
| 2334 | 2324 | } |
| @@ -2350,17 +2340,6 @@ void Application::update(float deltaTime) { · 15 unmodified lines | ||
| 2350 | 2340 | |
| 2351 | 2341 | } |
| 2352 | 2342 | |
| 2353 | − static QCursor cursor; | |
| 2354 | − if (OculusManager::isConnected() && | |
| 2355 | − Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)){ | |
| 2356 | − if (_window->cursor().shape() != Qt::BlankCursor) { | |
| 2357 | − cursor = _window->cursor(); | |
| 2358 | − _window->setCursor(QCursor(Qt::BlankCursor)); | |
| 2359 | − } | |
| 2360 | − } else if(_window->cursor().shape() == Qt::BlankCursor) { | |
| 2361 | − _window->setCursor(cursor); | |
| 2362 | − } | |
| 2363 | − | |
| 2364 | 2343 | // Dispatch input events |
| 2365 | 2344 | _controllerScriptingInterface.updateInputControllers(); |
| 2366 | 2345 | |
| @@ -4377,14 +4356,6 @@ void Application::skipVersion(QString latestVersion) { · 2010 unmodified lines | ||
| 4377 | 4356 | skipFile.write(latestVersion.toStdString().c_str()); |
| 4378 | 4357 | } |
| 4379 | 4358 | |
| 4380 | −void Application::setCursorVisible(bool visible) { | |
| 4381 | − if (visible) { | |
| 4382 | − restoreOverrideCursor(); | |
| 4383 | − } else { | |
| 4384 | − setOverrideCursor(Qt::BlankCursor); | |
| 4385 | − } | |
| 4386 | −} | |
| 4387 | − | |
| 4388 | 4359 | void Application::takeSnapshot() { |
| 4389 | 4360 | QMediaPlayer* player = new QMediaPlayer(); |
| 4390 | 4361 | QFileInfo inf = QFileInfo(Application::resourcesPath() + "sounds/snap.wav"); |