Set Avatar _driveKeys via touch manipulation
Showing the changes to interface/src/Application.cpp (1 of 2 files). Show all
Unified · Split
| @@ -2343,6 +2343,7 @@ void Application::touchBeginEvent(QTouchEvent* event) { · 2342 unmodified lines | ||
| 2343 | 2343 | TouchEvent thisEvent(*event); // on touch begin, we don't compare to last event |
| 2344 | 2344 | _controllerScriptingInterface->emitTouchBeginEvent(thisEvent); // send events to any registered scripts |
| 2345 | 2345 | |
| 2346 | + _currentTouchEvent = thisEvent; // and we reset our current event to this event before we call our update | |
| 2346 | 2347 | _lastTouchEvent = thisEvent; // and we reset our last event to this event before we call our update |
| 2347 | 2348 | touchUpdateEvent(event); |
| 2348 | 2349 | |
| @@ -2361,7 +2362,9 @@ void Application::touchEndEvent(QTouchEvent* event) { · 12 unmodified lines | ||
| 2361 | 2362 | _altPressed = false; |
| 2362 | 2363 | TouchEvent thisEvent(*event, _lastTouchEvent); |
| 2363 | 2364 | _controllerScriptingInterface->emitTouchEndEvent(thisEvent); // send events to any registered scripts |
| 2365 | + _currentTouchEvent = TouchEvent(); | |
| 2364 | 2366 | _lastTouchEvent = thisEvent; |
| 2367 | + _lastTouchTimeout = 30; // timeout used as gestures can be misinterpreted for some frames | |
| 2365 | 2368 | |
| 2366 | 2369 | // if one of our scripts have asked to capture this event, then stop processing it |
| 2367 | 2370 | if (_controllerScriptingInterface->isTouchCaptured()) { |
| @@ -3154,12 +3157,55 @@ void Application::update(float deltaTime) { · 786 unmodified lines | ||
| 3154 | 3157 | myAvatar->setDriveKeys(TRANSLATE_Y, userInputMapper->getActionState(controller::Action::TRANSLATE_Y)); |
| 3155 | 3158 | myAvatar->setDriveKeys(TRANSLATE_X, userInputMapper->getActionState(controller::Action::TRANSLATE_X)); |
| 3156 | 3159 | 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 | + } | |
| 3159 | 3176 | myAvatar->setDriveKeys(STEP_YAW, -1.0f * userInputMapper->getActionState(controller::Action::STEP_YAW)); |
| 3160 | 3177 | } |
| 3161 | 3178 | } |
| 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 | + } | |
| 3163 | 3209 | } |
| 3164 | 3210 | |
| 3165 | 3211 | controller::Pose leftHand = userInputMapper->getPoseState(controller::Action::LEFT_HAND); |