mirror of
https://github.com/Armored-Dragon/overte.git
synced 2025-03-11 16:13:16 +01: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["using_hmd"] = isHMDMode();
|
||||
|
||||
if (isOculusRiftPluginAvailable()){
|
||||
qCDebug(interfaceapp) << "Oculus Rift Plugin is available";
|
||||
QTimer *switchModeTimer = new QTimer(this);
|
||||
connect(switchModeTimer, SIGNAL(timeout()), this, SLOT(switchmode()));
|
||||
switchModeTimer->start(500);
|
||||
if (isOculusRiftPluginAvailable()) {
|
||||
// If Oculus Rift Plugin is Available,And Current Display Plugin is not Oculus Rift
|
||||
// then startOculusRiftStandBySession to listen Oculus HMD Mounted status.
|
||||
if (getActiveDisplayPlugin()->getName() != "Oculus Rift" &&
|
||||
!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();
|
||||
|
@ -1574,7 +1581,9 @@ void Application::aboutToQuit() {
|
|||
}
|
||||
|
||||
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.
|
||||
DependencyManager::get<OffscreenUi>()->hide("RunningScripts");
|
||||
|
||||
|
@ -6845,7 +6854,7 @@ bool Application::isOculusRiftPluginAvailable(){
|
|||
auto displayPlugins = PluginManager::getInstance()->getDisplayPlugins();
|
||||
// Default to the first item on the list, in case none of the menu items match
|
||||
DisplayPluginPointer defaultplugin = displayPlugins.at(0);
|
||||
if (defaultplugin->isHmd() && defaultplugin->getName() == "Oculus Rift"){
|
||||
if (defaultplugin->isHmd() && defaultplugin->getName() == "Oculus Rift") {
|
||||
oculusRiftPlugin = defaultplugin;
|
||||
return true; // No need to iterate again,so return
|
||||
}
|
||||
|
@ -6854,7 +6863,7 @@ bool Application::isOculusRiftPluginAvailable(){
|
|||
QString pluginname = displayPlugin->getName();
|
||||
if (displayPlugin->isHmd() && pluginname == "Oculus Rift") {
|
||||
oculusRiftPlugin = displayPlugin;
|
||||
_isDisplayVisible = displayPlugin->isDisplayVisible();
|
||||
_oculusHMDMountedStatus = displayPlugin->isDisplayVisible();
|
||||
isOculusRiftPluginAvailable = true;
|
||||
break;
|
||||
}
|
||||
|
@ -6862,15 +6871,32 @@ bool Application::isOculusRiftPluginAvailable(){
|
|||
return isOculusRiftPluginAvailable;
|
||||
}
|
||||
|
||||
void Application::switchmode(){
|
||||
bool isDisplayVisible = oculusRiftPlugin->isDisplayVisible();
|
||||
if (isDisplayVisible != _isDisplayVisible){
|
||||
if (isDisplayVisible == false && _isDisplayVisible == true){
|
||||
qCDebug(interfaceapp) << "switching from HMD to desktop mode";
|
||||
void Application::switchDisplayModeForOculus(){
|
||||
bool currenthmdMountedStatus = oculusRiftPlugin->isDisplayVisible();
|
||||
if (currenthmdMountedStatus != _oculusHMDMountedStatus){
|
||||
// Switch to respective mode as soon as currenthmdMountedStatus changes
|
||||
if (currenthmdMountedStatus == false && _oculusHMDMountedStatus == true) {
|
||||
qCDebug(interfaceapp) << "Switching from HMD to desktop mode";
|
||||
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 {
|
||||
|
|
|
@ -443,7 +443,7 @@ private slots:
|
|||
void addAssetToWorldErrorTimeout();
|
||||
|
||||
void handleSandboxStatus(QNetworkReply* reply);
|
||||
void switchmode();
|
||||
void switchDisplayModeForOculus();
|
||||
private:
|
||||
static void initDisplay();
|
||||
void init();
|
||||
|
@ -684,9 +684,13 @@ private:
|
|||
AudioInjector* _snapshotSoundInjector { nullptr };
|
||||
SharedSoundPointer _snapshotSound;
|
||||
|
||||
bool isOculusRiftPluginAvailable();
|
||||
|
||||
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)) {
|
||||
_container->showDisplayPluginsTools();
|
||||
}
|
||||
|
||||
return Parent::activate();
|
||||
return Parent::activate();
|
||||
}
|
||||
|
||||
void OpenGLDisplayPlugin::deactivate() {
|
||||
|
@ -339,6 +338,18 @@ void OpenGLDisplayPlugin::deactivate() {
|
|||
Parent::deactivate();
|
||||
}
|
||||
|
||||
bool OpenGLDisplayPlugin::startStandBySession() {
|
||||
if (!activateStandBySession()) {
|
||||
return false;
|
||||
}
|
||||
return Parent::startStandBySession();
|
||||
}
|
||||
|
||||
void OpenGLDisplayPlugin::endStandBySession() {
|
||||
deactivateStandBySession();
|
||||
return Parent::endStandBySession();
|
||||
}
|
||||
|
||||
void OpenGLDisplayPlugin::customizeContext() {
|
||||
auto presentThread = DependencyManager::get<PresentThread>();
|
||||
Q_ASSERT(thread() == presentThread->thread());
|
||||
|
|
|
@ -42,6 +42,8 @@ public:
|
|||
// between the main thread and the presentation thread
|
||||
bool activate() override final;
|
||||
void deactivate() override final;
|
||||
bool startStandBySession() override final;
|
||||
void endStandBySession() override final;
|
||||
bool eventFilter(QObject* receiver, QEvent* event) override;
|
||||
bool isDisplayVisible() const override { return true; }
|
||||
|
||||
|
@ -99,6 +101,10 @@ protected:
|
|||
// Returns true on successful activation
|
||||
virtual bool internalActivate() { return true; }
|
||||
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
|
||||
virtual void internalPresent();
|
||||
|
|
|
@ -53,6 +53,18 @@ public:
|
|||
virtual bool isActive() {
|
||||
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
|
||||
|
@ -73,6 +85,7 @@ signals:
|
|||
|
||||
protected:
|
||||
bool _active { false };
|
||||
bool _standbysessionactive { false };
|
||||
PluginContainer* _container { nullptr };
|
||||
static const char* UNKNOWN_PLUGIN_ID;
|
||||
|
||||
|
|
|
@ -127,6 +127,17 @@ void OculusBaseDisplayPlugin::internalDeactivate() {
|
|||
_session = nullptr;
|
||||
}
|
||||
|
||||
bool OculusBaseDisplayPlugin::activateStandBySession() {
|
||||
_session = acquireOculusSession();
|
||||
if (!_session) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void OculusBaseDisplayPlugin::deactivateStandBySession() {
|
||||
releaseOculusSession();
|
||||
_session = nullptr;
|
||||
}
|
||||
void OculusBaseDisplayPlugin::updatePresentPose() {
|
||||
//mat4 sensorResetMat;
|
||||
//_currentPresentFrameInfo.sensorSampleTime = ovr_GetTimeInSeconds();
|
||||
|
|
|
@ -33,6 +33,8 @@ protected:
|
|||
void uncustomizeContext() override;
|
||||
bool internalActivate() override;
|
||||
void internalDeactivate() override;
|
||||
bool activateStandBySession() override;
|
||||
void deactivateStandBySession() override;
|
||||
void updatePresentPose() override;
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in a new issue