Skip to content

Commit

Permalink
Capture pointer input during move gestures. Improve curved keyboard m…
Browse files Browse the repository at this point in the history
…ove. (#1500)
  • Loading branch information
MortimerGoro committed Aug 6, 2019
1 parent 62f53ae commit 9f2e0c0
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ private void placeWindow(@NonNull WindowWidget aWindow, WindowPlacement aPositio
WidgetPlacement placement = aWindow.getPlacement();
aWindow.setWindowPlacement(aPosition);
boolean curved = SettingsStore.getInstance(mContext).getCylinderDensity() > 0;
Log.e("VRB", "mortimer curved: " + curved);
switch (aPosition) {
case FRONT:
placement.anchorX = 0.5f;
Expand Down
22 changes: 16 additions & 6 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
continue;
}

vrb::Vector start = controller.transformMatrix.MultiplyPosition(controller.beamTransformMatrix.MultiplyPosition(vrb::Vector()));
vrb::Vector direction = controller.transformMatrix.MultiplyDirection(controller.beamTransformMatrix.MultiplyDirection(vrb::Vector(0.0f, 0.0f, -1.0f)));
const vrb::Vector start = controller.StartPoint();
const vrb::Vector direction = controller.Direction();

WidgetPtr hitWidget;
float hitDistance = farClip;
Expand All @@ -373,11 +373,15 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
// Don't interact with other widgets when resizing gesture is active.
continue;
}
if (movingWidget && movingWidget->GetWidget() != widget) {
// Don't interact with other widgets when moving gesture is active.
continue;
}
vrb::Vector result;
vrb::Vector normal;
float distance = 0.0f;
bool isInWidget = false;
const bool clamp = !widget->IsResizing();
const bool clamp = !widget->IsResizing() && !movingWidget;
if (widget->TestControllerIntersection(start, direction, result, normal, clamp, isInWidget, distance)) {
if (isInWidget && (distance < hitDistance)) {
hitWidget = widget;
Expand Down Expand Up @@ -954,8 +958,9 @@ BrowserWorld::StartWidgetMove(int32_t aHandle, int32_t aMoveBehavour) {
return;
}

vrb::Vector initialPoint;
vrb::Vector anchorPoint;
vrb::Vector start;
vrb::Vector direction;
int controllerIndex = -1;

for (Controller& controller: m.controllers->GetControllers()) {
Expand All @@ -965,7 +970,8 @@ BrowserWorld::StartWidgetMove(int32_t aHandle, int32_t aMoveBehavour) {

if (controller.pointer && controller.pointer->GetHitWidget() == widget) {
controllerIndex = controller.index;
initialPoint = controller.pointerWorldPoint;
start = controller.StartPoint();
direction = controller.Direction();
int32_t w, h;
widget->GetSurfaceTextureSize(w, h);
anchorPoint.x() = controller.pointerX / (float)w;
Expand All @@ -979,7 +985,11 @@ BrowserWorld::StartWidgetMove(int32_t aHandle, int32_t aMoveBehavour) {
}

m.movingWidget = WidgetMover::Create();
m.movingWidget->StartMoving(widget, aMoveBehavour, controllerIndex, initialPoint, anchorPoint);
WidgetPtr parent;
if (widget->GetPlacement()->parentHandle) {
parent = m.GetWidget(widget->GetPlacement()->parentHandle);
}
m.movingWidget->StartMoving(widget, parent, aMoveBehavour, controllerIndex, start, direction, anchorPoint);
}

void
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/cpp/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ Controller::Reset() {
lastHoverEvent = 0.0;
}

vrb::Vector Controller::StartPoint() const {
return transformMatrix.MultiplyPosition(beamTransformMatrix.MultiplyPosition(vrb::Vector()));
}

vrb::Vector Controller::Direction() const {
return transformMatrix.MultiplyDirection(beamTransformMatrix.MultiplyDirection(vrb::Vector(0.0f, 0.0f, -1.0f)));
}

void
Controller::DetachRoot() {
if (transform) {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/cpp/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ struct Controller {
double lastHoverEvent;
device::CapabilityFlags deviceCapabilities;

vrb::Vector StartPoint() const;
vrb::Vector Direction() const;

Controller();
Controller(const Controller& aController);
~Controller();
Expand Down
47 changes: 37 additions & 10 deletions app/src/main/cpp/WidgetMover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum class WidgetMoveBehaviour {

struct WidgetMover::State {
WidgetPtr widget;
WidgetPtr parentWidget;
int attachedController;
vrb::Vector initialPoint;
vrb::Vector anchorPoint;
Expand All @@ -39,17 +40,41 @@ struct WidgetMover::State {
, endRotation(0)
{}

vrb::Vector ProjectPoint(const vrb::Vector& aWorldPoint) const {
if (widget->GetCylinder()) {

vrb::Vector ProjectPoint(const WidgetPtr& aWidget, const vrb::Vector& aWorldPoint) const {
if (aWidget->GetCylinder()) {
// For a cylinder project the point to the virtual quad.
vrb::Vector min, max;
widget->GetWidgetMinAndMax(min, max);
vrb::Vector point = widget->GetCylinder()->ProjectPointToQuad(aWorldPoint, 0.5f, widget->GetCylinderDensity(), min, max);
return widget->GetTransformNode()->GetWorldTransform().MultiplyPosition(point);
aWidget->GetWidgetMinAndMax(min, max);
vrb::Vector point = aWidget->GetCylinder()->ProjectPointToQuad(aWorldPoint, 0.5f, aWidget->GetCylinderDensity(), min, max);
return aWidget->GetTransformNode()->GetWorldTransform().MultiplyPosition(point);
} else {
return aWorldPoint;
}
}

vrb::Vector GetMovePoint(const vrb::Vector& aStart, const vrb::Vector& aDirection) const {
float hitDistance = -1;
vrb::Vector hitPoint;
vrb::Vector hitNormal;
bool isInWidget = false;
widget->TestControllerIntersection(aStart, aDirection, hitPoint, hitNormal, false, isInWidget, hitDistance);

vrb::Vector result = ProjectPoint(widget, hitPoint);

if (parentWidget && moveBehaviour == WidgetMoveBehaviour::KEYBOARD && widget->GetCylinder()) {
// For Cylindrical keyboard move we want to use the x translation from the parent widget (the window)
parentWidget->TestControllerIntersection(aStart, aDirection, hitPoint, hitNormal, false, isInWidget, hitDistance);
if (hitDistance >= 0) {
vrb::Vector point = ProjectPoint(parentWidget, hitPoint);
result.x() = point.x();
result.z() = point.z();
}
}

return result;
}

WidgetPlacementPtr& HandleKeyboardMove(const vrb::Vector& aDelta) {
float x = initialPlacement->translation.x() * WidgetPlacement::kWorldDPIRatio;
float y = initialPlacement->translation.y() * WidgetPlacement::kWorldDPIRatio;
Expand Down Expand Up @@ -85,7 +110,7 @@ struct WidgetMover::State {
angle = t * maxAngle;
}

float t = 0.0f;
float t;
if (y > 1.45f) {
t = 1.0f;
} else {
Expand Down Expand Up @@ -121,7 +146,7 @@ WidgetMover::HandleMove(const vrb::Vector& aStart, const vrb::Vector& aDirection
if (hitDistance < 0) {
return nullptr;
};
hitPoint = m.ProjectPoint(hitPoint);
hitPoint = m.GetMovePoint(aStart, aDirection);

vrb::Vector delta = hitPoint - m.initialPoint;
delta.y() = hitPoint.y() - m.initialPoint.y();
Expand All @@ -145,16 +170,17 @@ WidgetMover::HandleMove(const vrb::Vector& aStart, const vrb::Vector& aDirection
}

void
WidgetMover::StartMoving(const WidgetPtr& aWidget, const int32_t aMoveBehaviour, const int32_t aControllerIndex,
const vrb::Vector& aHitPoint, const vrb::Vector& aAnchorPoint) {
WidgetMover::StartMoving(const WidgetPtr& aWidget, const WidgetPtr& aParentWidget, const int32_t aMoveBehaviour, const int32_t aControllerIndex,
const vrb::Vector& aStart, const vrb::Vector& aDirection, const vrb::Vector& aAnchorPoint) {
m.widget = aWidget;
m.parentWidget = aParentWidget;
m.attachedController = aControllerIndex;
m.initialTransform = aWidget->GetTransform();
m.initialPoint = m.ProjectPoint(aHitPoint);
m.anchorPoint = aAnchorPoint;
m.initialPlacement = aWidget->GetPlacement();
m.movePlacement = WidgetPlacement::Create(*m.initialPlacement);
m.moveBehaviour = (WidgetMoveBehaviour) aMoveBehaviour;
m.initialPoint = m.GetMovePoint(aStart, aDirection);
}

void
Expand All @@ -164,6 +190,7 @@ WidgetMover::EndMoving() {
VRBrowser::HandleMoveEnd(m.widget->GetHandle(), m.endDelta.x(), m.endDelta.y(), m.endDelta.z(), m.endRotation);
}
m.widget = nullptr;
m.parentWidget = nullptr;
}

WidgetPtr
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/WidgetMover.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class WidgetMover {
static WidgetMoverPtr Create();
bool IsMoving(const int aControllerIndex) const;
WidgetPlacementPtr HandleMove(const vrb::Vector& aStart, const vrb::Vector& aDirection);
void StartMoving(const WidgetPtr& aWidget, const int32_t aMoveBehavour, const int32_t aControllerIndex,
const vrb::Vector& aHitPoint, const vrb::Vector& aAnchorPoint);
void StartMoving(const WidgetPtr& aWidget, const WidgetPtr& aParentWidget, const int32_t aMoveBehavour, const int32_t aControllerIndex,
const vrb::Vector& aStart, const vrb::Vector& aDirection, const vrb::Vector& aAnchorPoint);
void EndMoving();
WidgetPtr GetWidget() const;
protected:
Expand Down

0 comments on commit 9f2e0c0

Please sign in to comment.