Showing the changes to interface/src/Application.cpp (1 of 161 files). Show all
Unified · Split
| @@ -681,6 +681,9 @@ private: · 680 unmodified lines | ||
| 681 | 681 | * <tr><td><code>CameraIndependent</code></td><td>number</td><td>number</td><td>The camera is in independent mode.</td></tr> |
| 682 | 682 | * <tr><td><code>CameraEntity</code></td><td>number</td><td>number</td><td>The camera is in entity mode.</td></tr> |
| 683 | 683 | * <tr><td><code>InHMD</code></td><td>number</td><td>number</td><td>The user is in HMD mode.</td></tr> |
| 684 | + * <tr><td><code>CaptureMouse</code></td><td>number</td><td>number</td><td>The mouse is captured. In this mode, | |
| 685 | + * the mouse is invisible and cannot leave the bounds of Interface, as long as Interface is the active window and | |
| 686 | + * no menu item is selected.</td></tr> | |
| 684 | 687 | * <tr><td><code>AdvancedMovement</code></td><td>number</td><td>number</td><td>Advanced movement (walking) controls are |
| 685 | 688 | * enabled.</td></tr> |
| 686 | 689 | * <tr><td><code>StrafeEnabled</code></td><td>number</td><td>number</td><td>Strafing is enabled</td></tr> |
| @@ -716,6 +719,7 @@ static const QString STATE_PLATFORM_ANDROID = "PlatformAndroid"; · 29 unmodified lines | ||
| 716 | 719 | static const QString STATE_LEFT_HAND_DOMINANT = "LeftHandDominant"; |
| 717 | 720 | static const QString STATE_RIGHT_HAND_DOMINANT = "RightHandDominant"; |
| 718 | 721 | static const QString STATE_STRAFE_ENABLED = "StrafeEnabled"; |
| 722 | +static const QString STATE_CAPTURE_MOUSE = "CaptureMouse"; | |
| 719 | 723 | |
| 720 | 724 | // Statically provided display and input plugins |
| 721 | 725 | extern DisplayPluginList getDisplayPlugins(); |
| @@ -919,7 +923,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { · 197 unmodified lines | ||
| 919 | 923 | DependencyManager::set<MessagesClient>(); |
| 920 | 924 | controller::StateController::setStateVariables({ { STATE_IN_HMD, STATE_CAMERA_FULL_SCREEN_MIRROR, |
| 921 | 925 | STATE_CAMERA_FIRST_PERSON, STATE_CAMERA_FIRST_PERSON_LOOK_AT, STATE_CAMERA_THIRD_PERSON, |
| 922 | − STATE_CAMERA_ENTITY, STATE_CAMERA_INDEPENDENT, STATE_CAMERA_LOOK_AT, STATE_CAMERA_SELFIE, | |
| 926 | + STATE_CAMERA_ENTITY, STATE_CAMERA_INDEPENDENT, STATE_CAMERA_LOOK_AT, STATE_CAMERA_SELFIE, STATE_CAPTURE_MOUSE, | |
| 923 | 927 | STATE_SNAP_TURN, STATE_ADVANCED_MOVEMENT_CONTROLS, STATE_GROUNDED, STATE_NAV_FOCUSED, |
| 924 | 928 | STATE_PLATFORM_WINDOWS, STATE_PLATFORM_MAC, STATE_PLATFORM_ANDROID, STATE_LEFT_HAND_DOMINANT, STATE_RIGHT_HAND_DOMINANT, STATE_STRAFE_ENABLED } }); |
| 925 | 929 | DependencyManager::set<UserInputMapper>(); |
| @@ -1892,6 +1896,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 966 unmodified lines | ||
| 1892 | 1896 | _applicationStateDevice->setInputVariant(STATE_CAMERA_INDEPENDENT, []() -> float { |
| 1893 | 1897 | return qApp->getCamera().getMode() == CAMERA_MODE_INDEPENDENT ? 1 : 0; |
| 1894 | 1898 | }); |
| 1899 | + _applicationStateDevice->setInputVariant(STATE_CAPTURE_MOUSE, []() -> float { | |
| 1900 | + return qApp->getCamera().getCaptureMouse() ? 1 : 0; | |
| 1901 | + }); | |
| 1895 | 1902 | _applicationStateDevice->setInputVariant(STATE_SNAP_TURN, []() -> float { |
| 1896 | 1903 | return qApp->getMyAvatar()->getSnapTurn() ? 1 : 0; |
| 1897 | 1904 | }); |
| @@ -2407,6 +2414,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo · 509 unmodified lines | ||
| 2407 | 2414 | updateSystemTabletMode(); |
| 2408 | 2415 | |
| 2409 | 2416 | connect(&_myCamera, &Camera::modeUpdated, this, &Application::cameraModeChanged); |
| 2417 | + connect(&_myCamera, &Camera::captureMouseChanged, this, &Application::captureMouseChanged); | |
| 2410 | 2418 | |
| 2411 | 2419 | DependencyManager::get<PickManager>()->setShouldPickHUDOperator([]() { return DependencyManager::get<HMDScriptingInterface>()->isHMDMode(); }); |
| 2412 | 2420 | DependencyManager::get<PickManager>()->setCalculatePos2DFromHUDOperator([this](const glm::vec3& intersection) { |
| @@ -4704,6 +4712,11 @@ void Application::maybeToggleMenuVisible(QMouseEvent* event) const { · 2291 unmodified lines | ||
| 4704 | 4712 | void Application::mouseMoveEvent(QMouseEvent* event) { |
| 4705 | 4713 | PROFILE_RANGE(app_input_mouse, __FUNCTION__); |
| 4706 | 4714 | |
| 4715 | + if (_ignoreMouseMove) { | |
| 4716 | + _ignoreMouseMove = false; | |
| 4717 | + return; | |
| 4718 | + } | |
| 4719 | + | |
| 4707 | 4720 | maybeToggleMenuVisible(event); |
| 4708 | 4721 | |
| 4709 | 4722 | auto& compositor = getApplicationCompositor(); |
| @@ -4749,7 +4762,7 @@ void Application::mouseMoveEvent(QMouseEvent* event) { · 39 unmodified lines | ||
| 4749 | 4762 | } |
| 4750 | 4763 | |
| 4751 | 4764 | if (_keyboardMouseDevice->isActive()) { |
| 4752 | − _keyboardMouseDevice->mouseMoveEvent(event); | |
| 4765 | + _keyboardMouseDevice->mouseMoveEvent(event, _captureMouse, _mouseCaptureTarget); | |
| 4753 | 4766 | } |
| 4754 | 4767 | } |
| 4755 | 4768 | |
| @@ -5950,6 +5963,20 @@ void Application::cameraModeChanged() { · 1194 unmodified lines | ||
| 5950 | 5963 | cameraMenuChanged(); |
| 5951 | 5964 | } |
| 5952 | 5965 | |
| 5966 | +bool Application::shouldCaptureMouse() const { | |
| 5967 | + return _captureMouse && _glWidget->isActiveWindow() && !ui::Menu::isSomeSubmenuShown(); | |
| 5968 | +} | |
| 5969 | + | |
| 5970 | +void Application::captureMouseChanged(bool captureMouse) { | |
| 5971 | + _captureMouse = captureMouse; | |
| 5972 | + if (_captureMouse) { | |
| 5973 | + _glWidget->setCursor(QCursor(Qt::BlankCursor)); | |
| 5974 | + } else { | |
| 5975 | + _mouseCaptureTarget = QPointF(NAN, NAN); | |
| 5976 | + _glWidget->unsetCursor(); | |
| 5977 | + } | |
| 5978 | +} | |
| 5979 | + | |
| 5953 | 5980 | void Application::changeViewAsNeeded(float boomLength) { |
| 5954 | 5981 | // Switch between first and third person views as needed |
| 5955 | 5982 | // This is called when the boom length has changed |
| @@ -6300,6 +6327,15 @@ void Application::update(float deltaTime) { · 344 unmodified lines | ||
| 6300 | 6327 | PROFILE_ASYNC_END(app, "Scene Loading", ""); |
| 6301 | 6328 | } |
| 6302 | 6329 | |
| 6330 | + if (shouldCaptureMouse()) { | |
| 6331 | + QPoint point = _glWidget->mapToGlobal(_glWidget->geometry().center()); | |
| 6332 | + if (QCursor::pos() != point) { | |
| 6333 | + _mouseCaptureTarget = point; | |
| 6334 | + _ignoreMouseMove = true; | |
| 6335 | + QCursor::setPos(point); | |
| 6336 | + } | |
| 6337 | + } | |
| 6338 | + | |
| 6303 | 6339 | auto myAvatar = getMyAvatar(); |
| 6304 | 6340 | { |
| 6305 | 6341 | PerformanceTimer perfTimer("devices"); |
| @@ -6355,8 +6391,8 @@ void Application::update(float deltaTime) { · 49 unmodified lines | ||
| 6355 | 6391 | if (deltaTime > FLT_EPSILON && userInputMapper->getActionState(controller::Action::TRANSLATE_CAMERA_Z) == 0.0f) { |
| 6356 | 6392 | myAvatar->setDriveKey(MyAvatar::PITCH, -1.0f * userInputMapper->getActionState(controller::Action::PITCH)); |
| 6357 | 6393 | myAvatar->setDriveKey(MyAvatar::YAW, -1.0f * userInputMapper->getActionState(controller::Action::YAW)); |
| 6358 | − myAvatar->setDriveKey(MyAvatar::DELTA_PITCH, -1.0f * userInputMapper->getActionState(controller::Action::DELTA_PITCH)); | |
| 6359 | − myAvatar->setDriveKey(MyAvatar::DELTA_YAW, -1.0f * userInputMapper->getActionState(controller::Action::DELTA_YAW)); | |
| 6394 | + myAvatar->setDriveKey(MyAvatar::DELTA_PITCH, -_myCamera.getSensitivity() * userInputMapper->getActionState(controller::Action::DELTA_PITCH)); | |
| 6395 | + myAvatar->setDriveKey(MyAvatar::DELTA_YAW, -_myCamera.getSensitivity() * userInputMapper->getActionState(controller::Action::DELTA_YAW)); | |
| 6360 | 6396 | myAvatar->setDriveKey(MyAvatar::STEP_YAW, -1.0f * userInputMapper->getActionState(controller::Action::STEP_YAW)); |
| 6361 | 6397 | } |
| 6362 | 6398 | } |