-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrift_in_action.h
92 lines (72 loc) · 2 KB
/
rift_in_action.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// Created by James Anderson on 10/1/16.
//
#ifndef PROJECT_RIFT_IN_ACTION_H
#define PROJECT_RIFT_IN_ACTION_H
#include <OVR.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/noise.hpp>
#include <glm/gtc/epsilon.hpp>
#include <glm/gtx/norm.hpp>
using namespace glm;
namespace rift_in_action {
inline mat4 toGlm(const ovrMatrix4f & om) {
return glm::transpose(glm::make_mat4(&om.M[0][0]));
}
inline mat4 toGlm(const ovrFovPort & fovport, float nearPlane = 0.01f, float farPlane = 10000.0f) {
return toGlm(ovrMatrix4f_Projection(fovport, nearPlane, farPlane, true));
}
inline vec3 toGlm(const ovrVector3f & ov) {
return glm::make_vec3(&ov.x);
}
inline vec2 toGlm(const ovrVector2f & ov) {
return glm::make_vec2(&ov.x);
}
inline uvec2 toGlm(const ovrSizei & ov) {
return uvec2(ov.w, ov.h);
}
inline quat toGlm(const ovrQuatf & oq) {
return glm::make_quat(&oq.x);
}
inline mat4 toGlm(const ovrPosef & op) {
mat4 orientation = glm::mat4_cast(toGlm(op.Orientation));
mat4 translation = glm::translate(mat4(), rift_in_action::toGlm(op.Position));
return translation * orientation;
}
inline ovrMatrix4f fromGlm(const mat4 & m) {
ovrMatrix4f result;
mat4 transposed(glm::transpose(m));
memcpy(result.M, &(transposed[0][0]), sizeof(float) * 16);
return result;
}
inline ovrVector3f fromGlm(const vec3 & v) {
ovrVector3f result;
result.x = v.x;
result.y = v.y;
result.z = v.z;
return result;
}
inline ovrVector2f fromGlm(const vec2 & v) {
ovrVector2f result;
result.x = v.x;
result.y = v.y;
return result;
}
inline ovrSizei fromGlm(const uvec2 & v) {
ovrSizei result;
result.w = v.x;
result.h = v.y;
return result;
}
inline ovrQuatf fromGlm(const quat & q) {
ovrQuatf result;
result.x = q.x;
result.y = q.y;
result.z = q.z;
result.w = q.w;
return result;
}
}
#endif //PROJECT_RIFT_IN_ACTION_H