Skip to content

Commit

Permalink
Merge pull request #343 from mozilla/feature/carboard_cursor_support
Browse files Browse the repository at this point in the history
cardboard support for cursor-controller
  • Loading branch information
InfiniteLee authored May 9, 2018
2 parents fbf4116 + 26737bb commit 135331f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
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);
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()) {
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

0 comments on commit 135331f

Please sign in to comment.