-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Axismove for touch and vive #2513
Changes from all commits
0fb4e70
24d1e72
03b9645
fa09983
60bbf95
1c97bd5
0f2cb4f
6a030d9
f204381
c48fe0d
5b8fdc5
8b9380e
9bb1b58
299d2c1
41a1b55
a3e96c9
10ae085
16ba6de
0dd0da0
1f37fce
2c3c3a4
4e5c303
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
var registerComponent = require('../core/component').registerComponent; | ||
var bind = require('../utils/bind'); | ||
var isControllerPresent = require('../utils/tracked-controls').isControllerPresent; | ||
var emitIfAxesChanged = require('../utils/tracked-controls').emitIfAxesChanged; | ||
|
||
var DAYDREAM_CONTROLLER_MODEL_BASE_URL = 'https://cdn.aframe.io/controllers/google/'; | ||
var DAYDREAM_CONTROLLER_MODEL_OBJ_URL = DAYDREAM_CONTROLLER_MODEL_BASE_URL + 'vr_controller_daydream.obj'; | ||
|
@@ -29,20 +30,21 @@ module.exports.Component = registerComponent('daydream-controls', { | |
// 1 - menu ( never dispatched on this layer ) | ||
// 2 - system ( never dispatched on this layer ) | ||
mapping: { | ||
axis0: 'trackpad', | ||
axis1: 'trackpad', | ||
button0: 'trackpad', | ||
button1: 'menu', | ||
button2: 'system' | ||
axes: {'trackpad': [0, 1]}, | ||
buttons: ['trackpad', 'menu', 'system'] | ||
}, | ||
|
||
// Use these labels for detail on axis events such as thumbstickmoved. | ||
// e.g. for thumbstickmoved detail, the first axis returned is labeled x, and the second is labeled y. | ||
axisLabels: ['x', 'y', 'z', 'w'], | ||
|
||
bindMethods: function () { | ||
this.onModelLoaded = bind(this.onModelLoaded, this); | ||
this.onControllersUpdate = bind(this.onControllersUpdate, this); | ||
this.checkIfControllerPresent = bind(this.checkIfControllerPresent, this); | ||
this.removeControllersUpdateListener = bind(this.removeControllersUpdateListener, this); | ||
this.onGamepadConnected = bind(this.onGamepadConnected, this); | ||
this.onGamepadDisconnected = bind(this.onGamepadDisconnected, this); | ||
this.onAxisMoved = bind(this.onAxisMoved, this); | ||
this.onGamepadConnectionEvent = bind(this.onGamepadConnectionEvent, this); | ||
}, | ||
|
||
init: function () { | ||
|
@@ -58,6 +60,7 @@ module.exports.Component = registerComponent('daydream-controls', { | |
this.lastControllerCheck = 0; | ||
this.bindMethods(); | ||
this.isControllerPresent = isControllerPresent; // to allow mock | ||
this.emitIfAxesChanged = emitIfAxesChanged; // to allow mock | ||
}, | ||
|
||
addEventListeners: function () { | ||
|
@@ -87,40 +90,33 @@ module.exports.Component = registerComponent('daydream-controls', { | |
if (isPresent) { this.injectTrackedControls(); } // inject track-controls | ||
}, | ||
|
||
onGamepadConnected: function (evt) { | ||
// for now, don't disable controller update listening, due to | ||
// apparent issue with FF Nightly only sending one event and seeing one controller; | ||
// this.everGotGamepadEvent = true; | ||
// this.removeControllersUpdateListener(); | ||
this.checkIfControllerPresent(); | ||
}, | ||
|
||
onGamepadDisconnected: function (evt) { | ||
// for now, don't disable controller update listening, due to | ||
// apparent issue with FF Nightly only sending one event and seeing one controller; | ||
// this.everGotGamepadEvent = true; | ||
// this.removeControllersUpdateListener(); | ||
onGamepadConnectionEvent: function (evt) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can get rid of this method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see below comment on the everGotGamepadEvent flag |
||
this.everGotGamepadEvent = true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This flag is never checked There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can see why in the comments, but yeah we can remove them for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually it is checked in onControllersUpdate (which last I recall is actually fired every tick). so the idea is that if you got gamepad connect/disconnect events, you don't always need to be checking to see when it shows up There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have to set the flag to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no because we expect |
||
// Due to an apparent bug in FF Nightly | ||
// where only one gamepadconnected / disconnected event is fired, | ||
// which makes it difficult to handle in individual controller entities, | ||
// we no longer remove the controllersupdate listener as a result. | ||
this.checkIfControllerPresent(); | ||
}, | ||
|
||
play: function () { | ||
this.checkIfControllerPresent(); | ||
window.addEventListener('gamepadconnected', this.onGamepadConnected, false); | ||
window.addEventListener('gamepaddisconnected', this.onGamepadDisconnected, false); | ||
this.addControllersUpdateListener(); | ||
this.addEventListeners(); | ||
window.addEventListener('gamepadconnected', this.onGamepadConnectionEvent, false); | ||
window.addEventListener('gamepaddisconnected', this.onGamepadConnectionEvent, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see below comment on the everGotGamepadEvent flag |
||
}, | ||
|
||
pause: function () { | ||
window.removeEventListener('gamepadconnected', this.onGamepadConnected, false); | ||
window.removeEventListener('gamepaddisconnected', this.onGamepadDisconnected, false); | ||
this.removeControllersUpdateListener(); | ||
this.removeEventListeners(); | ||
this.removeControllersUpdateListener(); | ||
window.removeEventListener('gamepadconnected', this.onGamepadConnectionEvent, false); | ||
window.removeEventListener('gamepaddisconnected', this.onGamepadConnectionEvent, false); | ||
}, | ||
|
||
injectTrackedControls: function () { | ||
var el = this.el; | ||
var data = this.data; | ||
this.addEventListeners(); | ||
el.setAttribute('tracked-controls', {idPrefix: GAMEPAD_ID_PREFIX, hand: data.hand, rotationOffset: data.rotationOffset}); | ||
if (!this.data.model) { return; } | ||
this.el.setAttribute('obj-model', { | ||
|
@@ -155,13 +151,10 @@ module.exports.Component = registerComponent('daydream-controls', { | |
controllerObject3D.position.set(0, 0, -0.04); | ||
}, | ||
|
||
onAxisMoved: function (evt) { | ||
if (evt.detail.axis[0] === 0 && evt.detail.axis[1] === 0) { return; } | ||
this.el.emit('trackpadmoved', { x: evt.detail.axis[0], y: evt.detail.axis[1] }); | ||
}, | ||
onAxisMoved: function (evt) { this.emitIfAxesChanged(this, this.mapping.axes, evt); }, | ||
|
||
onButtonEvent: function (id, evtName) { | ||
var buttonName = this.mapping['button' + id]; | ||
var buttonName = this.mapping.buttons[id]; | ||
var i; | ||
if (Array.isArray(buttonName)) { | ||
for (i = 0; i < buttonName.length; i++) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can get rid of this since we can do
window.addEventListener('gamepaddisconnected', this.checkIfControllerPresent, false);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see below comment on the everGotGamepadEvent flag