From 121fafdb687404f7cc4367a2651b377279712ee9 Mon Sep 17 00:00:00 2001
From: Marshall Quander <marshall@quander.me>
Date: Wed, 20 Jun 2018 20:27:40 -0700
Subject: [PATCH] Don't use A-Frame PolyfillControls helper

The PolyfillControls helper has some breakage where it doesn't
always use the polyfilled VRFrameData class. Also, we don't even
want the pose data to be applied to an Object3D, so it seems a
little bit silly to use.
---
 src/components/look-on-mobile.js | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/components/look-on-mobile.js b/src/components/look-on-mobile.js
index deb553e78..7cde5ba13 100644
--- a/src/components/look-on-mobile.js
+++ b/src/components/look-on-mobile.js
@@ -1,4 +1,3 @@
-const PolyfillControls = AFRAME.utils.device.PolyfillControls;
 const TWOPI = Math.PI * 2;
 
 class CircularBuffer {
@@ -50,24 +49,23 @@ AFRAME.registerComponent("look-on-mobile", {
 
   init() {
     this.hmdEuler = new THREE.Euler();
+    this.hmdQuaternion = new THREE.Quaternion();
     this.prevX = this.hmdEuler.x;
     this.prevY = this.hmdEuler.y;
     this.pendingLookX = 0;
     this.onRotateX = this.onRotateX.bind(this);
     this.dXBuffer = new CircularBuffer(6);
     this.dYBuffer = new CircularBuffer(6);
+    this.vrDisplay = window.webvrpolyfill.getPolyfillDisplays()[0];
+    this.frameData = new window.webvrpolyfill.constructor.VRFrameData();
   },
 
   play() {
     this.el.addEventListener("rotateX", this.onRotateX);
-    this.polyfillObject = new THREE.Object3D();
-    this.polyfillControls = new PolyfillControls(this.polyfillObject);
   },
 
   pause() {
     this.el.removeEventListener("rotateX", this.onRotateX);
-    this.polyfillControls = null;
-    this.polyfillObject = null;
   },
 
   update() {
@@ -81,8 +79,11 @@ AFRAME.registerComponent("look-on-mobile", {
   tick() {
     const hmdEuler = this.hmdEuler;
     const { horizontalLookSpeedRatio, verticalLookSpeedRatio } = this.data;
-    this.polyfillControls.update();
-    hmdEuler.setFromQuaternion(this.polyfillObject.quaternion, "YXZ");
+    this.vrDisplay.getFrameData(this.frameData);
+    if (this.frameData.pose.orientation !== null) {
+      this.hmdQuaternion.fromArray(this.frameData.pose.orientation);
+      hmdEuler.setFromQuaternion(this.hmdQuaternion, "YXZ");
+    }
 
     const dX = THREE.Math.RAD2DEG * difference(hmdEuler.x, this.prevX);
     const dY = THREE.Math.RAD2DEG * difference(hmdEuler.y, this.prevY);
-- 
GitLab