-
Notifications
You must be signed in to change notification settings - Fork 8
/
vr-controls.js
48 lines (38 loc) · 1.15 KB
/
vr-controls.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
THREE.VRControls = function (object) {
var vrDisplay;
var frameData = null;
if ('VRFrameData' in window) {
frameData = new VRFrameData();
}
function gotVRDisplays(displays) {
if (displays.length > 0) {
vrDisplay = displays[0];
}
}
navigator.getVRDisplays && navigator.getVRDisplays().then(gotVRDisplays);
this.update = function () {
if (vrDisplay) {
var pose;
if (vrDisplay.getFrameData) {
vrDisplay.getFrameData(frameData);
pose = frameData.pose;
} else if (vrDisplay.getPose) {
pose = vrDisplay.getPose();
}
if (pose && pose.orientation !== null) {
for (var i = 0; i < 3; ++i) {
pose.orientation[i] = Math.min(0.2, Math.max(-0.2, pose.orientation[i]));
}
object.quaternion.fromArray(pose.orientation);
}
}
};
this.resetPose = function () {
if ( vrDisplay ) {
vrDisplay.resetPose();
}
};
// this.dispose = function () {
// vrDisplay = null;
// };
};