History

integrate touch screen camera manipulation controls

Set Avatar _driveKeys via touch manipulation

Triplelexx committed 10 years ago

Commit fde01e01 parent 3a5ee1d2 files · +51 −3Browse files

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

Unified · Split

interface/src/Application.cpp+49−3
@@ -2343,6 +2343,7 @@ void Application::touchBeginEvent(QTouchEvent* event) { · 2342 unmodified lines
23432343 TouchEvent thisEvent(*event); // on touch begin, we don't compare to last event
23442344 _controllerScriptingInterface->emitTouchBeginEvent(thisEvent); // send events to any registered scripts
23452345
2346+ _currentTouchEvent = thisEvent; // and we reset our current event to this event before we call our update
23462347 _lastTouchEvent = thisEvent; // and we reset our last event to this event before we call our update
23472348 touchUpdateEvent(event);
23482349
@@ -2361,7 +2362,9 @@ void Application::touchEndEvent(QTouchEvent* event) { · 12 unmodified lines
23612362 _altPressed = false;
23622363 TouchEvent thisEvent(*event, _lastTouchEvent);
23632364 _controllerScriptingInterface->emitTouchEndEvent(thisEvent); // send events to any registered scripts
2365+ _currentTouchEvent = TouchEvent();
23642366 _lastTouchEvent = thisEvent;
2367+ _lastTouchTimeout = 30; // timeout used as gestures can be misinterpreted for some frames
23652368
23662369 // if one of our scripts have asked to capture this event, then stop processing it
23672370 if (_controllerScriptingInterface->isTouchCaptured()) {
@@ -3154,12 +3157,55 @@ void Application::update(float deltaTime) { · 786 unmodified lines
31543157 myAvatar->setDriveKeys(TRANSLATE_Y, userInputMapper->getActionState(controller::Action::TRANSLATE_Y));
31553158 myAvatar->setDriveKeys(TRANSLATE_X, userInputMapper->getActionState(controller::Action::TRANSLATE_X));
31563159 if (deltaTime > FLT_EPSILON) {
3157− myAvatar->setDriveKeys(PITCH, -1.0f * userInputMapper->getActionState(controller::Action::PITCH));
3158− myAvatar->setDriveKeys(YAW, -1.0f * userInputMapper->getActionState(controller::Action::YAW));
3160+ if (_currentTouchEvent.isPressed == false) {
3161+ if (_lastTouchTimeout > 0) {
3162+ --_lastTouchTimeout; // disable non-touch input for some frames to disallow interpretation as movement
3163+ } else {
3164+ myAvatar->setDriveKeys(PITCH, -1.0f * userInputMapper->getActionState(controller::Action::PITCH));
3165+ myAvatar->setDriveKeys(YAW, -1.0f * userInputMapper->getActionState(controller::Action::YAW));
3166+ }
3167+ } else {
3168+ const bool allowTouchPan = _lastTouchEvent.isPinching == false && _lastTouchEvent.isPinchOpening == false
3169+ && _lastTouchEvent.x - _currentTouchEvent.x != 0;
3170+ if (_lastTouchEvent.x > _currentTouchEvent.x && allowTouchPan) {
3171+ myAvatar->setDriveKeys(YAW, -1.0f);
3172+ } else if (_lastTouchEvent.x < _currentTouchEvent.x && allowTouchPan) {
3173+ myAvatar->setDriveKeys(YAW, 1.0f);
3174+ }
3175+ }
31593176 myAvatar->setDriveKeys(STEP_YAW, -1.0f * userInputMapper->getActionState(controller::Action::STEP_YAW));
31603177 }
31613178 }
3162− myAvatar->setDriveKeys(ZOOM, userInputMapper->getActionState(controller::Action::TRANSLATE_CAMERA_Z));
3179+
3180+ if (_currentTouchEvent.isPressed == true) {
3181+ static const float TOUCH_ZOOM_THRESHOLD = 5.0f;
3182+ const float boomLength = myAvatar->getBoomLength();
3183+ QScreen* windowScreen = getWindow()->windowHandle()->screen();
3184+ const float dpiScale = glm::clamp((float)(windowScreen->physicalDotsPerInchY() / 100.0f), 1.0f, 10.0f) * 15.0f; // at DPI 100 divide radius by 15
3185+
3186+ float scaledRadius = _lastTouchEvent.radius / dpiScale;
3187+ if (scaledRadius < TOUCH_ZOOM_THRESHOLD) {
3188+ const float extraRadiusScale = TOUCH_ZOOM_THRESHOLD / scaledRadius;
3189+ scaledRadius = _lastTouchEvent.radius / (dpiScale * extraRadiusScale);
3190+ }
3191+
3192+ if (_lastTouchEvent.isPinching == true) {
3193+ const bool boomChangeValid = boomLength - scaledRadius < 2.0f; // restrict changes to small increments to negate large jumps
3194+ if (boomChangeValid && scaledRadius < boomLength && scaledRadius > MyAvatar::ZOOM_MIN) {
3195+ myAvatar->setBoomLength(scaledRadius);
3196+ } else if (scaledRadius <= MyAvatar::ZOOM_MIN) {
3197+ _myCamera.setMode(CAMERA_MODE_FIRST_PERSON);
3198+ myAvatar->setBoomLength(MyAvatar::ZOOM_MIN);
3199+ }
3200+ } else if (_lastTouchEvent.isPinchOpening == true) {
3201+ const bool boomChangeValid = scaledRadius - boomLength < 2.0f; // restrict changes to small increments to negate large jumps
3202+ if (boomChangeValid && scaledRadius > boomLength && scaledRadius < MyAvatar::ZOOM_MAX) {
3203+ myAvatar->setBoomLength(scaledRadius);
3204+ }
3205+ }
3206+ } else {
3207+ myAvatar->setDriveKeys(ZOOM, userInputMapper->getActionState(controller::Action::TRANSLATE_CAMERA_Z));
3208+ }
31633209 }
31643210
31653211 controller::Pose leftHand = userInputMapper->getPoseState(controller::Action::LEFT_HAND);