Skip to content

Commit

Permalink
Handle Chrome m66+'s change of reporting a deviceorientation rotation…
Browse files Browse the repository at this point in the history
…Rate in degrees, rather than (incorrect) radians. Fixes #18
  • Loading branch information
jsantell committed Mar 5, 2018
1 parent ed963c7 commit 75a6d51
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/sensor-fusion/fusion-pose-sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ function FusionPoseSensor(kFilter, predictionTime, yawOnly, isDebug) {

this.isFirefoxAndroid = Util.isFirefoxAndroid();
this.isIOS = Util.isIOS();
// Chrome as of m66 started reporting `rotationRate` in degrees rather
// than radians, to be consistent with other browsers.
// https://github.com/immersive-web/cardboard-vr-display/issues/18
this.isChromeUsingDegrees = Util.getChromeVersion() >= 66;

this.orientationOut_ = new Float32Array(4);
}
Expand Down Expand Up @@ -153,9 +157,9 @@ FusionPoseSensor.prototype.updateDeviceMotion_ = function(deviceMotion) {
this.gyroscope.set(rotRate.alpha, rotRate.beta, rotRate.gamma);
}

// With iOS and Firefox Android, rotationRate is reported in degrees,
// so we first convert to radians.
if (this.isIOS || this.isFirefoxAndroid) {
// Browsers on iOS, Firefox/Android, and Chrome m66/Android `rotationRate`
// is reported in degrees, so we first convert to radians.
if (this.isIOS || this.isFirefoxAndroid || this.isChromeUsingDegrees) {
this.gyroscope.multiplyScalar(Math.PI / 180);
}

Expand Down
12 changes: 12 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ export const isFirefoxAndroid = (function() {
};
})();

/**
* Returns a number value indiciating the version of Chrome being used,
* or otherwise `null` if not on Chrome.
*/
export const getChromeVersion = (function() {
const match = navigator.userAgent.match(/.*Chrome\/([0-9]+)/);
const value = match ? parseInt(match[1], 10) : null;
return function() {
return value;
};
})();

export const isR7 = (function() {
var isR7 = navigator.userAgent.indexOf('R7 Build') !== -1;
return function() {
Expand Down

0 comments on commit 75a6d51

Please sign in to comment.