Touchlook tuned and always on!
Showing the changes to interface/src/Application.cpp (1 of 6 files). Show all
Unified · Split
| @@ -341,6 +341,7 @@ void Application::initializeGL() { · 340 unmodified lines | ||
| 341 | 341 | QTimer* idleTimer = new QTimer(this); |
| 342 | 342 | connect(idleTimer, SIGNAL(timeout()), SLOT(idle())); |
| 343 | 343 | idleTimer->start(0); |
| 344 | + _idleLoopStdev.reset(); | |
| 344 | 345 | |
| 345 | 346 | if (_justStarted) { |
| 346 | 347 | float startupTime = (usecTimestampNow() - usecTimestamp(&_applicationStartupTime)) / 1000000.0; |
| @@ -878,6 +879,8 @@ void Application::touchUpdateEvent(QTouchEvent* event) { · 531 unmodified lines | ||
| 878 | 879 | |
| 879 | 880 | void Application::touchBeginEvent(QTouchEvent* event) { |
| 880 | 881 | touchUpdateEvent(event); |
| 882 | + _lastTouchAvgX = _touchAvgX; | |
| 883 | + _lastTouchAvgY = _touchAvgY; | |
| 881 | 884 | } |
| 882 | 885 | |
| 883 | 886 | void Application::touchEndEvent(QTouchEvent* event) { |
| @@ -961,28 +964,36 @@ static glm::vec3 getFaceVector(BoxFace face) { · 77 unmodified lines | ||
| 961 | 964 | } |
| 962 | 965 | |
| 963 | 966 | void Application::idle() { |
| 967 | + | |
| 964 | 968 | timeval check; |
| 965 | 969 | gettimeofday(&check, NULL); |
| 966 | 970 | |
| 967 | 971 | // Only run simulation code if more than IDLE_SIMULATE_MSECS have passed since last time we ran |
| 968 | − | |
| 969 | − if (diffclock(&_lastTimeIdle, &check) > IDLE_SIMULATE_MSECS) { | |
| 972 | + | |
| 973 | + double timeSinceLastUpdate = diffclock(&_lastTimeUpdated, &check); | |
| 974 | + if (timeSinceLastUpdate > IDLE_SIMULATE_MSECS) { | |
| 970 | 975 | |
| 971 | 976 | // If we're using multi-touch look, immediately process any |
| 972 | 977 | // touch events, and no other events. |
| 973 | 978 | // This is necessary because id the idle() call takes longer than the |
| 974 | 979 | // interval between idle() calls, the event loop never gets to run, |
| 975 | 980 | // and touch events get delayed. |
| 976 | − if (_touchLook->isChecked()) { | |
| 977 | − sendPostedEvents(NULL, QEvent::TouchBegin); | |
| 978 | − sendPostedEvents(NULL, QEvent::TouchUpdate); | |
| 979 | − sendPostedEvents(NULL, QEvent::TouchEnd); | |
| 980 | − } | |
| 981 | − | |
| 982 | − update(1.0f / _fps); | |
| 983 | − | |
| 981 | + sendPostedEvents(NULL, QEvent::TouchBegin); | |
| 982 | + sendPostedEvents(NULL, QEvent::TouchUpdate); | |
| 983 | + sendPostedEvents(NULL, QEvent::TouchEnd); | |
| 984 | + | |
| 985 | + const float BIGGEST_DELTA_TIME_SECS = 0.25f; | |
| 986 | + update(glm::clamp((float)timeSinceLastUpdate / 1000.f, 0.f, BIGGEST_DELTA_TIME_SECS)); | |
| 984 | 987 | _glWidget->updateGL(); |
| 985 | − _lastTimeIdle = check; | |
| 988 | + _lastTimeUpdated = check; | |
| 989 | + _idleLoopStdev.addValue(timeSinceLastUpdate); | |
| 990 | + | |
| 991 | + // Record standard deviation and reset counter if needed | |
| 992 | + const int STDEV_SAMPLES = 500; | |
| 993 | + if (_idleLoopStdev.getSamples() > STDEV_SAMPLES) { | |
| 994 | + _idleLoopMeasuredJitter = _idleLoopStdev.getStDev(); | |
| 995 | + _idleLoopStdev.reset(); | |
| 996 | + } | |
| 986 | 997 | } |
| 987 | 998 | } |
| 988 | 999 | void Application::terminate() { |
| @@ -1496,10 +1507,6 @@ void Application::initMenu() { · 507 unmodified lines | ||
| 1496 | 1507 | optionsMenu->addAction("Noise", this, SLOT(setNoise(bool)), Qt::Key_N)->setCheckable(true); |
| 1497 | 1508 | (_gyroLook = optionsMenu->addAction("Smooth Gyro Look"))->setCheckable(true); |
| 1498 | 1509 | _gyroLook->setChecked(true); |
| 1499 | − (_mouseLook = optionsMenu->addAction("Mouse Look"))->setCheckable(true); | |
| 1500 | − _mouseLook->setChecked(true); | |
| 1501 | − (_touchLook = optionsMenu->addAction("Touch Look"))->setCheckable(true); | |
| 1502 | − _touchLook->setChecked(false); | |
| 1503 | 1510 | (_showHeadMouse = optionsMenu->addAction("Head Mouse"))->setCheckable(true); |
| 1504 | 1511 | _showHeadMouse->setChecked(false); |
| 1505 | 1512 | (_transmitterDrives = optionsMenu->addAction("Transmitter Drive"))->setCheckable(true); |
| @@ -1700,7 +1707,7 @@ void Application::init() { · 194 unmodified lines | ||
| 1700 | 1707 | LeapManager::initialize(); |
| 1701 | 1708 | |
| 1702 | 1709 | gettimeofday(&_timerStart, NULL); |
| 1703 | − gettimeofday(&_lastTimeIdle, NULL); | |
| 1710 | + gettimeofday(&_lastTimeUpdated, NULL); | |
| 1704 | 1711 | |
| 1705 | 1712 | loadSettings(); |
| 1706 | 1713 | if (!shouldDynamicallySetJitterBuffer()) { |
| @@ -1847,20 +1854,19 @@ void Application::update(float deltaTime) { · 140 unmodified lines | ||
| 1847 | 1854 | if (_myAvatar.getMode() == AVATAR_MODE_WALKING) { |
| 1848 | 1855 | _handControl.stop(); |
| 1849 | 1856 | } |
| 1850 | − | |
| 1851 | − // Update from Mouse | |
| 1852 | − if (_mouseLook->isChecked()) { | |
| 1853 | − QPoint mouse = QCursor::pos(); | |
| 1854 | − _myAvatar.updateFromMouse(_glWidget->mapFromGlobal(mouse).x(), | |
| 1855 | − _glWidget->mapFromGlobal(mouse).y(), | |
| 1856 | − _glWidget->width(), | |
| 1857 | − _glWidget->height()); | |
| 1858 | − } | |
| 1859 | − | |
| 1857 | + | |
| 1860 | 1858 | // Update from Touch |
| 1861 | − if (_isTouchPressed && _touchLook->isChecked()) { | |
| 1862 | − _myAvatar.updateFromTouch(_touchAvgX - _touchDragStartedAvgX, | |
| 1863 | − _touchAvgY - _touchDragStartedAvgY); | |
| 1859 | + if (_isTouchPressed) { | |
| 1860 | + float TOUCH_YAW_SCALE = -50.0f; | |
| 1861 | + float TOUCH_PITCH_SCALE = -50.0f; | |
| 1862 | + _myAvatar.getHead().addYaw((_touchAvgX - _lastTouchAvgX) | |
| 1863 | + * TOUCH_YAW_SCALE | |
| 1864 | + * deltaTime); | |
| 1865 | + _myAvatar.getHead().addPitch((_touchAvgY - _lastTouchAvgY) | |
| 1866 | + * TOUCH_PITCH_SCALE | |
| 1867 | + * deltaTime); | |
| 1868 | + _lastTouchAvgX = _touchAvgX; | |
| 1869 | + _lastTouchAvgY = _touchAvgY; | |
| 1864 | 1870 | } |
| 1865 | 1871 | |
| 1866 | 1872 | // Leap finger-sensing device |