Browse Source

Merge remote-tracking branch 'WestLangley/dev-orbit' into dev

Mr.doob 13 years ago
parent
commit
da7e067872
2 changed files with 30 additions and 6 deletions
  1. 15 3
      build/three.js
  2. 15 3
      src/extras/controls/OrbitControls.js

+ 15 - 3
build/three.js

@@ -30722,6 +30722,7 @@ THREE.TrackballControls = function ( object, domElement ) {
  * @author qiao / https://github.com/qiao
  * @author qiao / https://github.com/qiao
  * @author mrdoob / http://mrdoob.com
  * @author mrdoob / http://mrdoob.com
  * @author alteredq / http://alteredqualia.com/
  * @author alteredq / http://alteredqualia.com/
+ * @author WestLangley / https://github.com/WestLangley
  */
  */
 
 
 THREE.OrbitControls = function ( object, domElement ) {
 THREE.OrbitControls = function ( object, domElement ) {
@@ -30744,6 +30745,12 @@ THREE.OrbitControls = function ( object, domElement ) {
 	this.autoRotate = false;
 	this.autoRotate = false;
 	this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
 	this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
 
 
+	this.minPolarAngle = 0; // radians
+	this.maxPolarAngle = Math.PI; // radians
+
+	this.minDistance = 0;
+	this.maxDistance = Infinity;
+
 	// internals
 	// internals
 
 
 	var scope = this;
 	var scope = this;
@@ -30867,15 +30874,20 @@ THREE.OrbitControls = function ( object, domElement ) {
 		theta += thetaDelta;
 		theta += thetaDelta;
 		phi += phiDelta;
 		phi += phiDelta;
 
 
-		// restrict phi to be betwee EPS and PI-EPS
+		// restrict phi to be between desired limits
+		phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) );
 
 
+		// restrict phi to be betwee EPS and PI-EPS
 		phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
 		phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
 
 
-		var radius = offset.length();
+		var radius = offset.length() * scale;
+
+		// restrict radius to be between desired limits
+		radius = Math.max( this.minDistance, Math.min( this.maxDistance, radius ) );
+
 		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 );
-		offset.multiplyScalar( scale );
 
 
 		position.copy( this.center ).addSelf( offset );
 		position.copy( this.center ).addSelf( offset );
 
 

+ 15 - 3
src/extras/controls/OrbitControls.js

@@ -2,6 +2,7 @@
  * @author qiao / https://github.com/qiao
  * @author qiao / https://github.com/qiao
  * @author mrdoob / http://mrdoob.com
  * @author mrdoob / http://mrdoob.com
  * @author alteredq / http://alteredqualia.com/
  * @author alteredq / http://alteredqualia.com/
+ * @author WestLangley / https://github.com/WestLangley
  */
  */
 
 
 THREE.OrbitControls = function ( object, domElement ) {
 THREE.OrbitControls = function ( object, domElement ) {
@@ -24,6 +25,12 @@ THREE.OrbitControls = function ( object, domElement ) {
 	this.autoRotate = false;
 	this.autoRotate = false;
 	this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
 	this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
 
 
+	this.minPolarAngle = 0; // radians
+	this.maxPolarAngle = Math.PI; // radians
+
+	this.minDistance = 0;
+	this.maxDistance = Infinity;
+
 	// internals
 	// internals
 
 
 	var scope = this;
 	var scope = this;
@@ -147,15 +154,20 @@ THREE.OrbitControls = function ( object, domElement ) {
 		theta += thetaDelta;
 		theta += thetaDelta;
 		phi += phiDelta;
 		phi += phiDelta;
 
 
-		// restrict phi to be betwee EPS and PI-EPS
+		// restrict phi to be between desired limits
+		phi = Math.max( this.minPolarAngle, Math.min( this.maxPolarAngle, phi ) );
 
 
+		// restrict phi to be betwee EPS and PI-EPS
 		phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
 		phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
 
 
-		var radius = offset.length();
+		var radius = offset.length() * scale;
+
+		// restrict radius to be between desired limits
+		radius = Math.max( this.minDistance, Math.min( this.maxDistance, radius ) );
+
 		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 );
-		offset.multiplyScalar( scale );
 
 
 		position.copy( this.center ).addSelf( offset );
 		position.copy( this.center ).addSelf( offset );