History

Merge pull request #3937 from Atlante45/mouse_pick_in_oculus

Mouse pick improvments

Brad Hefta-Gaub committed 11 years ago

Commit 69f7a892 parents d54d7c7 dc4c9cd5 files · +40 −120Browse files

Showing the changes to interface/src/Application.cpp (1 of 5 files). Show all

Unified · Split

interface/src/Application.cpp+34−63
@@ -167,8 +167,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) : · 166 unmodified lines
167167 _raiseMirror(0.0f),
168168 _lastMouseMove(usecTimestampNow()),
169169 _lastMouseMoveWasSimulated(false),
170− _mouseHidden(false),
171− _seenMouseMove(false),
172170 _touchAvgX(0.0f),
173171 _touchAvgY(0.0f),
174172 _isTouchPressed(false),
@@ -1130,7 +1128,8 @@ void Application::keyPressEvent(QKeyEvent* event) { · 955 unmodified lines
11301128 if (!event->isAutoRepeat()) {
11311129 // this starts an HFActionEvent
11321130 HFActionEvent startActionEvent(HFActionEvent::startType(),
1133− _myCamera.computeViewPickRay(0.5f, 0.5f));
1131+ _myCamera.computePickRay(getTrueMouseX(),
1132+ getTrueMouseY()));
11341133 sendEvent(this, &startActionEvent);
11351134 }
11361135
@@ -1221,10 +1220,11 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 84 unmodified lines
12211220 case Qt::Key_Space: {
12221221 if (!event->isAutoRepeat()) {
12231222 // 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()));
12251226 sendEvent(this, &endActionEvent);
12261227 }
1227−
12281228 break;
12291229 }
12301230 case Qt::Key_Escape: {
@@ -1233,7 +1233,6 @@ void Application::keyReleaseEvent(QKeyEvent* event) { · 2 unmodified lines
12331233 HFBackEvent endBackEvent(HFBackEvent::endType());
12341234 sendEvent(this, &endBackEvent);
12351235 }
1236−
12371236 break;
12381237 }
12391238 default:
@@ -1252,34 +1251,24 @@ void Application::focusOutEvent(QFocusEvent* event) { · 12 unmodified lines
12521251 }
12531252
12541253 void Application::mouseMoveEvent(QMouseEvent* event, unsigned int deviceID) {
1255− bool showMouse = true;
1256−
12571254 // Used by application overlay to determine how to draw cursor(s)
12581255 _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();
12631258 }
12641259
1265− if (!_aboutToQuit) {
1266− _entities.mouseMoveEvent(event, deviceID);
1260+ if (_aboutToQuit) {
1261+ return;
12671262 }
1268−
1263+
1264+ _entities.mouseMoveEvent(event, deviceID);
1265+
12691266 _controllerScriptingInterface.emitMouseMoveEvent(event, deviceID); // send events to any registered scripts
1270−
12711267 // if one of our scripts have asked to capture this event, then stop processing it
12721268 if (_controllerScriptingInterface.isMouseCaptured()) {
12731269 return;
12741270 }
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+
12831272 }
12841273
12851274 void Application::mousePressEvent(QMouseEvent* event, unsigned int deviceID) {
@@ -2111,13 +2100,7 @@ void Application::updateMouseRay() { · 825 unmodified lines
21112100 // make sure the frustum is up-to-date
21122101 loadViewFrustum(_myCamera, _viewFrustum);
21132102
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());
21212104 _mouseRayOrigin = pickRay.origin;
21222105 _mouseRayDirection = pickRay.direction;
21232106
@@ -2313,22 +2296,29 @@ void Application::updateCursor(float deltaTime) { · 189 unmodified lines
23132296 bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings);
23142297 PerformanceWarning warn(showWarnings, "Application::updateCursor()");
23152298
2316− // watch mouse position, if it hasn't moved, hide the cursor
2299+ bool hideMouse = false;
23172300 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();
23252316 }
23262317 } 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);
23322322 }
23332323 }
23342324 }
@@ -2350,17 +2340,6 @@ void Application::update(float deltaTime) { · 15 unmodified lines
23502340
23512341 }
23522342
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−
23642343 // Dispatch input events
23652344 _controllerScriptingInterface.updateInputControllers();
23662345
@@ -4377,14 +4356,6 @@ void Application::skipVersion(QString latestVersion) { · 2010 unmodified lines
43774356 skipFile.write(latestVersion.toStdString().c_str());
43784357 }
43794358
4380−void Application::setCursorVisible(bool visible) {
4381− if (visible) {
4382− restoreOverrideCursor();
4383− } else {
4384− setOverrideCursor(Qt::BlankCursor);
4385− }
4386−}
4387−
43884359 void Application::takeSnapshot() {
43894360 QMediaPlayer* player = new QMediaPlayer();
43904361 QFileInfo inf = QFileInfo(Application::resourcesPath() + "sounds/snap.wav");

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t