This repository was archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathindex.html
More file actions
103 lines (84 loc) · 3.57 KB
/
Copy pathindex.html
File metadata and controls
103 lines (84 loc) · 3.57 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<title>VR Gamepads basic test</title>
</head>
<body>
<h1>VR Gamepads basic test</h1>
<p></p>
<ul>
</ul>
<script>
var list = document.querySelector('ul');
var info = document.querySelector('p');
var initialRun = true;
if(navigator.getVRDisplays && navigator.getGamepads) {
info.textContent = 'WebVR API and Gamepad API supported.'
reportDisplays();
} else {
info.textContent = 'WebVR API and/or Gamepad API not supported by this browser.'
}
function reportDisplays() {
navigator.getVRDisplays().then(function(displays) {
console.log(displays.length + ' displays');
for(var i = 0; i < displays.length; i++) {
var cap = displays[i].capabilities;
// cap is a VRDisplayCapabilities object
var listItem = document.createElement('li');
listItem.innerHTML = '<strong>Display ' + (i+1) + '</strong>'
+ '<br>VR Display ID: ' + displays[i].displayId
+ '<br>VR Display Name: ' + displays[i].displayName
+ '<br>Display can present content: ' + cap.canPresent
+ '<br>Display is separate from the computer\'s main display: ' + cap.hasExternalDisplay
+ '<br>Display can return position info: ' + cap.hasPosition
+ '<br>Display can return orientation info: ' + cap.hasOrientation
+ '<br>Display max layers: ' + cap.maxLayers;
list.appendChild(listItem);
}
setTimeout(reportGamepads, 1000);
// For VR, controllers will only be active after their corresponding headset is active
});
}
function reportGamepads() {
var gamepads = navigator.getGamepads();
console.log(gamepads.length + ' controllers');
for(var i = 0; i < gamepads.length; ++i) {
var gp = gamepads[i];
var listItem = document.createElement('li');
listItem.classList = 'gamepad';
listItem.innerHTML = '<strong>Gamepad ' + gp.index + '</strong> (' + gp.id + ')'
+ '<br>Associated with VR Display ID: ' + gp.displayId
+ '<br>Gamepad associated with which hand: ' + gp.hand
+ '<br>Available haptic actuators: ' + gp.hapticActuators.length
+ '<br>Gamepad can return position info: ' + gp.pose.hasPosition
+ '<br>Gamepad can return orientation info: ' + gp.pose.hasOrientation;
list.appendChild(listItem);
}
initialRun = false;
}
// Remove gamepads when needed
function removeGamepads() {
var gpLi = document.querySelectorAll('.gamepad');
for(var i = 0; i < gpLi.length; i++) {
list.removeChild(gpLi[i]);
}
reportGamepads();
}
// Events
// Gamepad API events, supported in Firefox and Chrome
window.addEventListener('gamepadconnected', function(e) {
info.textContent = 'Gamepad ' + e.gamepad.index + ' connected.';
if(!initialRun) {
setTimeout(removeGamepads, 1000);
}
});
window.addEventListener('gamepaddisconnected', function(e) {
info.textContent = 'Gamepad ' + e.gamepad.index + ' disconnected.';
setTimeout(removeGamepads, 1000);
});
</script>
</body>
</html>