Skip to content
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

cardboard support for cursor-controller #343

Merged
merged 5 commits into from
May 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/components/cursor-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ AFRAME.registerComponent("cursor-controller", {
this.data.playerRig.addEventListener(this.data.primaryUp, this._handlePrimaryUp);
this.data.playerRig.addEventListener(this.data.grabEvent, this._handlePrimaryDown);
this.data.playerRig.addEventListener(this.data.releaseEvent, this._handlePrimaryUp);
this.data.playerRig.addEventListener("gamepadbuttondown", this._handlePrimaryDown);
Copy link
Contributor

@cvan cvan May 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(apologies in advance, as I know this is a WIP PR.)

is this a correct branch? this appears to be for #364 perhaps?

btw, gamepadbuttondown/gamepadbuttonup/gamepadaxismove are events that are proprietary to and work only in Firefox. (see w3c/gamepad#15 for context.) also, only in Firefox Nightly/Beta is the about:config flag dom.gamepad.non_standard_events set to true; in release-channel Firefox, it's false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gd lol, I should've checked before spamming you with unnecessary info. thanks!

this.data.playerRig.addEventListener("gamepadbuttonup", this._handlePrimaryUp);

this.data.playerRig.addEventListener("model-loaded", this._handleModelLoaded);

Expand All @@ -116,6 +118,8 @@ AFRAME.registerComponent("cursor-controller", {
this.data.playerRig.removeEventListener(this.data.primaryUp, this._handlePrimaryUp);
this.data.playerRig.removeEventListener(this.data.grabEvent, this._handlePrimaryDown);
this.data.playerRig.removeEventListener(this.data.releaseEvent, this._handlePrimaryUp);
this.data.playerRig.removeEventListener("gamepadbuttondown", this._handlePrimaryDown);
this.data.playerRig.removeEventListener("gamepadbuttonup", this._handlePrimaryUp);

this.data.playerRig.removeEventListener("model-loaded", this._handleModelLoaded);

Expand Down Expand Up @@ -317,11 +321,13 @@ AFRAME.registerComponent("cursor-controller", {

for (let i = 0; i < e.changedTouches.length; i++) {
const touch = e.changedTouches[i];
const thisTouchDidNotDriveMousePos =
Math.abs(touch.clientX - this.lastTouch.clientX) > 0.1 &&
Math.abs(touch.clientY - this.lastTouch.clientY) > 0.1;
if (thisTouchDidNotDriveMousePos) {
return;
if (this.lastTouch) {
const thisTouchDidNotDriveMousePos =
Math.abs(touch.clientX - this.lastTouch.clientX) > 0.1 &&
Math.abs(touch.clientY - this.lastTouch.clientY) > 0.1;
if (thisTouchDidNotDriveMousePos) {
return;
}
}
}
this._setLookControlsEnabled(true);
Expand Down Expand Up @@ -370,10 +376,8 @@ AFRAME.registerComponent("cursor-controller", {
},

_handleEnterVR: function() {
if (AFRAME.utils.device.checkHeadsetConnected()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was it necessary to remove this check? In theory it should return true because the polyfill provides a "Cardboard" headset.

Copy link
Contributor Author

@InfiniteLee InfiniteLee May 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if thats true, at least it wasn't in the older version of the polyfill. But regardless listening to just enter/exit VR should be sufficient. That check was mostly just there as a holdover from before when we only used the cursor for 2d mode.

this.inVR = true;
this._updateController();
}
this.inVR = true;
this._updateController();
},

_handleExitVR: function() {
Expand All @@ -382,7 +386,7 @@ AFRAME.registerComponent("cursor-controller", {
},

_handlePrimaryDown: function(e) {
if (e.target === this.controller) {
if (e.target === this.controller || e.type === "gamepadbuttondown") {
const isInteractable = this._isTargetOfType(TARGET_TYPE_INTERACTABLE) && !this.grabStarting;
if (isInteractable || this._isTargetOfType(TARGET_TYPE_UI)) {
this.grabStarting = true;
Expand All @@ -394,7 +398,7 @@ AFRAME.registerComponent("cursor-controller", {
},

_handlePrimaryUp: function(e) {
if (e.target === this.controller) {
if (e.target === this.controller || e.type === "gamepadbuttonup") {
if (this._isGrabbing() || this._isTargetOfType(TARGET_TYPE_UI)) {
this.grabStarting = false;
this.data.cursor.emit("cursor-release", e.detail);
Expand Down Expand Up @@ -440,7 +444,7 @@ AFRAME.registerComponent("cursor-controller", {
_updateController: function() {
this.hasPointingDevice = this.controllerQueue.length > 0 && this.inVR;

this._setCursorVisibility(this.hasPointingDevice);
this._setCursorVisibility(this.hasPointingDevice || this.isMobile);

if (this.hasPointingDevice) {
const controllerData = this.controllerQueue[0];
Expand Down
1 change: 1 addition & 0 deletions src/hub.html
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
ik-root
player-info
networked-avatar
gamepad-controls
>
<a-entity
id="player-hud"
Expand Down
1 change: 1 addition & 0 deletions src/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ if (qs.quality) {
import "aframe-physics-system";
import "aframe-physics-extras";
import "aframe-extras/src/pathfinding";
import "aframe-extras/src/controls/gamepad-controls";
import "super-hands";
import "./components/super-networked-interactable";
import "./components/networked-counter";
Expand Down