History

Merge pull request #636 from PhilipRosedale/master

Touchlook tuned and always on!

Andrzej Kapolka committed 13 years ago

Commit 100f7c12 parents 790a48b dae79d86 files · +67 −62Browse files

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

Unified · Split

interface/src/Application.cpp+35−29
@@ -341,6 +341,7 @@ void Application::initializeGL() { · 340 unmodified lines
341341 QTimer* idleTimer = new QTimer(this);
342342 connect(idleTimer, SIGNAL(timeout()), SLOT(idle()));
343343 idleTimer->start(0);
344+ _idleLoopStdev.reset();
344345
345346 if (_justStarted) {
346347 float startupTime = (usecTimestampNow() - usecTimestamp(&_applicationStartupTime)) / 1000000.0;
@@ -878,6 +879,8 @@ void Application::touchUpdateEvent(QTouchEvent* event) { · 531 unmodified lines
878879
879880 void Application::touchBeginEvent(QTouchEvent* event) {
880881 touchUpdateEvent(event);
882+ _lastTouchAvgX = _touchAvgX;
883+ _lastTouchAvgY = _touchAvgY;
881884 }
882885
883886 void Application::touchEndEvent(QTouchEvent* event) {
@@ -961,28 +964,36 @@ static glm::vec3 getFaceVector(BoxFace face) { · 77 unmodified lines
961964 }
962965
963966 void Application::idle() {
967+
964968 timeval check;
965969 gettimeofday(&check, NULL);
966970
967971 // 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) {
970975
971976 // If we're using multi-touch look, immediately process any
972977 // touch events, and no other events.
973978 // This is necessary because id the idle() call takes longer than the
974979 // interval between idle() calls, the event loop never gets to run,
975980 // 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));
984987 _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+ }
986997 }
987998 }
988999 void Application::terminate() {
@@ -1496,10 +1507,6 @@ void Application::initMenu() { · 507 unmodified lines
14961507 optionsMenu->addAction("Noise", this, SLOT(setNoise(bool)), Qt::Key_N)->setCheckable(true);
14971508 (_gyroLook = optionsMenu->addAction("Smooth Gyro Look"))->setCheckable(true);
14981509 _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);
15031510 (_showHeadMouse = optionsMenu->addAction("Head Mouse"))->setCheckable(true);
15041511 _showHeadMouse->setChecked(false);
15051512 (_transmitterDrives = optionsMenu->addAction("Transmitter Drive"))->setCheckable(true);
@@ -1700,7 +1707,7 @@ void Application::init() { · 194 unmodified lines
17001707 LeapManager::initialize();
17011708
17021709 gettimeofday(&_timerStart, NULL);
1703− gettimeofday(&_lastTimeIdle, NULL);
1710+ gettimeofday(&_lastTimeUpdated, NULL);
17041711
17051712 loadSettings();
17061713 if (!shouldDynamicallySetJitterBuffer()) {
@@ -1847,20 +1854,19 @@ void Application::update(float deltaTime) { · 140 unmodified lines
18471854 if (_myAvatar.getMode() == AVATAR_MODE_WALKING) {
18481855 _handControl.stop();
18491856 }
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+
18601858 // 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;
18641870 }
18651871
18661872 // Leap finger-sensing device

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