diff --git a/plugins/Oculus/src/CMakeLists.txt b/plugins/Oculus/src/CMakeLists.txt index d65268c11a2ca..e989f7f35cadc 100644 --- a/plugins/Oculus/src/CMakeLists.txt +++ b/plugins/Oculus/src/CMakeLists.txt @@ -1,27 +1,37 @@ -INCLUDE_DIRECTORIES( - . - ${CMAKE_BINARY_DIR}/plugins/Oculus/src -) +SET(OCULUS_SDK_PATH "" CACHE PATH "Path to Oculus SDK") -LINK_DIRECTORIES(/src) -SET(Oculus_SRCS - Oculus.hpp - Oculus.cpp - ${OCULUS_SDK_PATH}/LibOVR/Shim/OVR_CAPI_Util.cpp -) +IF (IS_DIRECTORY ${OCULUS_SDK_PATH}) -SET(extLinkerOption ${OPENGL_LIBRARIES}) + MESSAGE(STATUS "Oculus SDK found.") -SET(OCULUS_SDK_PATH "" CACHE FILEPATH "Path to Oculus SDK") -INCLUDE_DIRECTORIES(${OCULUS_SDK_PATH}/LibOVR/Include) + INCLUDE_DIRECTORIES(${OCULUS_SDK_PATH}/LibOVR/Include + . + ${CMAKE_BINARY_DIR}/plugins/Oculus/src + ) -ADD_LIBRARY(Oculus-static STATIC ${Oculus_SRCS}) -SET_TARGET_PROPERTIES(Oculus-static PROPERTIES OUTPUT_NAME "Oculus") + LINK_DIRECTORIES(/src) -TARGET_LINK_LIBRARIES(Oculus-static Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets) -TARGET_LINK_LIBRARIES(Oculus-static ${OCULUS_SDK_PATH}/LibOVR/Lib/Windows/x64/Release/VS2015/libOVR.lib ws2_32) + SET(Oculus_SRCS + Oculus.hpp + Oculus.cpp + ${OCULUS_SDK_PATH}/LibOVR/Shim/OVR_CAPI_Util.cpp + ) + + SET(extLinkerOption ${OPENGL_LIBRARIES}) + + ADD_LIBRARY(Oculus-static STATIC ${Oculus_SRCS}) + SET_TARGET_PROPERTIES(Oculus-static PROPERTIES OUTPUT_NAME "Oculus") + + TARGET_LINK_LIBRARIES(Oculus-static Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::OpenGL) + TARGET_LINK_LIBRARIES(Oculus-static ${OCULUS_SDK_PATH}/LibOVR/Lib/Windows/x64/Release/VS2017/libOVR.lib ws2_32) + + SET_TARGET_PROPERTIES(Oculus-static PROPERTIES COMPILE_FLAGS "-DQT_STATICPLUGIN") + ADD_DEPENDENCIES(AllStaticPlugins Oculus-static) + SET_TARGET_PROPERTIES(Oculus-static PROPERTIES FOLDER "plugins/Oculus") + +ELSE(IS_DIRECTORY ${OCULUS_SDK_PATH}) + MESSAGE(STATUS "Oculus SDK not found! Building without plugin. Set OCULUS_SDK_PATH in CMakeCache.txt!") + +ENDIF (IS_DIRECTORY ${OCULUS_SDK_PATH}) -SET_TARGET_PROPERTIES(Oculus-static PROPERTIES COMPILE_FLAGS "-DQT_STATICPLUGIN") -ADD_DEPENDENCIES(AllStaticPlugins Oculus-static) -SET_TARGET_PROPERTIES(Oculus-static PROPERTIES FOLDER "plugins/Oculus") diff --git a/plugins/Oculus/src/Oculus.cpp b/plugins/Oculus/src/Oculus.cpp index b53db865becf7..c8ac8aa9650f4 100644 --- a/plugins/Oculus/src/Oculus.cpp +++ b/plugins/Oculus/src/Oculus.cpp @@ -19,17 +19,17 @@ #include "Oculus.hpp" #include "StelActionMgr.hpp" #include "StelApp.hpp" -#include "StelLocaleMgr.hpp" +#include "StelTranslator.hpp" #include "StelMainView.hpp" #include "StelModuleMgr.hpp" #include "StelMovementMgr.hpp" -#include "StelOpenGL.hpp" +#include + +#include "OVR_CAPI_GL.h" #include "Extras/OVR_Math.h" #include -#include - #define OVRC(f) do { \ ovrResult result = f; \ if (OVR_FAILURE(result)) { \ @@ -40,10 +40,10 @@ void quat_to_mat4(const float q[4], float out[4][4]) { - float x = q[0]; - float y = q[1]; - float z = q[2]; - float w = q[3]; + const float x = q[0]; + const float y = q[1]; + const float z = q[2]; + const float w = q[3]; out[0][0] = 1-2*y*y-2*z*z; out[0][1] = 2*x*y+2*z*w; @@ -197,14 +197,37 @@ void Oculus::init() { qDebug() << "Oculus plugin."; initializeOpenGLFunctions(); - OVRC(ovr_Initialize(nullptr)); - ovrHmdDesc hmd = ovr_GetHmdDesc(nullptr); + +#ifndef NDEBUG + ovrInitParams initParams = { ovrInit_Debug | ovrInit_RequestVersion, OVR_MINOR_VERSION, NULL, 0, 100 }; +#else + ovrInitParams initParams = { ovrInit_RequestVersion, OVR_MINOR_VERSION, NULL, 0, 100 }; +#endif + + OVRC(ovr_Initialize(&initParams)); + + OVRC(ovr_Create(&session, &luid)); + + if (!session) + { + QMessageBox::StandardButton ret=QMessageBox::critical(&StelMainView::getInstance(), + q_("Oculus Plugin"), + q_("Initialisation failed. Please see logfile for details. Continue without headset?"), + QMessageBox::Ok|QMessageBox::Abort, QMessageBox::Ok); + qDebug() << "MessageBox returned" << ret; + if (ret==QMessageBox::Abort) + { + StelApp::getInstance().quit(); // seems not to work gracefully :-( + exit(0); + } + } + + ovrHmdDesc hmd = ovr_GetHmdDesc(session); if (hmd.Type == ovrHmd_None) { qDebug() << "No Oculus connected"; return; } - OVRC(ovr_Create(&session, &luid)); // Create the textures and layer. layer.Header.Type = ovrLayerType_EyeFov; @@ -255,6 +278,9 @@ void Oculus::update(double deltaTime) { Q_UNUSED(deltaTime); if (!session) return; + static StelCore* core = StelApp::getInstance().getCore(); + static StelMovementMgr* mmgr = GETSTELMODULE(StelMovementMgr); + ovrHmdDesc hmd = ovr_GetHmdDesc(session); double displayMidpointSeconds = ovr_GetPredictedDisplayTime(session, 0); @@ -263,10 +289,8 @@ void Oculus::update(double deltaTime) if (!(ts.StatusFlags & (ovrStatus_OrientationTracked | ovrStatus_PositionTracked))) return; ovrPosef pose = ts.HeadPose.ThePose; - StelCore* core = StelApp::getInstance().getCore(); // Set the view direction. - StelMovementMgr* mmgr = GETSTELMODULE(StelMovementMgr); QQuaternion quaternion(pose.Orientation.w, pose.Orientation.x, pose.Orientation.y, pose.Orientation.z); QVector3D qViewDirection = quaternion.rotatedVector(QVector3D(0, 0, -1)); Vec3d viewDirection(qViewDirection.x(), -qViewDirection.z(), qViewDirection.y()); @@ -342,5 +366,6 @@ void Oculus::drawEye(int eye, GLuint texid, int width, int height, const ovrFovP void Oculus::recenter() { + if (!session) return; OVRC(ovr_RecenterTrackingOrigin(session)); } diff --git a/plugins/Oculus/src/Oculus.hpp b/plugins/Oculus/src/Oculus.hpp index 3972c07bf9c9c..5d678d9f10ef6 100644 --- a/plugins/Oculus/src/Oculus.hpp +++ b/plugins/Oculus/src/Oculus.hpp @@ -20,18 +20,32 @@ #define _OCULUS_HPP_ #include "StelModule.hpp" -#include "StelOpenGL.hpp" -#include "OVR_CAPI_GL.h" +#include "OVR_CAPI.h" #include + +//! @class Oculus +//! This StelModule derivative provides a simple VR view in Oculus DK2 (deprecated), Oculus Rift and Meta Quest 2 headsets. +//! There is no interaction apart from viewing. The view is mirrored to the regular PC screen, +//! and some tutor is required to operate the Stellarium menu. +//! +//! The view is not really stereoscopic. The Scenery3D plugin cannot be used. +//! +//! To build, you need to install the Oculus SDK and add the path for cmake. +//! The easiest is to run cmake once and fill in the OCULUS_SDK_PATH in CMakeCache +//! Last tested with ovr_sdk_win_32.0.0 +//! +//! Much could be done to improve this: Some menu, gesture interaction, info panel to describe selected objects etc. +//! + class Oculus : public StelModule, protected QOpenGLFunctions { Q_OBJECT public: Oculus(); - virtual ~Oculus(); + ~Oculus() override; // Methods defined in the StelModule class void init() override;