Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit ff5567e

Browse files
keianhzoMortimerGoro
authored andcommitted
Support for dragging outside the widget bounds
1 parent 5e0c591 commit ff5567e

4 files changed

Lines changed: 78 additions & 14 deletions

File tree

.editorconfig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[*]
2+
charset=utf-8
3+
end_of_line=lf
4+
insert_final_newline=false
5+
indent_style=space
6+
indent_size=4
7+
8+
[*.json]
9+
indent_style=space
10+
indent_size=2
11+
12+
[*.json5]
13+
indent_style=space
14+
indent_size=2
15+
16+
[{*.yml,*.yaml}]
17+
indent_style=space
18+
indent_size=2
19+
20+
[*.cpp]
21+
indent_style=space
22+
indent_size=2
23+
24+
[*.h]
25+
indent_style=space
26+
indent_size=2

app/src/main/cpp/BrowserWorld.cpp

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

app/src/main/cpp/Widget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,12 @@ Widget::TestControllerIntersection(const vrb::Vector& aStartPoint, const vrb::Ve
338338
}
339339

340340
void
341-
Widget::ConvertToWidgetCoordinates(const vrb::Vector& point, float& aX, float& aY) const {
341+
Widget::ConvertToWidgetCoordinates(const vrb::Vector& point, float& aX, float& aY, bool aClamp) const {
342342
bool clamp = !m.resizing;
343343
if (m.quad) {
344-
m.quad->ConvertToQuadCoordinates(point, aX, aY, clamp);
344+
m.quad->ConvertToQuadCoordinates(point, aX, aY, clamp && aClamp);
345345
} else {
346-
m.cylinder->ConvertToQuadCoordinates(point, aX, aY, clamp);
346+
m.cylinder->ConvertToQuadCoordinates(point, aX, aY, clamp && aClamp);
347347
}
348348
}
349349

app/src/main/cpp/Widget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Widget {
5353
void GetWorldSize(float& aWidth, float& aHeight) const;
5454
bool TestControllerIntersection(const vrb::Vector& aStartPoint, const vrb::Vector& aDirection, vrb::Vector& aResult, vrb::Vector& aNormal,
5555
const bool aClamp, bool& aIsInWidget, float& aDistance) const;
56-
void ConvertToWidgetCoordinates(const vrb::Vector& aPoint, float& aX, float& aY) const;
56+
void ConvertToWidgetCoordinates(const vrb::Vector& aPoint, float& aX, float& aY, bool aClamp = true) const;
5757
vrb::Vector ConvertToWorldCoordinates(const vrb::Vector& aLocalPoint) const;
5858
vrb::Vector ConvertToWorldCoordinates(const float aWidgetX, const float aWidgetY) const;
5959
const vrb::Matrix GetTransform() const;

0 commit comments

Comments
 (0)