void OSVRInterface::RefreshCapabilities() { #if OSVR_ENABLED if (OSVRClientInterface == nullptr) return; #if 0 // Detection currently doesn't work (v0.1-261-gb6c8db7) OSVR_TimeValue Time; OSVR_PositionState Position; OSVR_OrientationState Orientation; OSVR_ButtonState Button; OSVR_AnalogState Analog; OSVR_ReturnCode HasPositonState = osvrGetPositionState(OSVRClientInterface, &Time, &Position); Capabilities |= (HasPositonState == OSVR_RETURN_SUCCESS) ? POSITION_STATE_AVAILABLE : 0; OSVR_ReturnCode HasOrientationState = osvrGetOrientationState(OSVRClientInterface, &Time, &Orientation); Capabilities |= (HasOrientationState == OSVR_RETURN_SUCCESS) ? ORIENTATION_STATE_AVAILABLE : 0; OSVR_ReturnCode HasButtonState = osvrGetButtonState(OSVRClientInterface, &Time, &Button); Capabilities |= (HasButtonState == OSVR_RETURN_SUCCESS) ? BUTTON_STATE_AVAILABLE : 0; OSVR_ReturnCode HasAnalogState = osvrGetAnalogState(OSVRClientInterface, &Time, &Analog); Capabilities |= (HasAnalogState == OSVR_RETURN_SUCCESS) ? ANALOG_STATE_AVAILABLE : 0; #else Capabilities = POSITION_STATE_AVAILABLE | ORIENTATION_STATE_AVAILABLE | BUTTON_STATE_AVAILABLE | ANALOG_STATE_AVAILABLE; #endif #endif // OSVR_ENABLED }
int main() { osvr::clientkit::ClientContext context( "com.osvr.UserSettingsClient"); // This is just one of the paths: specifically, the Hydra's left // controller's analog trigger. More are in the docs and/or listed on // startup osvr::clientkit::Interface IPD = context.getInterface("/me/IPD"); osvr::clientkit::Interface StandingHeight = context.getInterface("/me/StandingHeight"); osvr::clientkit::Interface SeatedHeight = context.getInterface("/me/SeatedHeight"); // Pretend that this is your application's mainloop. for (int i = 0; i < 100000000; ++i) { context.update(); if ((i % 1000) == 0){ OSVR_AnalogState ipdState,standingState,seatedState; OSVR_TimeValue timestamp; OSVR_ReturnCode ret = osvrGetAnalogState(IPD.get(), ×tamp, &ipdState); osvrGetAnalogState(StandingHeight.get(), ×tamp, &standingState); osvrGetAnalogState(SeatedHeight.get(), ×tamp, &seatedState); if (OSVR_RETURN_SUCCESS != ret){ std::cout << "state read failure" << std::endl; } else{ std::cout << "state is IPD:" << ipdState <<" Standing:" << standingState << " Seated:" << seatedState << std::endl; } } } std::cout << "Library shut down, exiting." << std::endl; }
bool OSVRInterface::GetAnalogState(float& Value, bool Latest) const { if (Latest) { #if OSVR_ENABLED OSVR_TimeValue Time; OSVR_AnalogState Analog; OSVR_ReturnCode ReturnCode = osvrGetAnalogState(OSVRClientInterface, &Time, &Analog); Value = Analog; return ReturnCode == OSVR_RETURN_SUCCESS; #endif // OSVR_ENABLED } else { Value = AnalogState; } return HasAnalogState(); }
void QVRDevice::update() { if (config().processIndex() == QVRManager::processIndex()) { #ifdef HAVE_VRPN if (_internals->vrpnTrackerRemote) _internals->vrpnTrackerRemote->mainloop(); if (_internals->vrpnButtonRemote) _internals->vrpnButtonRemote->mainloop(); if (_internals->vrpnAnalogRemote) _internals->vrpnAnalogRemote->mainloop(); #endif #ifdef HAVE_OCULUS if (_internals->oculusTrackedEye >= 0) { const ovrPosef* p; if (_internals->oculusTrackedEye == 1) p = &(QVROculusRenderPoses[0]); else if (_internals->oculusTrackedEye == 2) p = &(QVROculusRenderPoses[1]); else p = &(QVROculusTrackingState.HeadPose.ThePose); // Note the position Y offset that moves the sitting user's eyes to a default standing height in // the virtual world. _position = QVector3D(p->Position.x, p->Position.y + QVRObserverConfig::defaultEyeHeight, p->Position.z); _orientation = QQuaternion(p->Orientation.w, p->Orientation.x, p->Orientation.y, p->Orientation.z); } #endif #ifdef HAVE_OPENVR if (_internals->openVrTrackedEntity >= 0) { _orientation = QVROpenVRTrackedOrientations[_internals->openVrTrackedEntity]; _position = QVROpenVRTrackedPositions[_internals->openVrTrackedEntity]; } if (_internals->openVrButtonsEntity >= 0) { _buttons[0] = QVROpenVRControllerStates[_internals->openVrButtonsEntity].rAxis[0].y > +0.5f; _buttons[1] = QVROpenVRControllerStates[_internals->openVrButtonsEntity].rAxis[0].y < -0.5f; _buttons[2] = QVROpenVRControllerStates[_internals->openVrButtonsEntity].rAxis[0].x < -0.5f; _buttons[3] = QVROpenVRControllerStates[_internals->openVrButtonsEntity].rAxis[0].x > +0.5f; unsigned long buttonPressed = QVROpenVRControllerStates[_internals->openVrButtonsEntity].ulButtonPressed; _buttons[4] = buttonPressed & vr::ButtonMaskFromId(vr::k_EButton_ApplicationMenu); _buttons[5] = buttonPressed & vr::ButtonMaskFromId(vr::k_EButton_Grip); } if (_internals->openVrAnalogsEntity >= 0) { _analogs[0] = QVROpenVRControllerStates[_internals->openVrAnalogsEntity].rAxis[0].y; _analogs[1] = QVROpenVRControllerStates[_internals->openVrAnalogsEntity].rAxis[0].x; _analogs[2] = QVROpenVRControllerStates[_internals->openVrAnalogsEntity].rAxis[1].x; } #endif #ifdef HAVE_OSVR if (_internals->osvrTrackedEye != -1 || _internals->osvrTrackingInterface) { OSVR_Pose3 pose; bool ok; if (_internals->osvrTrackedEye == 0) { // center eye ok = (osvrClientGetViewerPose(QVROsvrDisplayConfig, 0, &pose) == OSVR_RETURN_SUCCESS); } else if (_internals->osvrTrackedEye == 1) { // left eye ok = (osvrClientGetViewerEyePose(QVROsvrDisplayConfig, 0, 0, &pose) == OSVR_RETURN_SUCCESS); } else if (_internals->osvrTrackedEye == 2) { // right eye OSVR_EyeCount eyes; osvrClientGetNumEyesForViewer(QVROsvrDisplayConfig, 0, &eyes); int e = (eyes == 2 ? 1 : 0); ok = (osvrClientGetViewerEyePose(QVROsvrDisplayConfig, 0, e, &pose) == OSVR_RETURN_SUCCESS); } else { // _internals->osvrTrackingInterface struct OSVR_TimeValue timestamp; ok = (osvrGetPoseState(_internals->osvrTrackingInterface, ×tamp, &pose) == OSVR_RETURN_SUCCESS); } if (ok) { if (_internals->osvrTrackedEye >= 0 && pose.translation.data[1] < 1.1f) { // Assume the user wears a HMD and sits (i.e. no room-scale VR). // In this case, we apply an offset to a default standing observer, // just as we do for Oculus Rift. pose.translation.data[1] += QVRObserverConfig::defaultEyeHeight; } _position = QVector3D(pose.translation.data[0], pose.translation.data[1], pose.translation.data[2]); _orientation = QQuaternion(pose.rotation.data[0], pose.rotation.data[1], pose.rotation.data[2], pose.rotation.data[3]); } } if (_internals->osvrButtonsInterfaces.length() > 0) { OSVR_ButtonState state; struct OSVR_TimeValue timestamp; for (int i = 0; i < _buttons.length(); i++) { if (_internals->osvrButtonsInterfaces[i] && osvrGetButtonState(_internals->osvrButtonsInterfaces[i], ×tamp, &state) == OSVR_RETURN_SUCCESS) { _buttons[i] = state; } } } if (_internals->osvrAnalogsInterfaces.length() > 0) { OSVR_AnalogState state; struct OSVR_TimeValue timestamp; for (int i = 0; i < _analogs.length(); i++) { if (_internals->osvrAnalogsInterfaces[i] && osvrGetAnalogState(_internals->osvrAnalogsInterfaces[i], ×tamp, &state) == OSVR_RETURN_SUCCESS) { _analogs[i] = state; } } } #endif } }