Fix HMD.mountedChanged() API signal

This commit is contained in:
David Rowe 2018-07-19 13:00:57 +12:00
parent b29044fd7e
commit 5e624246a8
8 changed files with 31 additions and 11 deletions

View file

@ -143,6 +143,7 @@
#include <QmlFragmentClass.h> #include <QmlFragmentClass.h>
#include <Preferences.h> #include <Preferences.h>
#include <display-plugins/CompositorHelper.h> #include <display-plugins/CompositorHelper.h>
#include <display-plugins/hmd/HmdDisplayPlugin.h>
#include <trackers/EyeTracker.h> #include <trackers/EyeTracker.h>
#include <avatars-renderer/ScriptAvatar.h> #include <avatars-renderer/ScriptAvatar.h>
#include <RenderableEntityItem.h> #include <RenderableEntityItem.h>
@ -2717,6 +2718,10 @@ void Application::initializeDisplayPlugins() {
QObject::connect(displayPlugin.get(), &DisplayPlugin::recommendedFramebufferSizeChanged, QObject::connect(displayPlugin.get(), &DisplayPlugin::recommendedFramebufferSizeChanged,
[this](const QSize& size) { resizeGL(); }); [this](const QSize& size) { resizeGL(); });
QObject::connect(displayPlugin.get(), &DisplayPlugin::resetSensorsRequested, this, &Application::requestReset); QObject::connect(displayPlugin.get(), &DisplayPlugin::resetSensorsRequested, this, &Application::requestReset);
if (displayPlugin->isHmd()) {
QObject::connect(dynamic_cast<HmdDisplayPlugin*>(displayPlugin.get()), &HmdDisplayPlugin::isHmdMountedChanged,
DependencyManager::get<HMDScriptingInterface>().data(), &HMDScriptingInterface::mountedChanged);
}
} }
// The default display plugin needs to be activated first, otherwise the display plugin thread // The default display plugin needs to be activated first, otherwise the display plugin thread

View file

@ -345,17 +345,6 @@ signals:
*/ */
bool shouldShowHandControllersChanged(); bool shouldShowHandControllersChanged();
/**jsdoc
* Triggered when the <code>HMD.mounted</code> property value changes.
* @function HMD.mountedChanged
* @returns {Signal}
* @example <caption>Report when there's a change in the HMD being worn.</caption>
* HMD.mountedChanged.connect(function () {
* print("Mounted changed. HMD is mounted: " + HMD.mounted);
* });
*/
void mountedChanged();
public: public:
HMDScriptingInterface(); HMDScriptingInterface();
static QScriptValue getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine); static QScriptValue getHUDLookAtPosition2D(QScriptContext* context, QScriptEngine* engine);

View file

@ -54,6 +54,17 @@ signals:
*/ */
void displayModeChanged(bool isHMDMode); void displayModeChanged(bool isHMDMode);
/**jsdoc
* Triggered when the <code>HMD.mounted</code> property value changes.
* @function HMD.mountedChanged
* @returns {Signal}
* @example <caption>Report when there's a change in the HMD being worn.</caption>
* HMD.mountedChanged.connect(function () {
* print("Mounted changed. HMD is mounted: " + HMD.mounted);
* });
*/
void mountedChanged();
private: private:
float _IPDScale{ 1.0 }; float _IPDScale{ 1.0 };
}; };

View file

@ -21,6 +21,7 @@
#include "../OpenGLDisplayPlugin.h" #include "../OpenGLDisplayPlugin.h"
class HmdDisplayPlugin : public OpenGLDisplayPlugin { class HmdDisplayPlugin : public OpenGLDisplayPlugin {
Q_OBJECT
using Parent = OpenGLDisplayPlugin; using Parent = OpenGLDisplayPlugin;
public: public:
~HmdDisplayPlugin(); ~HmdDisplayPlugin();
@ -45,6 +46,9 @@ public:
virtual bool onDisplayTextureReset() override { _clearPreviewFlag = true; return true; }; virtual bool onDisplayTextureReset() override { _clearPreviewFlag = true; return true; };
signals:
void isHmdMountedChanged();
protected: protected:
virtual void hmdPresent() = 0; virtual void hmdPresent() = 0;
virtual bool isHmdMounted() const = 0; virtual bool isHmdMounted() const = 0;

View file

@ -36,6 +36,10 @@ bool OculusBaseDisplayPlugin::beginFrameRender(uint32_t frameIndex) {
if (ovr::reorientRequested(status)) { if (ovr::reorientRequested(status)) {
emit resetSensorsRequested(); emit resetSensorsRequested();
} }
if (ovr::hmdMounted(status) != _isHmdMounted) {
_isHmdMounted = !_isHmdMounted;
emit isHmdMountedChanged();
}
_currentRenderFrameInfo = FrameInfo(); _currentRenderFrameInfo = FrameInfo();
_currentRenderFrameInfo.sensorSampleTime = ovr_GetTimeInSeconds(); _currentRenderFrameInfo.sensorSampleTime = ovr_GetTimeInSeconds();

View file

@ -44,4 +44,5 @@ protected:
ovrLayerEyeFov _sceneLayer; ovrLayerEyeFov _sceneLayer;
ovrViewScaleDesc _viewScaleDesc; ovrViewScaleDesc _viewScaleDesc;
// ovrLayerEyeFovDepth _depthLayer; // ovrLayerEyeFovDepth _depthLayer;
bool _isHmdMounted { false };
}; };

View file

@ -699,7 +699,11 @@ void OpenVrDisplayPlugin::postPreview() {
_nextSimPoseData = nextSim; _nextSimPoseData = nextSim;
}); });
_nextRenderPoseData = nextRender; _nextRenderPoseData = nextRender;
}
if (isHmdMounted() != _isHmdMounted) {
_isHmdMounted = !_isHmdMounted;
emit isHmdMountedChanged();
} }
} }

View file

@ -90,4 +90,6 @@ private:
friend class OpenVrSubmitThread; friend class OpenVrSubmitThread;
bool _asyncReprojectionActive { false }; bool _asyncReprojectionActive { false };
bool _isHmdMounted { false };
}; };