10 #include <QtCore/QLoggingCategory>
13 #include <GLMHelpers.h>
14 #include <glm/gtc/type_ptr.hpp>
15 #include <glm/gtc/matrix_transform.hpp>
17 #include <controllers/Forward.h>
19 Q_DECLARE_LOGGING_CATEGORY(displayplugins)
20 Q_DECLARE_LOGGING_CATEGORY(oculusLog)
25 static bool available();
26 static ovrSession acquireRenderSession();
27 static void releaseRenderSession(ovrSession session);
28 static void withSession(
const std::function<
void(ovrSession)>& f);
29 static ovrSessionStatus getStatus();
30 static ovrSessionStatus getStatus(ovrResult& result);
31 static ovrTrackingState getTrackingState(
double absTime = 0.0, ovrBool latencyMarker = ovrFalse);
32 static QString getError();
34 static inline bool quitRequested() {
return quitRequested(getStatus()); }
35 static inline bool reorientRequested() {
return reorientRequested(getStatus()); }
36 static inline bool hmdMounted() {
return hmdMounted(getStatus()); }
37 static inline bool hasInputFocus() {
return hasInputFocus(getStatus()); }
39 static inline bool quitRequested(
const ovrSessionStatus& status) {
return status.ShouldQuit != ovrFalse; }
40 static inline bool displayLost(
const ovrSessionStatus& status) {
return status.DisplayLost != ovrFalse; }
41 static inline bool isVisible(
const ovrSessionStatus& status) {
return status.IsVisible != ovrFalse; }
42 static inline bool reorientRequested(
const ovrSessionStatus& status) {
return status.ShouldRecenter != ovrFalse; }
43 static inline bool hmdMounted(
const ovrSessionStatus& status) {
return status.HmdMounted != ovrFalse; }
44 static inline bool hasInputFocus(
const ovrSessionStatus& status) {
return status.HasInputFocus != ovrFalse; }
47 static inline void for_each_eye(
const std::function<
void(ovrEyeType eye)>& f) {
48 for (ovrEyeType eye = ovrEye_Left; eye < ovrEye_Count; eye = static_cast<ovrEyeType>(eye + 1)) {
53 static inline void for_each_hand(
const std::function<
void(ovrHandType eye)>& f) {
54 for (ovrHandType hand = ovrHand_Left; hand < ovrHand_Count; hand = static_cast<ovrHandType>(hand + 1)) {
59 static inline glm::mat4 toGlm(
const ovrMatrix4f& om) {
60 return glm::transpose(glm::make_mat4(&om.M[0][0]));
63 static inline glm::mat4 toGlm(
const ovrFovPort& fovport,
float nearPlane = 0.01f,
float farPlane = 10000.0f) {
64 return toGlm(ovrMatrix4f_Projection(fovport, nearPlane, farPlane,
true));
67 static inline glm::vec3 toGlm(
const ovrVector3f& ov) {
68 return glm::make_vec3(&ov.x);
71 static inline glm::vec2 toGlm(
const ovrVector2f& ov) {
72 return glm::make_vec2(&ov.x);
75 static inline glm::uvec2 toGlm(
const ovrSizei& ov) {
76 return glm::uvec2(ov.w, ov.h);
79 static inline glm::quat toGlm(
const ovrQuatf& oq) {
80 return glm::make_quat(&oq.x);
83 static inline glm::mat4 toGlm(
const ovrPosef& op) {
84 glm::mat4 orientation = glm::mat4_cast(toGlm(op.Orientation));
85 glm::mat4 translation = glm::translate(glm::mat4(), toGlm(op.Position));
86 return translation * orientation;
89 static inline ovrMatrix4f fromGlm(
const glm::mat4& m) {
91 glm::mat4 transposed(glm::transpose(m));
92 memcpy(result.M, &(transposed[0][0]),
sizeof(
float) * 16);
96 static inline ovrVector3f fromGlm(
const glm::vec3& v) {
97 return { v.x, v.y, v.z };
100 static inline ovrVector2f fromGlm(
const glm::vec2& v) {
104 static inline ovrSizei fromGlm(
const glm::uvec2& v) {
105 return { (int)v.x, (
int)v.y };
108 static inline ovrQuatf fromGlm(
const glm::quat& q) {
109 return { q.x, q.y, q.z, q.w };
112 static inline ovrPosef poseFromGlm(
const glm::mat4& m) {
113 glm::vec3 translation = glm::vec3(m[3]) / m[3].w;
114 glm::quat orientation = glm::quat_cast(m);
116 result.Orientation = fromGlm(orientation);
117 result.Position = fromGlm(translation);
121 static controller::Pose toControllerPose(ovrHandType hand,
const ovrPoseStatef& handPose);
122 static controller::Pose toControllerPose(ovrHandType hand,
const ovrPoseStatef& handPose,
const ovrPoseStatef& lastHandPose);