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

Commit

Permalink
Making PicoVR support WebXR gamepad.
Browse files Browse the repository at this point in the history
  • Loading branch information
daoshengmu committed Mar 31, 2020
1 parent 858a165 commit e911b8e
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions app/src/picovr/cpp/DeviceDelegatePicoVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ namespace crow {
static const vrb::Vector kAverageHeight(0.0f, 1.7f, 0.0f);
// TODO: support different controllers & buttons
static const int32_t kMaxControllerCount = 3;
static const int32_t kNumButtons = 6;
static const int32_t kNumG2Buttons = 2;
static const int32_t kNumGazeButtons = 2;
static const int32_t kNumAxes = 2;
static const int32_t kNumButtons = 7;
static const int32_t kNumG2Buttons = 3;
static const int32_t kNumGazeButtons = 1;
static const int32_t k6DofHeadSet = 1;
static const int32_t kButtonApp = 1;
static const int32_t kButtonTrigger = 1 << 1;
Expand Down Expand Up @@ -180,33 +179,48 @@ struct DeviceDelegatePicoVR::State {

controllerDelegate->SetButtonState(i, ControllerDelegate::BUTTON_APP, -1, appPressed,
appPressed);
controllerDelegate->SetButtonState(i, ControllerDelegate::BUTTON_TOUCHPAD, 0, touchPadPressed,
touchPadPressed);
controllerDelegate->SetButtonState(i, ControllerDelegate::BUTTON_TRIGGER, 1, triggerPressed,
controllerDelegate->SetButtonState(i, ControllerDelegate::BUTTON_TOUCHPAD, type == k6DofHeadSet ?
device::kImmersiveButtonThumbstick : device::kImmersiveButtonTouchpad, touchPadPressed, touchPadPressed);
controllerDelegate->SetButtonState(i, ControllerDelegate::BUTTON_TRIGGER, device::kImmersiveButtonTrigger, triggerPressed,
triggerPressed);
if (triggerPressed && renderMode == device::RenderMode::Immersive) {
controllerDelegate->SetSelectActionStart(i);
} else {
controllerDelegate->SetSelectActionStop(i);
}
if (type == k6DofHeadSet) {
controllerDelegate->SetButtonState(i, ControllerDelegate::BUTTON_OTHERS, 2, gripPressed,
controllerDelegate->SetButtonState(i, ControllerDelegate::BUTTON_OTHERS, device::kImmersiveButtonSqueeze, gripPressed,
gripPressed, gripPressed ? 20.0f : 0.0f);
if (gripPressed && renderMode == device::RenderMode::Immersive) {
controllerDelegate->SetSqueezeActionStart(i);
} else {
controllerDelegate->SetSqueezeActionStop(i);
}
controllerDelegate->SetButtonState(i,
(controller.IsRightHand() ? ControllerDelegate::BUTTON_A
: ControllerDelegate::BUTTON_X),
3, axPressed, axPressed);
device::kImmersiveButtonA, axPressed, axPressed);
controllerDelegate->SetButtonState(i,
(controller.IsRightHand() ? ControllerDelegate::BUTTON_B
: ControllerDelegate::BUTTON_Y),
4, byPressed, byPressed);
controllerDelegate->SetButtonState(i, ControllerDelegate::BUTTON_OTHERS, 5, false, false);
}
device::kImmersiveButtonB, byPressed, byPressed);
controllerDelegate->SetButtonState(i, ControllerDelegate::BUTTON_OTHERS, device::kImmersiveButtonThumbrest, false, false);

float axes[kNumAxes] = { controller.axisX , -controller.axisY };
controllerDelegate->SetAxes(i, axes, kNumAxes);
const int32_t kNumAxes = 4;
float axes[kNumAxes];
axes[device::kImmersiveAxisTouchpadX] = axes[device::kImmersiveAxisTouchpadY] = 0.0f;
axes[device::kImmersiveAxisThumbstickX] = controller.axisX;
axes[device::kImmersiveAxisThumbstickY] = -controller.axisY;
controllerDelegate->SetAxes(i, axes, controller.index != GazeModeIndex() ? kNumAxes : 0);


if (type == k6DofHeadSet) {
if (!triggerPressed) {
controllerDelegate->SetScrolledDelta(i, -controller.axisX, controller.axisY);
}
} else {
const int32_t kNumAxes = 2;
float axes[kNumAxes] = { controller.axisX , -controller.axisY };
controllerDelegate->SetAxes(i, axes, controller.index != GazeModeIndex() ? kNumAxes : 0);

if (controller.touched) {
controllerDelegate->SetTouchPosition(i, controller.axisX, controller.axisY);
} else {
Expand Down Expand Up @@ -336,19 +350,24 @@ DeviceDelegatePicoVR::SetControllerDelegate(ControllerDelegatePtr& aController)
m.controllerDelegate->CreateController(index, 0, "Pico Gaze Controller", beam);
m.controllerDelegate->SetButtonCount(index, kNumGazeButtons);
m.controllerDelegate->SetHapticCount(index, 0);

m.controllerDelegate->SetControllerType(index, mozilla::gfx::VRControllerType::PicoGaze);
m.controllerDelegate->SetTargetRayMode(index, mozilla::gfx::TargetRayMode::Gaze);
} else {
if (m.type == k6DofHeadSet) {
vrb::Matrix beam = vrb::Matrix::Rotation(vrb::Vector(1.0f, 0.0f, 0.0f), -vrb::PI_FLOAT / 11.5f);
beam.TranslateInPlace(vrb::Vector(0.0f, 0.012f, -0.06f));
m.controllerDelegate->CreateController(index, int32_t(controller.hand), controller.IsRightHand() ? "Pico Neo 2 (Right)" : "Pico Neo 2 (LEFT)", beam);
m.controllerDelegate->SetButtonCount(index, kNumButtons);
m.controllerDelegate->SetHapticCount(index, 1);
m.controllerDelegate->SetControllerType(index, mozilla::gfx::VRControllerType::PicoNeo2);
m.controllerDelegate->SetTargetRayMode(index, mozilla::gfx::TargetRayMode::TrackedPointer);
} else {
vrb::Matrix beam = vrb::Matrix::Rotation(vrb::Vector(1.0f, 0.0f, 0.0f), -vrb::PI_FLOAT / 11.5f);
m.controllerDelegate->CreateController(index, 0, "Pico G2 Controller", beam);
m.controllerDelegate->SetButtonCount(index, kNumG2Buttons);
m.controllerDelegate->SetHapticCount(index, 0);
m.controllerDelegate->SetControllerType(index, mozilla::gfx::VRControllerType::PicoG2);
m.controllerDelegate->SetTargetRayMode(index, mozilla::gfx::TargetRayMode::TrackedPointer);
}
}
controller.created = true;
Expand Down

0 comments on commit e911b8e

Please sign in to comment.