-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
57 lines (44 loc) · 1.34 KB
/
example.js
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
const assert = require("assert")
const openvr = require("./index.js")
const { vec3, quat, mat4 } = require("gl-matrix")
let state = {
hmd: { pos: vec3.create(), quat: quat.create() },
trackers: [
{ pos: vec3.create(), quat: quat.create() },
{ pos: vec3.create(), quat: quat.create() },
]
}
const tmpmat = mat4.create();
try {
openvr.init(0);
} catch(e) {
throw openvr.EVRInitError[e];
}
function getTrackingData() {
//openvr.update();
// let res = openvr.waitGetPoses();
// if (res) {
// console.log(res)
// }
let trackerCount = 0;
for (let i=0; i<8; i++) {
let devclass = openvr.getTrackedDeviceClass(i)
if (openvr.ETrackedDeviceClass[devclass] == "TrackedDeviceClass_GenericTracker") {
let out = state.trackers[trackerCount]
openvr.getLastPoseForTrackedDeviceIndex(i, tmpmat)
mat4.getTranslation(out.pos, tmpmat)
mat4.getRotation(out.quat, tmpmat);
trackerCount++;
} else if (openvr.ETrackedDeviceClass[devclass] == "TrackedDeviceClass_HMD") {
let out = state.hmd
openvr.getLastPoseForTrackedDeviceIndex(i, tmpmat)
mat4.getTranslation(out.pos, tmpmat)
mat4.getRotation(out.quat, tmpmat)
}
}
//console.log(state)
return state;
}
setInterval(getTrackingData, 100)
console.log("openvr", openvr)
//console.log("event type", openvr.EVREventType[1707])