Showing the changes to interface/src/Application.cpp (1 of 71 files). Show all
Unified · Split
| @@ -37,6 +37,7 @@ · 36 unmodified lines | ||
| 37 | 37 | #include <QOpenGLFramebufferObject> |
| 38 | 38 | #include <QObject> |
| 39 | 39 | #include <QWheelEvent> |
| 40 | +#include <QScreen> | |
| 40 | 41 | #include <QSettings> |
| 41 | 42 | #include <QShortcut> |
| 42 | 43 | #include <QTimer> |
| @@ -142,6 +143,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 99 unmodified lines | ||
| 142 | 143 | QApplication(argc, argv), |
| 143 | 144 | _window(new MainWindow(desktop())), |
| 144 | 145 | _glWidget(new GLCanvas()), |
| 146 | + _toolWindow(NULL), | |
| 145 | 147 | _nodeThread(new QThread(this)), |
| 146 | 148 | _datagramProcessor(), |
| 147 | 149 | _undoStack(), |
| @@ -168,8 +170,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 20 unmodified lines | ||
| 168 | 170 | _raiseMirror(0.0f), |
| 169 | 171 | _lastMouseMove(usecTimestampNow()), |
| 170 | 172 | _lastMouseMoveWasSimulated(false), |
| 171 | − _mouseHidden(false), | |
| 172 | − _seenMouseMove(false), | |
| 173 | 173 | _touchAvgX(0.0f), |
| 174 | 174 | _touchAvgY(0.0f), |
| 175 | 175 | _isTouchPressed(false), |
| @@ -418,9 +418,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 242 unmodified lines | ||
| 418 | 418 | _previousScriptLocation = _settings->value("LastScriptLocation", QVariant("")).toString(); |
| 419 | 419 | } |
| 420 | 420 | |
| 421 | − connect(_window, &MainWindow::windowGeometryChanged, | |
| 422 | − _runningScriptsWidget, &RunningScriptsWidget::setBoundary); | |
| 423 | − | |
| 424 | 421 | _trayIcon->show(); |
| 425 | 422 | |
| 426 | 423 | // set the local loopback interface for local sounds from audio scripts |
| @@ -1131,7 +1128,8 @@ void Application::keyPressEvent(QKeyEvent* event) { · 704 unmodified lines | ||
| 1131 | 1128 | if (!event->isAutoRepeat()) { |
| 1132 | 1129 | // this starts an HFActionEvent |
| 1133 | 1130 | HFActionEvent startActionEvent(HFActionEvent::startType(), |
| 1134 | − _myCamera.computeViewPickRay(0.5f, 0.5f)); | |
| 1131 | + _myCamera.computePickRay(getTrueMouseX(), | |
| 1132 | + getTrueMouseY())); | |
| 1135 | 1133 | sendEvent(this, &startActionEvent); |
| 1136 | 1134 | } |
| 1137 | 1135 | |
| @@ -1222,10 +1220,11 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 84 unmodified lines | ||
| 1222 | 1220 | case Qt::Key_Space: { |
| 1223 | 1221 | if (!event->isAutoRepeat()) { |
| 1224 | 1222 | // this ends the HFActionEvent |
| 1225 | − HFActionEvent endActionEvent(HFActionEvent::endType(), _myCamera.computeViewPickRay(0.5f, 0.5f)); | |
| 1223 | + HFActionEvent endActionEvent(HFActionEvent::endType(), | |
| 1224 | + _myCamera.computePickRay(getTrueMouseX(), | |
| 1225 | + getTrueMouseY())); | |
| 1226 | 1226 | sendEvent(this, &endActionEvent); |
| 1227 | 1227 | } |
| 1228 | − | |
| 1229 | 1228 | break; |
| 1230 | 1229 | } |
| 1231 | 1230 | case Qt::Key_Escape: { |
| @@ -1234,7 +1233,6 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 2 unmodified lines | ||
| 1234 | 1233 | HFBackEvent endBackEvent(HFBackEvent::endType()); |
| 1235 | 1234 | sendEvent(this, &endBackEvent); |
| 1236 | 1235 | } |
| 1237 | − | |
| 1238 | 1236 | break; |
| 1239 | 1237 | } |
| 1240 | 1238 | default: |
| @@ -1253,34 +1251,24 @@ void Application::focusOutEvent(QFocusEvent* event) { · 12 unmodified lines | ||
| 1253 | 1251 | } |
| 1254 | 1252 | |
| 1255 | 1253 | void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) { |
| 1256 | − bool showMouse = true; | |
| 1257 | − | |
| 1258 | 1254 | // Used by application overlay to determine how to draw cursor(s) |
| 1259 | 1255 | _lastMouseMoveWasSimulated = deviceID > 0; |
| 1260 | − | |
| 1261 | − // If this mouse move event is emitted by a controller, dont show the mouse cursor | |
| 1262 | − if (_lastMouseMoveWasSimulated) { | |
| 1263 | − showMouse = false; | |
| 1256 | + if (!_lastMouseMoveWasSimulated) { | |
| 1257 | + _lastMouseMove = usecTimestampNow(); | |
| 1264 | 1258 | } |
| 1265 | 1259 | |
| 1266 | − if (!_aboutToQuit) { | |
| 1267 | − _entities.mouseMoveEvent(event, deviceID); | |
| 1260 | + if (_aboutToQuit) { | |
| 1261 | + return; | |
| 1268 | 1262 | } |
| 1269 | − | |
| 1263 | + | |
| 1264 | + _entities.mouseMoveEvent(event, deviceID); | |
| 1265 | + | |
| 1270 | 1266 | _controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts |
| 1271 | − | |
| 1272 | 1267 | // if one of our scripts have asked to capture this event, then stop processing it |
| 1273 | 1268 | if (_controllerScriptingInterface.isMouseCaptured()) { |
| 1274 | 1269 | return; |
| 1275 | 1270 | } |
| 1276 | − | |
| 1277 | − _lastMouseMove = usecTimestampNow(); | |
| 1278 | − | |
| 1279 | − if (_mouseHidden && showMouse && !OculusManager::isConnected() && !TV3DManager::isConnected()) { | |
| 1280 | − getGLWidget()->setCursor(Qt::ArrowCursor); | |
| 1281 | − _mouseHidden = false; | |
| 1282 | − _seenMouseMove = true; | |
| 1283 | − } | |
| 1271 | + | |
| 1284 | 1272 | } |
| 1285 | 1273 | |
| 1286 | 1274 | void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) { |
| @@ -1929,8 +1917,6 @@ void Application::init() { · 642 unmodified lines | ||
| 1929 | 1917 | _deferredLightingEffect.init(); |
| 1930 | 1918 | _glowEffect.init(); |
| 1931 | 1919 | _ambientOcclusionEffect.init(); |
| 1932 | − _voxelShader.init(); | |
| 1933 | − _pointShader.init(); | |
| 1934 | 1920 | |
| 1935 | 1921 | // TODO: move _myAvatar out of Application. Move relevant code to MyAvataar or AvatarManager |
| 1936 | 1922 | _avatarManager.init(); |
| @@ -2002,8 +1988,6 @@ void Application::init() { · 65 unmodified lines | ||
| 2002 | 1988 | |
| 2003 | 1989 | // Set up VoxelSystem after loading preferences so we can get the desired max voxel count |
| 2004 | 1990 | _voxels.setMaxVoxels(Menu::getInstance()->getMaxVoxels()); |
| 2005 | − _voxels.setUseVoxelShader(false); | |
| 2006 | − _voxels.setVoxelsAsPoints(false); | |
| 2007 | 1991 | _voxels.setDisableFastVoxelPipeline(false); |
| 2008 | 1992 | _voxels.init(); |
| 2009 | 1993 | |
| @@ -2047,17 +2031,6 @@ void Application::init() { · 37 unmodified lines | ||
| 2047 | 2031 | connect(_rearMirrorTools, SIGNAL(shrinkView()), SLOT(shrinkMirrorView())); |
| 2048 | 2032 | connect(_rearMirrorTools, SIGNAL(resetView()), SLOT(resetSensors())); |
| 2049 | 2033 | |
| 2050 | − // set up our audio reflector | |
| 2051 | − _audioReflector.setMyAvatar(getAvatar()); | |
| 2052 | − _audioReflector.setVoxels(_voxels.getTree()); | |
| 2053 | − _audioReflector.setAudio(getAudio()); | |
| 2054 | − _audioReflector.setAvatarManager(&_avatarManager); | |
| 2055 | − | |
| 2056 | − connect(getAudio(), &Audio::processInboundAudio, &_audioReflector, &AudioReflector::processInboundAudio,Qt::DirectConnection); | |
| 2057 | − connect(getAudio(), &Audio::processLocalAudio, &_audioReflector, &AudioReflector::processLocalAudio,Qt::DirectConnection); | |
| 2058 | − connect(getAudio(), &Audio::preProcessOriginalInboundAudio, &_audioReflector, | |
| 2059 | − &AudioReflector::preProcessOriginalInboundAudio,Qt::DirectConnection); | |
| 2060 | − | |
| 2061 | 2034 | connect(getAudio(), &Audio::muteToggled, AudioDeviceScriptingInterface::getInstance(), |
| 2062 | 2035 | &AudioDeviceScriptingInterface::muteToggled, Qt::DirectConnection); |
| 2063 | 2036 | |
| @@ -2113,13 +2086,7 @@ void Application::updateMouseRay() { · 49 unmodified lines | ||
| 2113 | 2086 | // make sure the frustum is up-to-date |
| 2114 | 2087 | loadViewFrustum(_myCamera, _viewFrustum); |
| 2115 | 2088 | |
| 2116 | − // if the mouse pointer isn't visible, act like it's at the center of the screen | |
| 2117 | − float x = 0.5f, y = 0.5f; | |
| 2118 | − if (!_mouseHidden) { | |
| 2119 | − x = getTrueMouseX() / (float)_glWidget->width(); | |
| 2120 | − y = getTrueMouseY() / (float)_glWidget->height(); | |
| 2121 | − } | |
| 2122 | − PickRay pickRay = _myCamera.computeViewPickRay(x, y); | |
| 2089 | + PickRay pickRay = _myCamera.computePickRay(getTrueMouseX(), getTrueMouseY()); | |
| 2123 | 2090 | _mouseRayOrigin = pickRay.origin; |
| 2124 | 2091 | _mouseRayDirection = pickRay.direction; |
| 2125 | 2092 | |
| @@ -2315,22 +2282,30 @@ void Application::updateCursor(float deltaTime) { · 189 unmodified lines | ||
| 2315 | 2282 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |
| 2316 | 2283 | PerformanceWarning warn(showWarnings, "Application::updateCursor()"); |
| 2317 | 2284 | |
| 2318 | − // watch mouse position, if it hasn't moved, hide the cursor | |
| 2319 | − bool underMouse = _glWidget->underMouse(); | |
| 2320 | − if (!_mouseHidden) { | |
| 2321 | − quint64 now = usecTimestampNow(); | |
| 2322 | − int elapsed = now - _lastMouseMove; | |
| 2323 | − const int HIDE_CURSOR_TIMEOUT = 1 * 1000 * 1000; // 1 second | |
| 2324 | − if (elapsed > HIDE_CURSOR_TIMEOUT && (underMouse || !_seenMouseMove)) { | |
| 2325 | − getGLWidget()->setCursor(Qt::BlankCursor); | |
| 2326 | − _mouseHidden = true; | |
| 2285 | + bool hideMouse = false; | |
| 2286 | + bool underMouse = QGuiApplication::topLevelAt(QCursor::pos()) == | |
| 2287 | + Application::getInstance()->getWindow()->windowHandle(); | |
| 2288 | + | |
| 2289 | + static const int HIDE_CURSOR_TIMEOUT = 3 * USECS_PER_SECOND; // 3 second | |
| 2290 | + int elapsed = usecTimestampNow() - _lastMouseMove; | |
| 2291 | + if ((elapsed > HIDE_CURSOR_TIMEOUT) || | |
| 2292 | + (OculusManager::isConnected() && Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode))) { | |
| 2293 | + hideMouse = underMouse; | |
| 2294 | + } | |
| 2295 | + | |
| 2296 | + setCursorVisible(!hideMouse); | |
| 2297 | +} | |
| 2298 | + | |
| 2299 | +void Application::setCursorVisible(bool visible) { | |
| 2300 | + if (visible) { | |
| 2301 | + if (overrideCursor() != NULL) { | |
| 2302 | + restoreOverrideCursor(); | |
| 2327 | 2303 | } |
| 2328 | 2304 | } else { |
| 2329 | − // if the mouse is hidden, but we're not inside our window, then consider ourselves to be moving | |
| 2330 | − if (!underMouse && _seenMouseMove) { | |
| 2331 | − _lastMouseMove = usecTimestampNow(); | |
| 2332 | − getGLWidget()->setCursor(Qt::ArrowCursor); | |
| 2333 | − _mouseHidden = false; | |
| 2305 | + if (overrideCursor() != NULL) { | |
| 2306 | + changeOverrideCursor(Qt::BlankCursor); | |
| 2307 | + } else { | |
| 2308 | + setOverrideCursor(Qt::BlankCursor); | |
| 2334 | 2309 | } |
| 2335 | 2310 | } |
| 2336 | 2311 | } |
| @@ -2352,17 +2327,6 @@ void Application::update(float deltaTime) { · 15 unmodified lines | ||
| 2352 | 2327 | |
| 2353 | 2328 | } |
| 2354 | 2329 | |
| 2355 | − static QCursor cursor; | |
| 2356 | − if (OculusManager::isConnected() && | |
| 2357 | − Menu::getInstance()->isOptionChecked(MenuOption::EnableVRMode)){ | |
| 2358 | − if (_window->cursor().shape() != Qt::BlankCursor) { | |
| 2359 | − cursor = _window->cursor(); | |
| 2360 | − _window->setCursor(QCursor(Qt::BlankCursor)); | |
| 2361 | − } | |
| 2362 | − } else if(_window->cursor().shape() == Qt::BlankCursor) { | |
| 2363 | − _window->setCursor(cursor); | |
| 2364 | − } | |
| 2365 | − | |
| 2366 | 2330 | // Dispatch input events |
| 2367 | 2331 | _controllerScriptingInterface.updateInputControllers(); |
| 2368 | 2332 | |
| @@ -2740,6 +2704,29 @@ bool Application::isHMDMode() const { · 371 unmodified lines | ||
| 2740 | 2704 | } |
| 2741 | 2705 | } |
| 2742 | 2706 | |
| 2707 | +QRect Application::getDesirableApplicationGeometry() { | |
| 2708 | + QRect applicationGeometry = getWindow()->geometry(); | |
| 2709 | + | |
| 2710 | + // If our parent window is on the HMD, then don't use it's geometry, instead use | |
| 2711 | + // the "main screen" geometry. | |
| 2712 | + HMDToolsDialog* hmdTools = Menu::getInstance()->getHMDToolsDialog(); | |
| 2713 | + if (hmdTools && hmdTools->hasHMDScreen()) { | |
| 2714 | + QScreen* hmdScreen = hmdTools->getHMDScreen(); | |
| 2715 | + QWindow* appWindow = getWindow()->windowHandle(); | |
| 2716 | + QScreen* appScreen = appWindow->screen(); | |
| 2717 | + | |
| 2718 | + // if our app's screen is the hmd screen, we don't want to place the | |
| 2719 | + // running scripts widget on it. So we need to pick a better screen. | |
| 2720 | + // we will use the screen for the HMDTools since it's a guarenteed | |
| 2721 | + // better screen. | |
| 2722 | + if (appScreen == hmdScreen) { | |
| 2723 | + QScreen* betterScreen = hmdTools->windowHandle()->screen(); | |
| 2724 | + applicationGeometry = betterScreen->geometry(); | |
| 2725 | + } | |
| 2726 | + } | |
| 2727 | + return applicationGeometry; | |
| 2728 | +} | |
| 2729 | + | |
| 2743 | 2730 | ///////////////////////////////////////////////////////////////////////////////////// |
| 2744 | 2731 | // loadViewFrustum() |
| 2745 | 2732 | // |
| @@ -2876,8 +2863,13 @@ void Application::updateShadowMap() { · 130 unmodified lines | ||
| 2876 | 2863 | |
| 2877 | 2864 | // store view matrix without translation, which we'll use for precision-sensitive objects |
| 2878 | 2865 | updateUntranslatedViewMatrix(); |
| 2879 | − // TODO: assign an equivalent viewTransform object to the application to match the current path which uses glMatrixStack | |
| 2880 | − // setViewTransform(viewTransform); | |
| 2866 | + | |
| 2867 | + // Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation | |
| 2868 | + // the viewTransofmr object is updatded with the correct values and saved, | |
| 2869 | + // this is what is used for rendering the Entities and avatars | |
| 2870 | + Transform viewTransform; | |
| 2871 | + viewTransform.setRotation(rotation); | |
| 2872 | + setViewTransform(viewTransform); | |
| 2881 | 2873 | |
| 2882 | 2874 | glEnable(GL_POLYGON_OFFSET_FILL); |
| 2883 | 2875 | glPolygonOffset(1.1f, 4.0f); // magic numbers courtesy http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt |
| @@ -3082,12 +3074,6 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly, RenderAr · 198 unmodified lines | ||
| 3082 | 3074 | glColor3f(1,0,0); |
| 3083 | 3075 | _geometryCache.renderSphere(originSphereRadius, 15, 15); |
| 3084 | 3076 | |
| 3085 | − // draw the audio reflector overlay | |
| 3086 | − { | |
| 3087 | − PerformanceTimer perfTimer("audio"); | |
| 3088 | − _audioReflector.render(); | |
| 3089 | − } | |
| 3090 | − | |
| 3091 | 3077 | // Draw voxels |
| 3092 | 3078 | if (Menu::getInstance()->isOptionChecked(MenuOption::Voxels)) { |
| 3093 | 3079 | PerformanceTimer perfTimer("voxels"); |
| @@ -4015,7 +4001,6 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 921 unmodified lines | ||
| 4015 | 4001 | scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance()); |
| 4016 | 4002 | scriptEngine->registerGlobalObject("AnimationCache", &_animationCache); |
| 4017 | 4003 | scriptEngine->registerGlobalObject("SoundCache", &SoundCache::getInstance()); |
| 4018 | − scriptEngine->registerGlobalObject("AudioReflector", &_audioReflector); | |
| 4019 | 4004 | scriptEngine->registerGlobalObject("Account", AccountScriptingInterface::getInstance()); |
| 4020 | 4005 | scriptEngine->registerGlobalObject("Metavoxels", &_metavoxels); |
| 4021 | 4006 | |
| @@ -4374,14 +4359,6 @@ void Application::skipVersion(QString latestVersion) { · 352 unmodified lines | ||
| 4374 | 4359 | skipFile.write(latestVersion.toStdString().c_str()); |
| 4375 | 4360 | } |
| 4376 | 4361 | |
| 4377 | −void Application::setCursorVisible(bool visible) { | |
| 4378 | − if (visible) { | |
| 4379 | − restoreOverrideCursor(); | |
| 4380 | − } else { | |
| 4381 | − setOverrideCursor(Qt::BlankCursor); | |
| 4382 | − } | |
| 4383 | −} | |
| 4384 | − | |
| 4385 | 4362 | void Application::takeSnapshot() { |
| 4386 | 4363 | QMediaPlayer* player = new QMediaPlayer(); |
| 4387 | 4364 | QFileInfo inf = QFileInfo(Application::resourcesPath() + "sounds/snap.wav"); |