11 #include <glm/glm.hpp>
12 #include <glm/gtc/type_ptr.hpp>
13 #include <glm/gtc/matrix_transform.hpp>
14 #include <VrApi_Types.h>
19 float leftRightUpDown[4];
21 Fov(
const ovrMatrix4f& mat) { extract(mat); }
22 void extract(
const ovrMatrix4f& mat);
23 void extend(
const Fov& other);
24 glm::mat4 withZ(
const glm::mat4& other)
const;
25 glm::mat4 withZ(
float nearZ,
float farZ)
const;
29 static inline void for_each_eye(
const std::function<
void(ovrEye)>& f) {
34 static inline void for_each_hand(
const std::function<
void(ovrTrackedDeviceTypeId)>& f) {
35 f(VRAPI_TRACKED_DEVICE_HAND_LEFT);
36 f(VRAPI_TRACKED_DEVICE_HAND_RIGHT);
39 static inline glm::mat4 toGlm(
const ovrMatrix4f& om) {
40 return glm::transpose(glm::make_mat4(&om.M[0][0]));
43 static inline glm::vec3 toGlm(
const ovrVector3f& ov) {
44 return glm::make_vec3(&ov.x);
47 static inline glm::vec2 toGlm(
const ovrVector2f& ov) {
48 return glm::make_vec2(&ov.x);
51 static inline glm::quat toGlm(
const ovrQuatf& oq) {
52 return glm::make_quat(&oq.x);
55 static inline glm::mat4 toGlm(
const ovrPosef& op) {
56 glm::mat4 orientation = glm::mat4_cast(toGlm(op.Orientation));
57 glm::mat4 translation = glm::translate(glm::mat4(), toGlm(op.Position));
58 return translation * orientation;
61 static inline ovrMatrix4f fromGlm(
const glm::mat4& m) {
63 glm::mat4 transposed(glm::transpose(m));
64 memcpy(result.M, &(transposed[0][0]),
sizeof(
float) * 16);
68 static inline ovrVector3f fromGlm(
const glm::vec3& v) {
69 return { v.x, v.y, v.z };
72 static inline ovrVector2f fromGlm(
const glm::vec2& v) {
76 static inline ovrQuatf fromGlm(
const glm::quat& q) {
77 return { q.x, q.y, q.z, q.w };
80 static inline ovrPosef poseFromGlm(
const glm::mat4& m) {
81 glm::vec3 translation = glm::vec3(m[3]) / m[3].w;
82 glm::quat orientation = glm::quat_cast(m);
84 result.Orientation = fromGlm(orientation);
85 result.Position = fromGlm(translation);