浏览代码

Merge pull request #13000 from WestLangley/dev-device

DeviceOrientationControls: clean up
Mr.doob 7 年之前
父节点
当前提交
22aa2162b4
共有 1 个文件被更改,包括 16 次插入6 次删除
  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;
 
-		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.disconnect();
+		scope.disconnect();
 
 	};