/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */
RefPtr<XRNativeOrigin> nativeOriginTargetRay = nullptr;
mTargetRayMode = XRTargetRayMode::Tracked_pointer; switch (controllerState.targetRayMode) { case gfx::TargetRayMode::Gaze:
mTargetRayMode = XRTargetRayMode::Gaze;
nativeOriginTargetRay = new XRNativeOriginViewer(displayClient); break; case gfx::TargetRayMode::TrackedPointer:
mTargetRayMode = XRTargetRayMode::Tracked_pointer; // We use weak pointers of poses in XRNativeOriginTracker to sync their // data internally.
nativeOriginTargetRay = new XRNativeOriginTracker(&controllerState.targetRayPose); break; case gfx::TargetRayMode::Screen:
mTargetRayMode = XRTargetRayMode::Screen; break; default:
MOZ_ASSERT(false && "Undefined TargetRayMode type."); break;
}
mTargetRaySpace = new XRInputSpace(aSession->GetParentObject(), aSession,
nativeOriginTargetRay, aIndex);
// OculusVR and OpenVR controllers need to wait until // update functions to assign GamepadCapabilityFlags::Cap_GripSpacePosition // flag. if (!mGripSpace) {
CreateGripSpace(aSession, controllerState);
}
if (buttons[i]->Pressed() != pressed || buttons[i]->Touched() != touched ||
buttons[i]->Value() != controllerState.triggerValue[i]) {
mGamepad->SetButton(i, pressed, touched, controllerState.triggerValue[i]);
}
} // Update axis values.
nsTArray<double> axes;
mGamepad->GetAxes(axes); for (uint32_t i = 0; i < axes.Length(); ++i) { if (axes[i] != controllerState.axisValue[i]) {
mGamepad->SetAxis(i, controllerState.axisValue[i]);
}
}
// We define 0.85f and 0.15f based on our current finding // for better experience, we can adjust these values if we need. constfloat completeThreshold = 0.90f; constfloat startThreshold = 0.85f; constfloat endThreshold = 0.15f; const uint32_t selectIndex = 0; const uint32_t squeezeIndex = 1;
// Checking selectstart, select, selectend if (buttons.Length() > selectIndex) { if (controllerState.selectActionStartFrameId >
controllerState.selectActionStopFrameId) { if (mSelectAction == ActionState::ActionState_Released &&
controllerState.triggerValue[selectIndex] > endThreshold) {
DispatchEvent(u"selectstart"_ns, aSession);
mSelectAction = ActionState::ActionState_Pressing;
} elseif (mSelectAction == ActionState::ActionState_Pressing &&
controllerState.triggerValue[selectIndex] >
completeThreshold) {
mSelectAction = ActionState::ActionState_Pressed;
} elseif (mSelectAction == ActionState::ActionState_Pressed &&
controllerState.triggerValue[selectIndex] < startThreshold) {
DispatchEvent(u"select"_ns, aSession);
mSelectAction = ActionState::ActionState_Releasing;
} elseif (mSelectAction <= ActionState::ActionState_Releasing &&
controllerState.triggerValue[selectIndex] < endThreshold) { // For a select btn which only has pressed and unpressed status. if (mSelectAction == ActionState::ActionState_Pressed) {
DispatchEvent(u"select"_ns, aSession);
}
DispatchEvent(u"selectend"_ns, aSession);
mSelectAction = ActionState::ActionState_Released;
}
} elseif (mSelectAction <= ActionState::ActionState_Releasing) { // For a select btn which only has pressed and unpressed status. if (mSelectAction == ActionState::ActionState_Pressed) {
DispatchEvent(u"select"_ns, aSession);
}
DispatchEvent(u"selectend"_ns, aSession);
mSelectAction = ActionState::ActionState_Released;
}
}
// Checking squeezestart, squeeze, squeezeend if (buttons.Length() > squeezeIndex) { if (controllerState.squeezeActionStartFrameId >
controllerState.squeezeActionStopFrameId) { if (mSqueezeAction == ActionState::ActionState_Released &&
controllerState.triggerValue[squeezeIndex] > endThreshold) {
DispatchEvent(u"squeezestart"_ns, aSession);
mSqueezeAction = ActionState::ActionState_Pressing;
} elseif (mSqueezeAction == ActionState::ActionState_Pressing &&
controllerState.triggerValue[squeezeIndex] >
completeThreshold) {
mSqueezeAction = ActionState::ActionState_Pressed;
} elseif (mSqueezeAction == ActionState::ActionState_Pressed &&
controllerState.triggerValue[squeezeIndex] < startThreshold) {
DispatchEvent(u"squeeze"_ns, aSession);
mSqueezeAction = ActionState::ActionState_Releasing;
} elseif (mSqueezeAction <= ActionState::ActionState_Releasing &&
controllerState.triggerValue[squeezeIndex] < endThreshold) { // For a squeeze btn which only has pressed and unpressed status. if (mSqueezeAction == ActionState::ActionState_Pressed) {
DispatchEvent(u"squeeze"_ns, aSession);
}
DispatchEvent(u"squeezeend"_ns, aSession);
mSqueezeAction = ActionState::ActionState_Released;
}
} elseif (mSqueezeAction <= ActionState::ActionState_Releasing) { // For a squeeze btn which only has pressed and unpressed status. if (mSqueezeAction == ActionState::ActionState_Pressed) {
DispatchEvent(u"squeeze"_ns, aSession);
}
DispatchEvent(u"squeezeend"_ns, aSession);
mSqueezeAction = ActionState::ActionState_Released;
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.