Skip to content

Commit

Permalink
Generalize pointer scaling and color change during trigger event (#1076)
Browse files Browse the repository at this point in the history
* Renames Controller::pinchFactor to Controller::selectFactor

Right now we are using the `pinchFactor` value to scale the pointer target
as a select (trigger) gesture is closing during hand-tracking.

But since we are going to extend this to controllers' trigger button, we
are renaming it to `selectFactor` to make it generic to a select event.

* Scale down and change color of pointer target during select event

This patch extends the feature we currently have for pinch gesture,
where the pointer target is scaled as the pinch gesture closes, until
it is fully closed and the color is changed to blue.

With this, we provide a nice visual cue of the trigger event to the
user, and also make Wolvic interactions more consistent.

* Reduce pointer target maximum size a bit

It was (arguably) a bit too big already, and now that we are using it
for controllers too, it makes sense to reduce it a bit.
  • Loading branch information
elima authored and felipeerias committed Oct 20, 2023
1 parent 85ce1c4 commit 04f6705
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
17 changes: 6 additions & 11 deletions app/src/main/cpp/BrowserWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const double kHoverRate = 1.0 / 10.0;
// 'azure' color, for active pinch gesture while on hand mode
const vrb::Color kPointerColorSelected = vrb::Color(0.32f, 0.56f, 0.88f);
// How big is the pointer target while in hand-tracking mode
const float kPointerPinchSize = 5.0;
const float kPointerSize = 3.0;

class SurfaceObserver;
typedef std::shared_ptr<SurfaceObserver> SurfaceObserverPtr;
Expand Down Expand Up @@ -515,16 +515,11 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
controller.pointer->SetTransform(reorient.AfineInverse().PostMultiply(translation).PostMultiply(localRotation));

const float scale = (hitPoint - device->GetHeadTransform().MultiplyPosition(vrb::Vector(0.0f, 0.0f, 0.0f))).Magnitude();
if (controller.mode == ControllerMode::Device) {
controller.pointer->SetScale(scale);
controller.pointer->SetScale(scale + kPointerSize - controller.selectFactor * kPointerSize);
if (controller.selectFactor >= 1.0f)
controller.pointer->SetPointerColor(kPointerColorSelected);
else
controller.pointer->SetPointerColor(VRBrowser::GetPointerColor());
} else {
controller.pointer->SetScale(scale + kPointerPinchSize - controller.pinchFactor * kPointerPinchSize);
if (controller.pinchFactor >= 1.0f)
controller.pointer->SetPointerColor(kPointerColorSelected);
else
controller.pointer->SetPointerColor(VRBrowser::GetPointerColor());
}
}
}

Expand Down Expand Up @@ -552,7 +547,7 @@ BrowserWorld::State::UpdateControllers(bool& aRelayoutWidgets) {
vrb::Matrix iconMatrix = vrb::Matrix::Identity();

// Scale the button down as the pinch gesture is closing
float scale = 1.0 - controller.pinchFactor * 0.5f;
float scale = 1.0 - controller.selectFactor * 0.5f;
// Make the button disappear if pinch is closed
scale = scale <= 0.5f ? 0.0f : scale;
iconMatrix.ScaleInPlace(vrb::Vector(scale, scale, scale));
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/cpp/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Controller::operator=(const Controller& aController) {
handActionEnabled = aController.handActionEnabled;
handActionButtonToggle = aController.handActionButtonToggle;
handActionButtonTransform = aController.handActionButtonTransform;
selectFactor = aController.selectFactor;
return *this;
}

Expand Down Expand Up @@ -133,6 +134,7 @@ Controller::Reset() {
handActionEnabled = false;
handActionButtonToggle = nullptr;
handActionButtonTransform = nullptr;
selectFactor = 0.0;
}

vrb::Vector Controller::StartPoint() const {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ struct Controller {
bool handActionEnabled;
vrb::TogglePtr handActionButtonToggle;
vrb::TransformPtr handActionButtonTransform;
float pinchFactor;
float selectFactor;
vrb::TransformPtr beamParent;
PointerPtr pointer;
vrb::Matrix transformMatrix;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/cpp/ControllerContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ void ControllerContainer::SetMode(const int32_t aControllerIndex, ControllerMode
m.list[aControllerIndex].mode = aMode;
}

void ControllerContainer::SetPinchFactor(const int32_t aControllerIndex, float aFactor)
void ControllerContainer::SetSelectFactor(const int32_t aControllerIndex, float aFactor)
{
if (!m.Contains(aControllerIndex))
return;
m.list[aControllerIndex].pinchFactor = aFactor;
m.list[aControllerIndex].selectFactor = aFactor;
}

void ControllerContainer::SetAimEnabled(const int32_t aControllerIndex, bool aEnabled) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/ControllerContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ControllerContainer : public crow::ControllerDelegate {
void SetAimEnabled(const int32_t aControllerIndex, bool aEnabled = true) override;
void SetHandActionEnabled(const int32_t aControllerIndex, bool aEnabled = false) override;
void SetMode(const int32_t aControllerIndex, ControllerMode aMode = ControllerMode::None) override;
void SetPinchFactor(const int32_t aControllerIndex, float aFactor = 1.0f) override;
void SetSelectFactor(const int32_t aControllerIndex, float aFactor = 1.0f) override;
void SetFrameId(const uint64_t aFrameId);
protected:
struct State;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/ControllerDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ControllerDelegate {
virtual void SetAimEnabled(const int32_t aControllerIndex, bool aEnabled = true) = 0;
virtual void SetHandActionEnabled(const int32_t aControllerIndex, bool aEnabled = false) = 0;
virtual void SetMode(const int32_t aControllerIndex, ControllerMode aMode = ControllerMode::None) = 0;
virtual void SetPinchFactor(const int32_t aControllerIndex, float aFactor = 1.0f) = 0;
virtual void SetSelectFactor(const int32_t aControllerIndex, float aFactor = 1.0f) = 0;
protected:
ControllerDelegate() {}
private:
Expand Down
5 changes: 4 additions & 1 deletion app/src/openxr/cpp/OpenXRInputSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ void OpenXRInputSource::EmulateControllerFromHand(device::RenderMode renderMode,
double pinchFactor = 0.0f;
mGestureManager->getTriggerPinchStatusAndFactor(mHandJoints, indexPinching, pinchFactor);

delegate.SetPinchFactor(mIndex, pinchFactor);
delegate.SetSelectFactor(mIndex, pinchFactor);
bool triggerButtonPressed = indexPinching && !systemGestureDetected && hasAim;
delegate.SetButtonState(mIndex, ControllerDelegate::BUTTON_TRIGGER,
device::kImmersiveButtonTrigger, triggerButtonPressed,
Expand Down Expand Up @@ -829,6 +829,9 @@ void OpenXRInputSource::Update(const XrFrameState& frameState, XrSpace localSpac
auto immersiveButton = GetImmersiveButton(button);
delegate.SetButtonState(mIndex, browserButton, immersiveButton.has_value() ? immersiveButton.value() : -1, state->clicked, state->touched, state->value);

if (button.type == OpenXRButtonType::Trigger)
delegate.SetSelectFactor(mIndex, state->value);

// Select action
if (renderMode == device::RenderMode::Immersive && button.type == OpenXRButtonType::Trigger && state->clicked != selectActionStarted) {
selectActionStarted = state->clicked;
Expand Down

0 comments on commit 04f6705

Please sign in to comment.