mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 22:10:25 +02:00
Initial Commit: Switching from Desktop mode to HMD [Oculus Rift] mode automatically when the user wear Oculus Rift.
This commit is contained in:
parent
0c4cd96bfd
commit
1f24e38585
7 changed files with 92 additions and 19 deletions
|
@ -1338,11 +1338,18 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
||||||
properties["active_display_plugin"] = getActiveDisplayPlugin()->getName();
|
properties["active_display_plugin"] = getActiveDisplayPlugin()->getName();
|
||||||
properties["using_hmd"] = isHMDMode();
|
properties["using_hmd"] = isHMDMode();
|
||||||
|
|
||||||
if (isOculusRiftPluginAvailable()){
|
if (isOculusRiftPluginAvailable()) {
|
||||||
qCDebug(interfaceapp) << "Oculus Rift Plugin is available";
|
// If Oculus Rift Plugin is Available,And Current Display Plugin is not Oculus Rift
|
||||||
QTimer *switchModeTimer = new QTimer(this);
|
// then startOculusRiftStandBySession to listen Oculus HMD Mounted status.
|
||||||
connect(switchModeTimer, SIGNAL(timeout()), this, SLOT(switchmode()));
|
if (getActiveDisplayPlugin()->getName() != "Oculus Rift" &&
|
||||||
switchModeTimer->start(500);
|
!oculusRiftPlugin->isFakeSessionActive()) {
|
||||||
|
startOculusRiftStandBySession();
|
||||||
|
}
|
||||||
|
// Poll periodically to check whether the user has worn Oculus HMD or not. And switch mode
|
||||||
|
// accordingly. If the user wear HMD, switch to VR mode, if remove switch to Desktop mode.
|
||||||
|
QTimer *switchDisplayModeTimer = new QTimer(this);
|
||||||
|
connect(switchDisplayModeTimer, SIGNAL(timeout()), this, SLOT(switchDisplayModeForOculus()));
|
||||||
|
switchDisplayModeTimer->start(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto glInfo = getGLContextData();
|
auto glInfo = getGLContextData();
|
||||||
|
@ -1574,7 +1581,9 @@ void Application::aboutToQuit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
getActiveDisplayPlugin()->deactivate();
|
getActiveDisplayPlugin()->deactivate();
|
||||||
|
if (oculusRiftPlugin && oculusRiftPlugin->isFakeSessionActive()){
|
||||||
|
oculusRiftPlugin->endStandBySession();
|
||||||
|
}
|
||||||
// Hide Running Scripts dialog so that it gets destroyed in an orderly manner; prevents warnings at shutdown.
|
// Hide Running Scripts dialog so that it gets destroyed in an orderly manner; prevents warnings at shutdown.
|
||||||
DependencyManager::get<OffscreenUi>()->hide("RunningScripts");
|
DependencyManager::get<OffscreenUi>()->hide("RunningScripts");
|
||||||
|
|
||||||
|
@ -6845,7 +6854,7 @@ bool Application::isOculusRiftPluginAvailable(){
|
||||||
auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins();
|
auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins();
|
||||||
// Default to the first item on the list, in case none of the menu items match
|
// Default to the first item on the list, in case none of the menu items match
|
||||||
DisplayPluginPointer defaultplugin = displayPlugins.at(0);
|
DisplayPluginPointer defaultplugin = displayPlugins.at(0);
|
||||||
if (defaultplugin->isHmd() && defaultplugin->getName() == "Oculus Rift"){
|
if (defaultplugin->isHmd() && defaultplugin->getName() == "Oculus Rift") {
|
||||||
oculusRiftPlugin = defaultplugin;
|
oculusRiftPlugin = defaultplugin;
|
||||||
return true; // No need to iterate again,so return
|
return true; // No need to iterate again,so return
|
||||||
}
|
}
|
||||||
|
@ -6854,7 +6863,7 @@ bool Application::isOculusRiftPluginAvailable(){
|
||||||
QString pluginname = displayPlugin->getName();
|
QString pluginname = displayPlugin->getName();
|
||||||
if (displayPlugin->isHmd() && pluginname == "Oculus Rift") {
|
if (displayPlugin->isHmd() && pluginname == "Oculus Rift") {
|
||||||
oculusRiftPlugin = displayPlugin;
|
oculusRiftPlugin = displayPlugin;
|
||||||
_isDisplayVisible = displayPlugin->isDisplayVisible();
|
_oculusHMDMountedStatus = displayPlugin->isDisplayVisible();
|
||||||
isOculusRiftPluginAvailable = true;
|
isOculusRiftPluginAvailable = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -6862,15 +6871,32 @@ bool Application::isOculusRiftPluginAvailable(){
|
||||||
return isOculusRiftPluginAvailable;
|
return isOculusRiftPluginAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::switchmode(){
|
void Application::switchDisplayModeForOculus(){
|
||||||
bool isDisplayVisible = oculusRiftPlugin->isDisplayVisible();
|
bool currenthmdMountedStatus = oculusRiftPlugin->isDisplayVisible();
|
||||||
if (isDisplayVisible != _isDisplayVisible){
|
if (currenthmdMountedStatus != _oculusHMDMountedStatus){
|
||||||
if (isDisplayVisible == false && _isDisplayVisible == true){
|
// Switch to respective mode as soon as currenthmdMountedStatus changes
|
||||||
qCDebug(interfaceapp) << "switching from HMD to desktop mode";
|
if (currenthmdMountedStatus == false && _oculusHMDMountedStatus == true) {
|
||||||
|
qCDebug(interfaceapp) << "Switching from HMD to desktop mode";
|
||||||
setActiveDisplayPlugin("Desktop");
|
setActiveDisplayPlugin("Desktop");
|
||||||
|
startOculusRiftStandBySession();
|
||||||
|
}
|
||||||
|
if (currenthmdMountedStatus == true && _oculusHMDMountedStatus == false) {
|
||||||
|
qCDebug(interfaceapp) << "Switching from Desktop to HMD mode";
|
||||||
|
endOculusRiftStandBySession();
|
||||||
|
setActiveDisplayPlugin("Oculus Rift");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_isDisplayVisible = isDisplayVisible; // assign current status
|
_oculusHMDMountedStatus = currenthmdMountedStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Application::startOculusRiftStandBySession(){
|
||||||
|
bool isStandBySessionStarted = oculusRiftPlugin->startStandBySession();
|
||||||
|
qCDebug(interfaceapp) << "startOculusRiftStandBySession: " << isStandBySessionStarted;
|
||||||
|
return isStandBySessionStarted;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::endOculusRiftStandBySession(){
|
||||||
|
oculusRiftPlugin->endStandBySession();
|
||||||
}
|
}
|
||||||
|
|
||||||
mat4 Application::getEyeProjection(int eye) const {
|
mat4 Application::getEyeProjection(int eye) const {
|
||||||
|
|
|
@ -443,7 +443,7 @@ private slots:
|
||||||
void addAssetToWorldErrorTimeout();
|
void addAssetToWorldErrorTimeout();
|
||||||
|
|
||||||
void handleSandboxStatus(QNetworkReply* reply);
|
void handleSandboxStatus(QNetworkReply* reply);
|
||||||
void switchmode();
|
void switchDisplayModeForOculus();
|
||||||
private:
|
private:
|
||||||
static void initDisplay();
|
static void initDisplay();
|
||||||
void init();
|
void init();
|
||||||
|
@ -684,9 +684,13 @@ private:
|
||||||
AudioInjector* _snapshotSoundInjector { nullptr };
|
AudioInjector* _snapshotSoundInjector { nullptr };
|
||||||
SharedSoundPointer _snapshotSound;
|
SharedSoundPointer _snapshotSound;
|
||||||
|
|
||||||
bool isOculusRiftPluginAvailable();
|
|
||||||
DisplayPluginPointer oculusRiftPlugin;
|
DisplayPluginPointer oculusRiftPlugin;
|
||||||
bool _isDisplayVisible;
|
|
||||||
|
bool isOculusRiftPluginAvailable();
|
||||||
|
bool _oculusHMDMountedStatus; // Keep track of HMD Mounted Flag
|
||||||
|
bool startOculusRiftStandBySession();
|
||||||
|
void endOculusRiftStandBySession();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -315,8 +315,7 @@ bool OpenGLDisplayPlugin::activate() {
|
||||||
if (isHmd() && (getHmdScreen() >= 0)) {
|
if (isHmd() && (getHmdScreen() >= 0)) {
|
||||||
_container->showDisplayPluginsTools();
|
_container->showDisplayPluginsTools();
|
||||||
}
|
}
|
||||||
|
return Parent::activate();
|
||||||
return Parent::activate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLDisplayPlugin::deactivate() {
|
void OpenGLDisplayPlugin::deactivate() {
|
||||||
|
@ -339,6 +338,18 @@ void OpenGLDisplayPlugin::deactivate() {
|
||||||
Parent::deactivate();
|
Parent::deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OpenGLDisplayPlugin::startStandBySession() {
|
||||||
|
if (!activateStandBySession()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Parent::startStandBySession();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OpenGLDisplayPlugin::endStandBySession() {
|
||||||
|
deactivateStandBySession();
|
||||||
|
return Parent::endStandBySession();
|
||||||
|
}
|
||||||
|
|
||||||
void OpenGLDisplayPlugin::customizeContext() {
|
void OpenGLDisplayPlugin::customizeContext() {
|
||||||
auto presentThread = DependencyManager::get<PresentThread>();
|
auto presentThread = DependencyManager::get<PresentThread>();
|
||||||
Q_ASSERT(thread() == presentThread->thread());
|
Q_ASSERT(thread() == presentThread->thread());
|
||||||
|
|
|
@ -42,6 +42,8 @@ public:
|
||||||
// between the main thread and the presentation thread
|
// between the main thread and the presentation thread
|
||||||
bool activate() override final;
|
bool activate() override final;
|
||||||
void deactivate() override final;
|
void deactivate() override final;
|
||||||
|
bool startStandBySession() override final;
|
||||||
|
void endStandBySession() override final;
|
||||||
bool eventFilter(QObject* receiver, QEvent* event) override;
|
bool eventFilter(QObject* receiver, QEvent* event) override;
|
||||||
bool isDisplayVisible() const override { return true; }
|
bool isDisplayVisible() const override { return true; }
|
||||||
|
|
||||||
|
@ -99,6 +101,10 @@ protected:
|
||||||
// Returns true on successful activation
|
// Returns true on successful activation
|
||||||
virtual bool internalActivate() { return true; }
|
virtual bool internalActivate() { return true; }
|
||||||
virtual void internalDeactivate() {}
|
virtual void internalDeactivate() {}
|
||||||
|
|
||||||
|
// Returns true on successful activation of standby session
|
||||||
|
virtual bool activateStandBySession() { return true; }
|
||||||
|
virtual void deactivateStandBySession() {}
|
||||||
|
|
||||||
// Plugin specific functionality to send the composed scene to the output window or device
|
// Plugin specific functionality to send the composed scene to the output window or device
|
||||||
virtual void internalPresent();
|
virtual void internalPresent();
|
||||||
|
|
|
@ -53,6 +53,18 @@ public:
|
||||||
virtual bool isActive() {
|
virtual bool isActive() {
|
||||||
return _active;
|
return _active;
|
||||||
}
|
}
|
||||||
|
virtual bool startStandBySession(){
|
||||||
|
_standbysessionactive = true;
|
||||||
|
return _standbysessionactive;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void endStandBySession(){
|
||||||
|
_standbysessionactive = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool isFakeSessionActive() {
|
||||||
|
return _standbysessionactive;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by the application during it's idle phase. If the plugin needs to do
|
* Called by the application during it's idle phase. If the plugin needs to do
|
||||||
|
@ -73,6 +85,7 @@ signals:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool _active { false };
|
bool _active { false };
|
||||||
|
bool _standbysessionactive { false };
|
||||||
PluginContainer* _container { nullptr };
|
PluginContainer* _container { nullptr };
|
||||||
static const char* UNKNOWN_PLUGIN_ID;
|
static const char* UNKNOWN_PLUGIN_ID;
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,17 @@ void OculusBaseDisplayPlugin::internalDeactivate() {
|
||||||
_session = nullptr;
|
_session = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool OculusBaseDisplayPlugin::activateStandBySession() {
|
||||||
|
_session = acquireOculusSession();
|
||||||
|
if (!_session) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
void OculusBaseDisplayPlugin::deactivateStandBySession() {
|
||||||
|
releaseOculusSession();
|
||||||
|
_session = nullptr;
|
||||||
|
}
|
||||||
void OculusBaseDisplayPlugin::updatePresentPose() {
|
void OculusBaseDisplayPlugin::updatePresentPose() {
|
||||||
//mat4 sensorResetMat;
|
//mat4 sensorResetMat;
|
||||||
//_currentPresentFrameInfo.sensorSampleTime = ovr_GetTimeInSeconds();
|
//_currentPresentFrameInfo.sensorSampleTime = ovr_GetTimeInSeconds();
|
||||||
|
|
|
@ -33,6 +33,8 @@ protected:
|
||||||
void uncustomizeContext() override;
|
void uncustomizeContext() override;
|
||||||
bool internalActivate() override;
|
bool internalActivate() override;
|
||||||
void internalDeactivate() override;
|
void internalDeactivate() override;
|
||||||
|
bool activateStandBySession() override;
|
||||||
|
void deactivateStandBySession() override;
|
||||||
void updatePresentPose() override;
|
void updatePresentPose() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in a new issue