Skip to content

Commit

Permalink
Oculus plugin: Add minimal documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
gzotti committed Jan 22, 2024
1 parent cbb18be commit 2ab7f9e
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 36 deletions.
50 changes: 30 additions & 20 deletions plugins/Oculus/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
51 changes: 38 additions & 13 deletions plugins/Oculus/src/Oculus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <QMessageBox>

#include "OVR_CAPI_GL.h"
#include "Extras/OVR_Math.h"

#include <QOpenGLFramebufferObject>

#include <assert.h>

#define OVRC(f) do { \
ovrResult result = f; \
if (OVR_FAILURE(result)) { \
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand Down Expand Up @@ -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));
}
20 changes: 17 additions & 3 deletions plugins/Oculus/src/Oculus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,32 @@
#define _OCULUS_HPP_

#include "StelModule.hpp"
#include "StelOpenGL.hpp"
#include "OVR_CAPI_GL.h"
#include "OVR_CAPI.h"

#include <QOpenGLFunctions>


//! @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;
Expand Down

0 comments on commit 2ab7f9e

Please sign in to comment.