From a4a06751dab94022672d0d83855345443e50ca4a Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 27 Jan 2015 12:43:44 -0800 Subject: [PATCH] attempt to enter VR mode when docked, get sensor data --- gvr-interface/src/GVRInterface.cpp | 89 +++++++++++++++++++++--------- gvr-interface/src/GVRInterface.h | 9 ++- 2 files changed, 70 insertions(+), 28 deletions(-) diff --git a/gvr-interface/src/GVRInterface.cpp b/gvr-interface/src/GVRInterface.cpp index 3316d80047..a757acafbf 100644 --- a/gvr-interface/src/GVRInterface.cpp +++ b/gvr-interface/src/GVRInterface.cpp @@ -16,6 +16,8 @@ #include #include +#include +#include #include "GVRMainWindow.h" #include "RenderingClient.h" @@ -47,7 +49,31 @@ void GVRInterface::idle() { if (!_inVRMode && ovr_IsHeadsetDocked()) { qDebug() << "The headset just got docked - we should try and go into VR mode"; _inVRMode = true; - } + enterVRMode(); + } else if (_inVRMode) { + if (!ovr_IsHeadsetDocked()) { + qDebug() << "The headset was just undocked - we should leave VR mode now"; + leaveVRMode(); + } else { + // Get the latest head tracking state, predicted ahead to the midpoint of the time + // it will be displayed. It will always be corrected to the real values by + // time warp, but the closer we get, the less black will be pulled in at the edges. + const double now = ovr_GetTimeInSeconds(); + static double prev; + const double rawDelta = now - prev; + prev = now; + const double clampedPrediction = std::min( 0.1, rawDelta * 2); + ovrSensorState sensor = ovrHmd_GetSensorState(OvrHmd, now + clampedPrediction, true ); + + float w = sensor.Predicted.Pose.Orientation.w; + float x = sensor.Predicted.Pose.Orientation.x; + float y = sensor.Predicted.Pose.Orientation.y; + float z = sensor.Predicted.Pose.Orientation.z; + + qDebug() << "GetSensorState: " << x << y << z << w; + } + + } } void GVRInterface::handleApplicationStateChange(Qt::ApplicationState state) { @@ -57,39 +83,50 @@ void GVRInterface::handleApplicationStateChange(Qt::ApplicationState state) { break; case Qt::ApplicationSuspended: qDebug() << "The application is being suspended."; - pauseOVR(); break; default: break; } } -void GVRInterface::resumeOVR() { +void GVRInterface::enterVRMode() { // Reload local preferences, in case we are coming back from a // switch to the dashboard that changed them. - // ovr_UpdateLocalPreferences(); -// -// // Default vrModeParms -// ovrModeParms vrModeParms; -// ovrHmdInfo hmdInfo; -// -// const char* cpuLevelStr = ovr_GetLocalPreferenceValueForKey( LOCAL_PREF_DEV_CPU_LEVEL, "-1" ); -// const int cpuLevel = atoi( cpuLevelStr ); -// if ( cpuLevel >= 0 ) { -// vrModeParms.CpuLevel = cpuLevel; -// qDebug() << "Local Preferences: Setting cpuLevel" << vrModeParms.CpuLevel; -// } -// -// const char* gpuLevelStr = ovr_GetLocalPreferenceValueForKey( LOCAL_PREF_DEV_GPU_LEVEL, "-1" ); -// const int gpuLevel = atoi( gpuLevelStr ); -// if ( gpuLevel >= 0 ) { -// vrModeParms.GpuLevel = gpuLevel; -// qDebug() << "Local Preferences: Setting gpuLevel" << vrModeParms.GpuLevel; -// } -// -// ovr_EnterVrMode(vrModeParms, &hmdInfo); + ovr_UpdateLocalPreferences(); + + // Default vrModeParms + ovrModeParms vrModeParms; + vrModeParms.AsynchronousTimeWarp = true; + vrModeParms.AllowPowerSave = true; + vrModeParms.DistortionFileName = NULL; + vrModeParms.EnableImageServer = false; + vrModeParms.CpuLevel = 2; + vrModeParms.GpuLevel = 2; + vrModeParms.GameThreadTid = 0; + + QPlatformNativeInterface* interface = QApplication::platformNativeInterface(); + + vrModeParms.ActivityObject = (jobject) interface->nativeResourceForIntegration("QtActivity"); + + _hmdInfo = new ovrHmdInfo; + + const char* cpuLevelStr = ovr_GetLocalPreferenceValueForKey( LOCAL_PREF_DEV_CPU_LEVEL, "-1" ); + const int cpuLevel = atoi( cpuLevelStr ); + if ( cpuLevel >= 0 ) { + vrModeParms.CpuLevel = cpuLevel; + qDebug() << "Local Preferences: Setting cpuLevel" << vrModeParms.CpuLevel; + } + + const char* gpuLevelStr = ovr_GetLocalPreferenceValueForKey( LOCAL_PREF_DEV_GPU_LEVEL, "-1" ); + const int gpuLevel = atoi( gpuLevelStr ); + if ( gpuLevel >= 0 ) { + vrModeParms.GpuLevel = gpuLevel; + qDebug() << "Local Preferences: Setting gpuLevel" << vrModeParms.GpuLevel; + } + + _ovr = ovr_EnterVrMode(vrModeParms, _hmdInfo); } -void GVRInterface::pauseOVR() { - // ovr_LeaveVrMode(); +void GVRInterface::leaveVRMode() { + ovr_LeaveVrMode(_ovr); } diff --git a/gvr-interface/src/GVRInterface.h b/gvr-interface/src/GVRInterface.h index 3f95ad90cd..0a384f59ae 100644 --- a/gvr-interface/src/GVRInterface.h +++ b/gvr-interface/src/GVRInterface.h @@ -15,6 +15,8 @@ #include class RenderingClient; +class ovrMobile; +class ovrHmdInfo; #if defined(qApp) #undef qApp @@ -32,11 +34,14 @@ private slots: void handleApplicationStateChange(Qt::ApplicationState state); void idle(); private: - void resumeOVR(); - void pauseOVR(); + void enterVRMode(); + void leaveVRMode(); RenderingClient* _client; bool _inVRMode; + + ovrMobile* _ovr; + ovrHmdInfo* _hmdInfo; }; #endif // hifi_GVRInterface_h