WestLangley 7 years ago
parent
commit
c3a76dc225
1 changed files with 16 additions and 6 deletions
  1. 16 6
      examples/js/controls/DeviceOrientationControls.js

+ 16 - 6
examples/js/controls/DeviceOrientationControls.js

@@ -81,18 +81,28 @@ THREE.DeviceOrientationControls = function( object ) {
 
 
 		if ( scope.enabled === false ) return;
 		if ( scope.enabled === false ) return;
 
 
-		var alpha = scope.deviceOrientation.alpha ? THREE.Math.degToRad( scope.deviceOrientation.alpha ) + this.alphaOffset : 0; // Z
-		var beta = scope.deviceOrientation.beta ? THREE.Math.degToRad( scope.deviceOrientation.beta ) : 0; // X'
-		var gamma = scope.deviceOrientation.gamma ? THREE.Math.degToRad( scope.deviceOrientation.gamma ) : 0; // Y''
-		var orient = scope.screenOrientation ? THREE.Math.degToRad( scope.screenOrientation ) : 0; // O
+		var device = scope.deviceOrientation;
+
+		if ( device ) {
+
+			var alpha = device.alpha ? THREE.Math.degToRad( device.alpha ) + scope.alphaOffset : 0; // Z
+
+			var beta = device.beta ? THREE.Math.degToRad( device.beta ) : 0; // X'
+
+			var gamma = device.gamma ? THREE.Math.degToRad( device.gamma ) : 0; // Y''
+
+			var orient = scope.screenOrientation ? THREE.Math.degToRad( scope.screenOrientation ) : 0; // O
+
+			setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient );
+
+		}
 
 
-		setObjectQuaternion( scope.object.quaternion, alpha, beta, gamma, orient );
 
 
 	};
 	};
 
 
 	this.dispose = function() {
 	this.dispose = function() {
 
 
-		this.disconnect();
+		scope.disconnect();
 
 
 	};
 	};