mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
attempt to enter VR mode when docked, get sensor data
This commit is contained in:
parent
5aa49e4e8d
commit
a4a06751da
2 changed files with 70 additions and 28 deletions
|
@ -16,6 +16,8 @@
|
|||
#include <QtWidgets/QMenuBar>
|
||||
|
||||
#include <VrApi/VrApi.h>
|
||||
#include <VrApi/VrApi_local.h>
|
||||
#include <VrApi/LocalPreferences.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include <QtWidgets/QApplication>
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue