mirror of https://github.com/bjornbytes/lovr.git
WebXR input fixes;
This commit is contained in:
parent
fc48df874c
commit
98f481e941
|
@ -7,7 +7,7 @@ var webxr = {
|
||||||
left: [0, 3, null, 1, null, null, null, 4, 5],
|
left: [0, 3, null, 1, null, null, null, 4, 5],
|
||||||
right: [0, 3, null, 1, null, 4, 5, null, null],
|
right: [0, 3, null, 1, null, 4, 5, null, null],
|
||||||
},
|
},
|
||||||
'valve-index': [0, 3, 2, 1, null, 4, null, 4, null],
|
'valve-index': [0, 3, 2, 1, null, 4, null],
|
||||||
'microsoft-mixed-reality': [0, 3, 2, 1],
|
'microsoft-mixed-reality': [0, 3, 2, 1],
|
||||||
'htc-vive': [0, null, 2, 1],
|
'htc-vive': [0, null, 2, 1],
|
||||||
'generic-trigger': [0],
|
'generic-trigger': [0],
|
||||||
|
@ -94,7 +94,7 @@ var webxr = {
|
||||||
session.inputSources.forEach(function(inputSource) {
|
session.inputSources.forEach(function(inputSource) {
|
||||||
state.hands[({ left: 1, right: 2 })[inputSource.handedness]] = inputSource;
|
state.hands[({ left: 1, right: 2 })[inputSource.handedness]] = inputSource;
|
||||||
|
|
||||||
var profile = inputSource.profiles.find(function(profile) { return mappings[profile]; });
|
var profile = inputSource.profiles.find(function(profile) { return buttons[profile]; });
|
||||||
|
|
||||||
if (!inputSource.gamepad || !profile) {
|
if (!inputSource.gamepad || !profile) {
|
||||||
inputSource.buttons = [];
|
inputSource.buttons = [];
|
||||||
|
@ -143,7 +143,7 @@ var webxr = {
|
||||||
fn();
|
fn();
|
||||||
state.hands.forEach(function(inputSource, i) {
|
state.hands.forEach(function(inputSource, i) {
|
||||||
state.lastButtonState[i] = inputSource && inputSource.buttons.map(function(button) {
|
state.lastButtonState[i] = inputSource && inputSource.buttons.map(function(button) {
|
||||||
return button.pressed;
|
return button && button.pressed;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -277,16 +277,16 @@ var webxr = {
|
||||||
},
|
},
|
||||||
|
|
||||||
webxr_isDown: function(device, button, down, changed) {
|
webxr_isDown: function(device, button, down, changed) {
|
||||||
var button = state.hands[device] && state.hands[device].button;
|
var b = state.hands[device] && state.hands[device].buttons[button];
|
||||||
HEAPU32[down >> 2] = button && button.pressed;
|
HEAPU8[down] = b && b.pressed;
|
||||||
HEAPU32[changed >> 2] = button && (state.lastButtonState[device][button] ^ button.pressed);
|
HEAPU8[changed] = b && (state.lastButtonState[device][button] ^ b.pressed);
|
||||||
return !!button;
|
return !!b;
|
||||||
},
|
},
|
||||||
|
|
||||||
webxr_isTouched: function(device, button, touched) {
|
webxr_isTouched: function(device, button, touched) {
|
||||||
var button = state.hands[device] && state.hands[device].button;
|
var b = state.hands[device] && state.hands[device].buttons[button];
|
||||||
HEAPU32[touched >> 2] = button && button.touched;
|
HEAPU8[touched] = b && b.touched;
|
||||||
return !!button;
|
return !!b;
|
||||||
},
|
},
|
||||||
|
|
||||||
webxr_getAxis: function(device, axis, value) {
|
webxr_getAxis: function(device, axis, value) {
|
||||||
|
@ -303,13 +303,13 @@ var webxr = {
|
||||||
return !!hand.buttons[axis];
|
return !!hand.buttons[axis];
|
||||||
|
|
||||||
case 1: /* AXIS_THUMBSTICK */
|
case 1: /* AXIS_THUMBSTICK */
|
||||||
HEAPF32[value >> 2 + 0] = hand.gamepad.axes[2];
|
HEAPF32[(value >> 2) + 0] = hand.gamepad.axes[2];
|
||||||
HEAPF32[value >> 2 + 1] = hand.gamepad.axes[3];
|
HEAPF32[(value >> 2) + 1] = hand.gamepad.axes[3];
|
||||||
return hand.axes.thumbstick;
|
return hand.axes.thumbstick;
|
||||||
|
|
||||||
case 2: /* AXIS_TOUCHPAD */
|
case 2: /* AXIS_TOUCHPAD */
|
||||||
HEAPF32[value >> 2 + 0] = hand.gamepad.axes[0];
|
HEAPF32[(value >> 2) + 0] = hand.gamepad.axes[0];
|
||||||
HEAPF32[value >> 2 + 1] = hand.gamepad.axes[1];
|
HEAPF32[(value >> 2) + 1] = hand.gamepad.axes[1];
|
||||||
return hand.axes.touchpad;
|
return hand.axes.touchpad;
|
||||||
|
|
||||||
default: return false;
|
default: return false;
|
||||||
|
@ -362,23 +362,23 @@ var webxr = {
|
||||||
if (state.viewer) {
|
if (state.viewer) {
|
||||||
var views = state.viewer.views;
|
var views = state.viewer.views;
|
||||||
HEAPF32.set(views[0].transform.inverse.matrix, matrix >> 2);
|
HEAPF32.set(views[0].transform.inverse.matrix, matrix >> 2);
|
||||||
Module['_lovrGraphicsSetViewMatrix'](0, matrix);
|
Module._lovrGraphicsSetViewMatrix(0, matrix);
|
||||||
HEAPF32.set(views[1].transform.inverse.matrix, matrix >> 2);
|
HEAPF32.set(views[1].transform.inverse.matrix, matrix >> 2);
|
||||||
Module['_lovrGraphicsSetViewMatrix'](1, matrix);
|
Module._lovrGraphicsSetViewMatrix(1, matrix);
|
||||||
HEAPF32.set(views[0].projectionMatrix, matrix >> 2);
|
HEAPF32.set(views[0].projectionMatrix, matrix >> 2);
|
||||||
Module['_lovrGraphicsSetProjection'](0, matrix);
|
Module._lovrGraphicsSetProjection(0, matrix);
|
||||||
HEAPF32.set(views[1].projectionMatrix, matrix >> 2);
|
HEAPF32.set(views[1].projectionMatrix, matrix >> 2);
|
||||||
Module['_lovrGraphicsSetProjection'](1, matrix);
|
Module._lovrGraphicsSetProjection(1, matrix);
|
||||||
} else {
|
} else {
|
||||||
HEAPF32.set([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], matrix >> 2);
|
HEAPF32.set([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1], matrix >> 2);
|
||||||
Module['_lovrGraphicsSetViewMatrix'](0, matrix);
|
Module._lovrGraphicsSetViewMatrix(0, matrix);
|
||||||
Module['_lovrGraphicsSetViewMatrix'](1, matrix);
|
Module._lovrGraphicsSetViewMatrix(1, matrix);
|
||||||
// TODO projection?
|
// TODO projection?
|
||||||
}
|
}
|
||||||
Module.stackRestore(matrix);
|
Module.stackRestore(matrix);
|
||||||
Module['_lovrGraphicsSetBackbuffer'](state.canvas, true, true);
|
Module._lovrGraphicsSetBackbuffer(state.canvas, true, true);
|
||||||
Module['dynCall_vi'](callback, userdata);
|
Module.dynCall_vi(callback, userdata);
|
||||||
Module['_lovrGraphicsSetBackbuffer'](0, false, false);
|
Module._lovrGraphicsSetBackbuffer(0, false, false);
|
||||||
},
|
},
|
||||||
|
|
||||||
webxr_update: function(dt) {
|
webxr_update: function(dt) {
|
||||||
|
|
Loading…
Reference in New Issue