Browse Source

Fixed rotation center of OrbitControls

Xueqiao Xu 13 years ago
parent
commit
3b4604e153
1 changed files with 4 additions and 8 deletions
  1. 4 8
      src/extras/controls/OrbitControls.js

+ 4 - 8
src/extras/controls/OrbitControls.js

@@ -36,15 +36,12 @@ THREE.OrbitControls = function( object, domElement ) {
 	this.update = function () {
 	this.update = function () {
 
 
 		var position = this.object.position;
 		var position = this.object.position;
+		var offset = position.clone().subSelf( this.center )
 
 
 		// angle from z-axis around y-axis
 		// angle from z-axis around y-axis
-		var theta = Math.atan2( position.x, position.z ); 
-
+		var theta = Math.atan2( offset.x, offset.z ); 
 		// angle from y-axis
 		// angle from y-axis
-		var phi = Math.atan2( 
-			Math.sqrt( position.x * position.x + position.z * position.z ),
-			position.y
-		);
+		var phi = Math.atan2( Math.sqrt( offset.x * offset.x + offset.z * offset.z ), offset.y );
 		
 		
 		if ( this.autoRotate ) {
 		if ( this.autoRotate ) {
 
 
@@ -65,8 +62,7 @@ THREE.OrbitControls = function( object, domElement ) {
 
 
 		}
 		}
 
 
-		var radius = position.clone().subSelf( this.center ).length();
-		var offset = new THREE.Vector3();
+		var radius = offset.length();
 		offset.x = radius * Math.sin( phi ) * Math.sin( theta );
 		offset.x = radius * Math.sin( phi ) * Math.sin( theta );
 		offset.y = radius * Math.cos( phi );
 		offset.y = radius * Math.cos( phi );
 		offset.z = radius * Math.sin( phi ) * Math.cos( theta );
 		offset.z = radius * Math.sin( phi ) * Math.cos( theta );