2020-01-09 23:10:09 +00:00
|
|
|
#ifndef MWVR_OPENRXMANAGER_H
|
|
|
|
#define MWVR_OPENRXMANAGER_H
|
|
|
|
#ifndef USE_OPENXR
|
|
|
|
#error "openxrmanager.hpp included without USE_OPENXR defined"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <memory>
|
2020-02-14 21:11:19 +00:00
|
|
|
#include <array>
|
2020-01-09 23:10:09 +00:00
|
|
|
#include <mutex>
|
2020-01-26 19:06:47 +00:00
|
|
|
#include <components/debug/debuglog.hpp>
|
2020-01-09 23:10:09 +00:00
|
|
|
#include <components/sdlutil/sdlgraphicswindow.hpp>
|
|
|
|
#include <components/settings/settings.hpp>
|
|
|
|
#include <osg/Camera>
|
|
|
|
#include <osgViewer/Viewer>
|
|
|
|
|
|
|
|
|
|
|
|
struct XrSwapchainSubImage;
|
|
|
|
|
2020-01-23 23:14:23 +00:00
|
|
|
|
2020-01-09 23:10:09 +00:00
|
|
|
namespace MWVR
|
|
|
|
{
|
2020-01-26 19:06:47 +00:00
|
|
|
struct Timer
|
|
|
|
{
|
2020-02-02 12:12:53 +00:00
|
|
|
using Measure = std::pair < const char*, int64_t >;
|
|
|
|
using Measures = std::vector < Measure >;
|
|
|
|
using MeasurementContext = std::pair < const char*, Measures* >;
|
|
|
|
|
|
|
|
Timer(const char* name);
|
|
|
|
~Timer();
|
|
|
|
void checkpoint(const char* name);
|
2020-01-26 19:06:47 +00:00
|
|
|
|
|
|
|
std::chrono::steady_clock::time_point mBegin;
|
2020-02-02 12:12:53 +00:00
|
|
|
std::chrono::steady_clock::time_point mLastCheckpoint;
|
|
|
|
const char* mName = nullptr;
|
|
|
|
Measures* mContext = nullptr;
|
2020-01-26 19:06:47 +00:00
|
|
|
};
|
|
|
|
|
2020-01-23 23:14:23 +00:00
|
|
|
//! Represents the pose of a limb in VR space.
|
|
|
|
struct Pose
|
|
|
|
{
|
|
|
|
//! Position in VR space
|
2020-02-02 12:12:53 +00:00
|
|
|
osg::Vec3 position{ 0,0,0 };
|
2020-01-23 23:14:23 +00:00
|
|
|
//! Orientation in VR space.
|
2020-02-02 12:12:53 +00:00
|
|
|
osg::Quat orientation{ 0,0,0,1 };
|
2020-01-23 23:14:23 +00:00
|
|
|
//! Speed of movement in VR space, expressed in meters per second
|
2020-02-02 12:12:53 +00:00
|
|
|
osg::Vec3 velocity{ 0,0,0 };
|
2020-01-23 23:14:23 +00:00
|
|
|
};
|
|
|
|
|
2020-02-14 21:11:19 +00:00
|
|
|
using PoseSet = std::array<Pose, 2>;
|
|
|
|
|
|
|
|
struct PoseSets
|
|
|
|
{
|
|
|
|
PoseSet eye[2]{};
|
|
|
|
PoseSet hands[2]{};
|
|
|
|
PoseSet head{};
|
|
|
|
};
|
|
|
|
|
2020-01-23 23:14:23 +00:00
|
|
|
//! Describes what limb to track.
|
|
|
|
enum class TrackedLimb
|
|
|
|
{
|
|
|
|
LEFT_HAND,
|
|
|
|
RIGHT_HAND,
|
|
|
|
HEAD
|
|
|
|
};
|
|
|
|
|
|
|
|
//! Describes what space to track the limb in
|
|
|
|
enum class TrackedSpace
|
|
|
|
{
|
2020-02-02 12:12:53 +00:00
|
|
|
STAGE=0, //!< Track limb in the VR stage space. Meaning a space with a floor level origin and fixed horizontal orientation.
|
|
|
|
VIEW=1 //!< Track limb in the VR view space. Meaning a space with the head as origin and orientation.
|
2020-01-23 23:14:23 +00:00
|
|
|
};
|
|
|
|
|
2020-02-23 10:02:38 +00:00
|
|
|
enum class Side
|
2020-01-26 19:06:47 +00:00
|
|
|
{
|
2020-02-02 12:12:53 +00:00
|
|
|
LEFT_HAND = 0,
|
|
|
|
RIGHT_HAND = 1
|
2020-01-26 19:06:47 +00:00
|
|
|
};
|
|
|
|
|
2020-01-09 23:10:09 +00:00
|
|
|
// Use the pimpl pattern to avoid cluttering the namespace with openxr dependencies.
|
|
|
|
class OpenXRManagerImpl;
|
|
|
|
|
|
|
|
class OpenXRManager : public osg::Referenced
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
class RealizeOperation : public osg::GraphicsOperation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RealizeOperation(osg::ref_ptr<OpenXRManager> XR) : osg::GraphicsOperation("OpenXRRealizeOperation", false), mXR(XR) {};
|
|
|
|
void operator()(osg::GraphicsContext* gc) override;
|
2020-01-23 23:14:23 +00:00
|
|
|
virtual bool realized();
|
2020-01-09 23:10:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
osg::ref_ptr<OpenXRManager> mXR;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CleanupOperation : public osg::GraphicsOperation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CleanupOperation(osg::ref_ptr<OpenXRManager> XR) : osg::GraphicsOperation("OpenXRCleanupOperation", false), mXR(XR) {};
|
|
|
|
void operator()(osg::GraphicsContext* gc) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
osg::ref_ptr<OpenXRManager> mXR;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
OpenXRManager();
|
|
|
|
|
|
|
|
~OpenXRManager();
|
|
|
|
|
|
|
|
bool realized();
|
|
|
|
|
|
|
|
long long frameIndex();
|
|
|
|
bool sessionRunning();
|
|
|
|
|
|
|
|
void handleEvents();
|
|
|
|
void waitFrame();
|
2020-01-26 19:06:47 +00:00
|
|
|
void beginFrame();
|
2020-02-02 12:12:53 +00:00
|
|
|
void endFrame(int64_t displayTime, class OpenXRLayerStack* layerStack);
|
2020-01-09 23:10:09 +00:00
|
|
|
void updateControls();
|
2020-02-14 21:11:19 +00:00
|
|
|
void playerScale(MWVR::Pose& stagePose);
|
2020-01-09 23:10:09 +00:00
|
|
|
|
|
|
|
void realize(osg::GraphicsContext* gc);
|
|
|
|
|
|
|
|
int eyes();
|
|
|
|
|
2020-01-23 23:14:23 +00:00
|
|
|
OpenXRManagerImpl& impl() { return *mPrivate; }
|
|
|
|
|
|
|
|
private:
|
2020-01-09 23:10:09 +00:00
|
|
|
std::shared_ptr<OpenXRManagerImpl> mPrivate;
|
|
|
|
std::mutex mMutex;
|
|
|
|
using lock_guard = std::lock_guard<std::mutex>;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-01-23 23:14:23 +00:00
|
|
|
std::ostream& operator <<(std::ostream& os, const MWVR::Pose& pose);
|
|
|
|
|
2020-01-09 23:10:09 +00:00
|
|
|
#endif
|