Browse Source

Always use clientHeight

Eric Haines 12 years ago
parent
commit
273241e1b9
1 changed files with 8 additions and 22 deletions
  1. 8 22
      examples/js/controls/OrbitControls.js

+ 8 - 22
examples/js/controls/OrbitControls.js

@@ -164,20 +164,14 @@ THREE.OrbitControls = function ( object, domElement ) {
 			// half of the fov is center to top of screen
 			// half of the fov is center to top of screen
 			targetDistance *= Math.tan( (scope.object.fov/2) * Math.PI / 180.0 );
 			targetDistance *= Math.tan( (scope.object.fov/2) * Math.PI / 180.0 );
 			// we actually don't use screenWidth, since perspective camera is fixed to screen height
 			// we actually don't use screenWidth, since perspective camera is fixed to screen height
-			var height = ( scope.domElement.height !== undefined ) ? 
-				scope.domElement.height : scope.domElement.body.clientHeight;
-			scope.panLeft( 2 * delta.x * targetDistance / height );
-			scope.panUp( 2 * delta.y * targetDistance / height );
+			scope.panLeft( 2 * delta.x * targetDistance / scope.domElement.body.clientHeight );
+			scope.panUp( 2 * delta.y * targetDistance / scope.domElement.body.clientHeight );
 		}
 		}
 		else if ( scope.object.top !== undefined )
 		else if ( scope.object.top !== undefined )
 		{
 		{
 			// orthographic
 			// orthographic
-			var width = ( scope.domElement.width !== undefined ) ? 
-				scope.domElement.width : scope.domElement.body.clientWidth;
-			var height = ( scope.domElement.height !== undefined ) ? 
-				scope.domElement.height : scope.domElement.body.clientHeight;
-			scope.panLeft( delta.x * (scope.object.right - scope.object.left) / width );
-			scope.panUp( delta.y * (scope.object.top - scope.object.bottom) / height );
+			scope.panLeft( delta.x * (scope.object.right - scope.object.left) / scope.domElement.body.clientWidth );
+			scope.panUp( delta.y * (scope.object.top - scope.object.bottom) / scope.domElement.body.clientHeight );
 		}
 		}
 		else
 		else
 		{
 		{
@@ -328,14 +322,10 @@ THREE.OrbitControls = function ( object, domElement ) {
 			rotateEnd.set( event.clientX, event.clientY );
 			rotateEnd.set( event.clientX, event.clientY );
 			rotateDelta.subVectors( rotateEnd, rotateStart );
 			rotateDelta.subVectors( rotateEnd, rotateStart );
 
 
-			var width = ( scope.domElement.width !== undefined ) ? 
-				scope.domElement.width : scope.domElement.body.clientWidth;
-			var height = ( scope.domElement.height !== undefined ) ? 
-				scope.domElement.height : scope.domElement.body.clientHeight;
 			// rotating across whole screen goes 360 degrees around
 			// rotating across whole screen goes 360 degrees around
-			scope.rotateLeft( 2 * Math.PI * rotateDelta.x / width * scope.rotateSpeed );
+			scope.rotateLeft( 2 * Math.PI * rotateDelta.x / scope.domElement.body.clientWidth * scope.rotateSpeed );
 			// rotating up and down along whole screen attempts to go 360, but limited to 180
 			// rotating up and down along whole screen attempts to go 360, but limited to 180
-			scope.rotateUp( 2 * Math.PI * rotateDelta.y / height * scope.rotateSpeed );
+			scope.rotateUp( 2 * Math.PI * rotateDelta.y / scope.domElement.body.clientHeight * scope.rotateSpeed );
 
 
 			rotateStart.copy( rotateEnd );
 			rotateStart.copy( rotateEnd );
 
 
@@ -507,14 +497,10 @@ THREE.OrbitControls = function ( object, domElement ) {
 				rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
 				rotateEnd.set( event.touches[ 0 ].pageX, event.touches[ 0 ].pageY );
 				rotateDelta.subVectors( rotateEnd, rotateStart );
 				rotateDelta.subVectors( rotateEnd, rotateStart );
 
 
-				var width = ( scope.domElement.width !== undefined ) ? 
-					scope.domElement.width : scope.domElement.body.clientWidth;
-				var height = ( scope.domElement.height !== undefined ) ? 
-					scope.domElement.height : scope.domElement.body.clientHeight;
 				// rotating across whole screen goes 360 degrees around
 				// rotating across whole screen goes 360 degrees around
-				scope.rotateLeft( 2 * Math.PI * rotateDelta.x / width * scope.rotateSpeed );
+				scope.rotateLeft( 2 * Math.PI * rotateDelta.x / scope.domElement.body.clientWidth * scope.rotateSpeed );
 				// rotating up and down along whole screen attempts to go 360, but limited to 180
 				// rotating up and down along whole screen attempts to go 360, but limited to 180
-				scope.rotateUp( 2 * Math.PI * rotateDelta.y / height * scope.rotateSpeed );
+				scope.rotateUp( 2 * Math.PI * rotateDelta.y / scope.domElement.body.clientHeight * scope.rotateSpeed );
 
 
 				rotateStart.copy( rotateEnd );
 				rotateStart.copy( rotateEnd );
 				break;
 				break;