CS185c
Chris Pollett
Mar 18, 2019
Which of the following statements is true?
function gamepadHandler(e, connecting)
{
var gamepad = e.gamepad;
if (connecting) {
console.log("Gamepad connected at index " +
gamepad.index + ": "+ gamepad.id + ". " +
gamepad.buttons.length + " buttons," +
gamepad.axes.length + " axes.");
} else {
console.log("Gamepad disconnected from index "+
gamepad.index + ": "+ gamepad.id);
}
}
window.addEventListener("gamepadconnected", function(e) {
gamepadHandler(e, true); }, false);
window.addEventListener("gamepaddisconnected", function(e) {
gamepadHandler(e, false); }, false);
03-18 11:57:25.554 2233 2233 I chromium: [INFO:CONSOLE(215)] "Gamepad connected at index 0: Oculus Go Controller. 2 buttons, 2 axes.", source: https://www.cs.sjsu.edu/faculty/pollett/ 185c.1.19s/WebGamePad.html (215)in the log.
gamepads = navigator.getGamepads();
if (gamepads != {}) {
console.log("We have at least one Gamepad!");
for (var i = 0; i < gamepads.length; i++)
if (gamepads[i] && gamepads[i].connected) {
var buttons = gamepads[i].buttons;
console.log("Num Buttons" + buttons.length);
// asssuming Oculus Go so know button number should be 2.
console.log("Button 0 pressed? " + gamepads[i].buttons[0].pressed);
console.log("Button 1 pressed? " + gamepads[i].buttons[1].pressed);
console.log("Left right trackpad value " + gamepads[i].axes[0]);
console.log("Up down trackpad value " + gamepads[i].axes[1]);
console.log("Hand controller is for " + gamepads[i].hand + " hand.");
console.log("Controller supports pose " +
gamepads[i].pose.hasOrientation);
console.log("Pos orientation quarternion " +
gamepads[i].pose.orientation);
}
}
03-18 12:10:10.533 2233 2233 I chromium: [INFO:CONSOLE(425)] "We have at least one Gamepad!", source: https://www.cs.sjsu.edu/faculty/pollett/185c.1.19s/WebGamePad.html (425) 03-18 12:10:10.533 2233 2233 I chromium: [INFO:CONSOLE(429)] "Num Buttons2", source: https://www.cs.sjsu.edu/faculty/pollett/185c.1.19s/WebGamePad.html (429) 03-18 12:10:10.533 2233 2233 I chromium: [INFO:CONSOLE(431)] "Button 0 pressed? false", source: https://www.cs.sjsu.edu/faculty/pollett/185c.1.19s/WebGamePad.html (431) 03-18 12:10:10.533 2233 2233 I chromium: [INFO:CONSOLE(432)] "Button 1 pressed? false", source: https://www.cs.sjsu.edu/faculty/pollett/185c.1.19s/WebGamePad.html (432) 03-18 12:10:10.533 2233 2233 I chromium: [INFO:CONSOLE(433)] "Left right trackpad value 0", source: https://www.cs.sjsu.edu/faculty/pollett/185c.1.19s/WebGamePad.html (433) 03-18 12:10:10.533 2233 2233 I chromium: [INFO:CONSOLE(434)] "Up down trackpad value 0", source: https://www.cs.sjsu.edu/faculty/pollett/185c.1.19s/WebGamePad.html (434) 03-18 12:10:10.533 2233 2233 I chromium: [INFO:CONSOLE(435)] "Hand controller is for right hand.", source: https://www.cs.sjsu.edu/faculty/pollett/185c.1.19s/WebGamePad.html (435) 03-18 12:10:10.533 2233 2233 I chromium: [INFO:CONSOLE(436)] "Controller supports pose true", source: https://www.cs.sjsu.edu/faculty/pollett/185c.1.19s/WebGamePad.html (436) 03-18 12:10:10.533 2233 2233 I chromium: [INFO:CONSOLE(437)] "Pos orientation quarternion 0.0631496012210846,-0.12882277369499207,0.023658324033021927,0.9893720746040344", source: https://www.cs.sjsu.edu/faculty/pollett/185c.1.19s/WebGamePad.html (437) 03-18 12:10:10.658 2233 11306 I chromium: [INFO:vr_shell_gl.cc(1493)] Left VR 03-18 12:10:10.667 2233 2233 I chromium: [INFO:CONSOLE(219)] "Gamepad disconnected from index 0: Oculus Go Controller", source: https://www.cs.sjsu.edu/faculty/pollett/185c.1.19s/WebGamePad.html (219)
function getPoseMatrix(out, pose)
{
var orientation = pose.orientation;
if (!orientation) {
orientation = [0, 0, 0, 1];
}
mat4.fromQuat(out, orientation);
mat4.invert(out, out);
}
which we used to get a matrix to convert into the headset orientation can also be used to convert the orientation of a Gamepad pose to a matrix.mat4.multiply(vrModelViewMatrix, poseMatrix, modelViewMatrix); gl.uniformMatrix4fv(programInfo.uniformLocations.modelViewMatrix, false, vrModelViewMatrix); // code as before to set up project matrix and viewport for given eye gl.drawElements(gl.TRIANGLES, vertexCount, type, offset);to draw the gamepad.