@@ -365,6 +365,23 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
365365 continue ;
366366 }
367367
368+ const bool pressed = controller.buttonState & ControllerDelegate::BUTTON_TRIGGER ||
369+ controller.buttonState & ControllerDelegate::BUTTON_TOUCHPAD;
370+ const bool wasPressed = controller.lastButtonState & ControllerDelegate::BUTTON_TRIGGER ||
371+ controller.lastButtonState & ControllerDelegate::BUTTON_TOUCHPAD;
372+
373+ bool dragging = false ;
374+ bool wasDragging = false ;
375+ if (wasPressed) {
376+ if (pressed) {
377+ if (controller.widget ) {
378+ dragging = true ;
379+ }
380+ } else {
381+ wasDragging = true ;
382+ }
383+ }
384+
368385 const vrb::Vector start = controller.StartPoint ();
369386 const vrb::Vector direction = controller.Direction ();
370387
@@ -373,7 +390,8 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
373390 vrb::Vector hitPoint;
374391 vrb::Vector hitNormal;
375392
376- for (const WidgetPtr& widget: widgets) {
393+ if (dragging) {
394+ WidgetPtr widget = GetWidget (controller.widget );
377395 if (resizingWidget && resizingWidget->IsResizingActive () && resizingWidget != widget) {
378396 // Don't interact with other widgets when resizing gesture is active.
379397 continue ;
@@ -386,13 +404,35 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
386404 vrb::Vector normal;
387405 float distance = 0 .0f ;
388406 bool isInWidget = false ;
389- const bool clamp = !widget->IsResizing () && !movingWidget;
407+ const bool clamp = !widget->IsResizing () && !movingWidget && !dragging ;
390408 if (widget->TestControllerIntersection (start, direction, result, normal, clamp, isInWidget, distance)) {
391- if (isInWidget && (distance < hitDistance)) {
392409 hitWidget = widget;
393- hitDistance = distance;
394410 hitPoint = result;
395411 hitNormal = normal;
412+ }
413+
414+ } else {
415+ for (const WidgetPtr& widget: widgets) {
416+ if (resizingWidget && resizingWidget->IsResizingActive () && resizingWidget != widget) {
417+ // Don't interact with other widgets when resizing gesture is active.
418+ continue ;
419+ }
420+ if (movingWidget && movingWidget->GetWidget () != widget) {
421+ // Don't interact with other widgets when moving gesture is active.
422+ continue ;
423+ }
424+ vrb::Vector result;
425+ vrb::Vector normal;
426+ float distance = 0 .0f ;
427+ bool isInWidget = false ;
428+ const bool clamp = !widget->IsResizing () && !movingWidget;
429+ if (widget->TestControllerIntersection (start, direction, result, normal, clamp, isInWidget, distance)) {
430+ if (isInWidget && (distance < hitDistance)) {
431+ hitWidget = widget;
432+ hitDistance = distance;
433+ hitPoint = result;
434+ hitNormal = normal;
435+ }
396436 }
397437 }
398438 }
@@ -405,7 +445,7 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
405445 if (controller.pointer ) {
406446 controller.pointer ->SetVisible (hitWidget.get () != nullptr );
407447 controller.pointer ->SetHitWidget (hitWidget);
408- if (hitWidget) {
448+ if (hitWidget || dragging ) {
409449 vrb::Matrix translation = vrb::Matrix::Translation (hitPoint);
410450 vrb::Matrix localRotation = vrb::Matrix::Rotation (hitNormal);
411451 vrb::Matrix reorient = device->GetReorientTransform ();
@@ -414,11 +454,6 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
414454 }
415455 }
416456
417- const bool pressed = controller.buttonState & ControllerDelegate::BUTTON_TRIGGER ||
418- controller.buttonState & ControllerDelegate::BUTTON_TOUCHPAD;
419- const bool wasPressed = controller.lastButtonState & ControllerDelegate::BUTTON_TRIGGER ||
420- controller.lastButtonState & ControllerDelegate::BUTTON_TOUCHPAD;
421-
422457 if (movingWidget && movingWidget->IsMoving (controller.index )) {
423458 if (!pressed && wasPressed) {
424459 movingWidget->EndMoving ();
@@ -498,6 +533,9 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
498533 }
499534 }
500535 } else if (controller.widget ) {
536+ if (wasDragging) {
537+ VRBrowser::HandleMotionEvent (controller.widget , controller.index , (jboolean) pressed, controller.lastTouchX , controller.lastTouchY );
538+ }
501539 VRBrowser::HandleMotionEvent (0 , controller.index , (jboolean) pressed, 0 .0f , 0 .0f );
502540 controller.widget = 0 ;
503541
0 commit comments