forked from digitarhythm/VR360Contents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample2.html
150 lines (143 loc) · 6.29 KB
/
sample2.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
<!DOCTYPE html>
<html>
<head>
<title>vr.js Raw Data</title>
<script src="./extlib/vr.js"></script>
</head>
<body>
<canvas id="canvas" width="400" height="800"></canvas>
<script>
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
vr.load(function(error) {
if (error) {
window.alert('VR error:\n' + error.toString());
}
var state = new vr.State();
function tick() {
vr.requestAnimationFrame(tick);
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.fillStyle = 'black';
ctx.font = '12px monospace';
var w = 8;
var i0 = w * 0, i1 = w * 1, i2 = w * 2, i3 = w * 3;
var h = 12;
var y = 0;
if (!vr.pollState(state)) {
y += h; ctx.fillText('NPVR plugin not found/error polling', 0, y);
return;
}
if (state.sixense.present) {
y += h; ctx.fillText('sixense detected', i0, y);
for (var n = 0; n < state.sixense.controllers.length; n++) {
var controller = state.sixense.controllers[n];
y += h; ctx.fillText('controller ' + n + ':', i1, y);
y += h; ctx.fillText('isDocked: ' + controller.isDocked, i2, y);
var handValue;
switch (controller.hand) {
case vr.SixenseHand.UNKNOWN:
handValue = 'unknown';
break;
case vr.SixenseHand.LEFT:
handValue = 'left';
break;
case vr.SixenseHand.RIGHT:
handValue = 'right';
break;
}
y += h; ctx.fillText('hand: ' + handValue, i2, y);
y += h; ctx.fillText('tracking hemispheres: ' +
controller.isTrackingHemispheres, i2, y);
if (controller.buttons) {
var buttons = [];
if (controller.buttons & vr.SixenseButton.BUTTON_START) {
buttons.push('start');
}
if (controller.buttons & vr.SixenseButton.BUTTON_1) {
buttons.push('b1');
}
if (controller.buttons & vr.SixenseButton.BUTTON_2) {
buttons.push('b2');
}
if (controller.buttons & vr.SixenseButton.BUTTON_3) {
buttons.push('b3');
}
if (controller.buttons & vr.SixenseButton.BUTTON_4) {
buttons.push('b4');
}
if (controller.buttons & vr.SixenseButton.BUMPER) {
buttons.push('bumper');
}
if (controller.buttons & vr.SixenseButton.JOYSTICK) {
buttons.push('joystick');
}
y += h; ctx.fillText('buttons: ' + buttons.join(','), i2, y);
} else {
y += h; ctx.fillText('buttons: (none)', i2, y);
}
y += h; ctx.fillText('joystick:', i2, y);
y += h; ctx.fillText(controller.joystick[0], i3, y);
y += h; ctx.fillText(controller.joystick[1], i3, y);
y += h; ctx.fillText('trigger:', i2, y);
y += h; ctx.fillText(controller.trigger, i3, y);
y += h; ctx.fillText('position:', i2, y);
y += h; ctx.fillText(controller.position[0], i3, y);
y += h; ctx.fillText(controller.position[1], i3, y);
y += h; ctx.fillText(controller.position[2], i3, y);
y += h; ctx.fillText('rotation:', i2, y);
y += h; ctx.fillText(controller.rotation[0], i3, y);
y += h; ctx.fillText(controller.rotation[1], i3, y);
y += h; ctx.fillText(controller.rotation[2], i3, y);
y += h; ctx.fillText(controller.rotation[3], i3, y);
}
} else {
y += h; ctx.fillText('sixense not detected', 0, y);
}
if (state.hmd.present) {
y += h; ctx.fillText('oculus rift detected', 0, y);
var hmdInfo = vr.getHmdInfo();
if (hmdInfo) {
y += h; ctx.fillText('name: ' +
hmdInfo.toString(), i1, y);
y += h; ctx.fillText('desktop position (px): ' +
hmdInfo.desktopX + ',' + hmdInfo.desktopY, i1, y);
y += h; ctx.fillText('resolution (px): ' +
hmdInfo.resolutionHorz + 'x' + hmdInfo.resolutionVert, i1, y);
y += h; ctx.fillText('screen size (m): ' +
hmdInfo.screenSizeHorz + 'x' + hmdInfo.screenSizeVert, i1, y);
y += h; ctx.fillText('screen center (m): ' +
hmdInfo.screenCenterVert, i1, y);
y += h; ctx.fillText('eye-to-screen (m): ' +
hmdInfo.eyeToScreenDistance, i1, y);
y += h; ctx.fillText('lens separation (m): ' +
hmdInfo.lensSeparationDistance, i1, y);
y += h; ctx.fillText('IPD (m): ' +
hmdInfo.interpupillaryDistance, i1, y);
y += h; ctx.fillText('distortion k: ' +
hmdInfo.distortionK[0] + ',' +
hmdInfo.distortionK[1] + ',' +
hmdInfo.distortionK[2] + ',' +
hmdInfo.distortionK[3] + ',', i1, y);
y += h; ctx.fillText('chromaAbCorrection[0]: ' +
hmdInfo.chromaAbCorrection[0], i1, y);
y += h; ctx.fillText('chromaAbCorrection[1]: ' +
hmdInfo.chromaAbCorrection[1], i1, y);
y += h; ctx.fillText('chromaAbCorrection[2]: ' +
hmdInfo.chromaAbCorrection[2], i1, y);
y += h; ctx.fillText('chromaAbCorrection[3]: ' +
hmdInfo.chromaAbCorrection[3], i1, y);
}
y += h; ctx.fillText('rotation:', i1, y);
y += h; ctx.fillText(state.hmd.rotation[0], i2, y);
y += h; ctx.fillText(state.hmd.rotation[1], i2, y);
y += h; ctx.fillText(state.hmd.rotation[2], i2, y);
y += h; ctx.fillText(state.hmd.rotation[3], i2, y);
} else {
y += h; ctx.fillText('oculus rift not detected', 0, y);
}
};
vr.requestAnimationFrame(tick);
});
</script>
</body>
</html>