mirror of
https://github.com/overte-org/overte.git
synced 2025-08-10 02:52:57 +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 <QtWidgets/QMenuBar>
|
||||||
|
|
||||||
#include <VrApi/VrApi.h>
|
#include <VrApi/VrApi.h>
|
||||||
|
#include <VrApi/VrApi_local.h>
|
||||||
|
#include <VrApi/LocalPreferences.h>
|
||||||
|
|
||||||
#include "GVRMainWindow.h"
|
#include "GVRMainWindow.h"
|
||||||
#include "RenderingClient.h"
|
#include "RenderingClient.h"
|
||||||
|
@ -47,7 +49,31 @@ void GVRInterface::idle() {
|
||||||
if (!_inVRMode && ovr_IsHeadsetDocked()) {
|
if (!_inVRMode && ovr_IsHeadsetDocked()) {
|
||||||
qDebug() << "The headset just got docked - we should try and go into VR mode";
|
qDebug() << "The headset just got docked - we should try and go into VR mode";
|
||||||
_inVRMode = true;
|
_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) {
|
void GVRInterface::handleApplicationStateChange(Qt::ApplicationState state) {
|
||||||
|
@ -57,39 +83,50 @@ void GVRInterface::handleApplicationStateChange(Qt::ApplicationState state) {
|
||||||
break;
|
break;
|
||||||
case Qt::ApplicationSuspended:
|
case Qt::ApplicationSuspended:
|
||||||
qDebug() << "The application is being suspended.";
|
qDebug() << "The application is being suspended.";
|
||||||
pauseOVR();
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GVRInterface::resumeOVR() {
|
void GVRInterface::enterVRMode() {
|
||||||
// Reload local preferences, in case we are coming back from a
|
// Reload local preferences, in case we are coming back from a
|
||||||
// switch to the dashboard that changed them.
|
// switch to the dashboard that changed them.
|
||||||
// ovr_UpdateLocalPreferences();
|
ovr_UpdateLocalPreferences();
|
||||||
//
|
|
||||||
// // Default vrModeParms
|
// Default vrModeParms
|
||||||
// ovrModeParms vrModeParms;
|
ovrModeParms vrModeParms;
|
||||||
// ovrHmdInfo hmdInfo;
|
vrModeParms.AsynchronousTimeWarp = true;
|
||||||
//
|
vrModeParms.AllowPowerSave = true;
|
||||||
// const char* cpuLevelStr = ovr_GetLocalPreferenceValueForKey( LOCAL_PREF_DEV_CPU_LEVEL, "-1" );
|
vrModeParms.DistortionFileName = NULL;
|
||||||
// const int cpuLevel = atoi( cpuLevelStr );
|
vrModeParms.EnableImageServer = false;
|
||||||
// if ( cpuLevel >= 0 ) {
|
vrModeParms.CpuLevel = 2;
|
||||||
// vrModeParms.CpuLevel = cpuLevel;
|
vrModeParms.GpuLevel = 2;
|
||||||
// qDebug() << "Local Preferences: Setting cpuLevel" << vrModeParms.CpuLevel;
|
vrModeParms.GameThreadTid = 0;
|
||||||
// }
|
|
||||||
//
|
QPlatformNativeInterface* interface = QApplication::platformNativeInterface();
|
||||||
// const char* gpuLevelStr = ovr_GetLocalPreferenceValueForKey( LOCAL_PREF_DEV_GPU_LEVEL, "-1" );
|
|
||||||
// const int gpuLevel = atoi( gpuLevelStr );
|
vrModeParms.ActivityObject = (jobject) interface->nativeResourceForIntegration("QtActivity");
|
||||||
// if ( gpuLevel >= 0 ) {
|
|
||||||
// vrModeParms.GpuLevel = gpuLevel;
|
_hmdInfo = new ovrHmdInfo;
|
||||||
// qDebug() << "Local Preferences: Setting gpuLevel" << vrModeParms.GpuLevel;
|
|
||||||
// }
|
const char* cpuLevelStr = ovr_GetLocalPreferenceValueForKey( LOCAL_PREF_DEV_CPU_LEVEL, "-1" );
|
||||||
//
|
const int cpuLevel = atoi( cpuLevelStr );
|
||||||
// ovr_EnterVrMode(vrModeParms, &hmdInfo);
|
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() {
|
void GVRInterface::leaveVRMode() {
|
||||||
// ovr_LeaveVrMode();
|
ovr_LeaveVrMode(_ovr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@
|
||||||
#include <QtWidgets/QApplication>
|
#include <QtWidgets/QApplication>
|
||||||
|
|
||||||
class RenderingClient;
|
class RenderingClient;
|
||||||
|
class ovrMobile;
|
||||||
|
class ovrHmdInfo;
|
||||||
|
|
||||||
#if defined(qApp)
|
#if defined(qApp)
|
||||||
#undef qApp
|
#undef qApp
|
||||||
|
@ -32,11 +34,14 @@ private slots:
|
||||||
void handleApplicationStateChange(Qt::ApplicationState state);
|
void handleApplicationStateChange(Qt::ApplicationState state);
|
||||||
void idle();
|
void idle();
|
||||||
private:
|
private:
|
||||||
void resumeOVR();
|
void enterVRMode();
|
||||||
void pauseOVR();
|
void leaveVRMode();
|
||||||
|
|
||||||
RenderingClient* _client;
|
RenderingClient* _client;
|
||||||
bool _inVRMode;
|
bool _inVRMode;
|
||||||
|
|
||||||
|
ovrMobile* _ovr;
|
||||||
|
ovrHmdInfo* _hmdInfo;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_GVRInterface_h
|
#endif // hifi_GVRInterface_h
|
||||||
|
|
Loading…
Reference in a new issue