|
@@ -133,12 +133,7 @@ THREE.OrbitControls = function ( object, domElement ) {
|
|
|
offset.applyQuaternion( quat );
|
|
|
|
|
|
// angle from z-axis around y-axis
|
|
|
-
|
|
|
- theta = Math.atan2( offset.x, offset.z );
|
|
|
-
|
|
|
- // angle from y-axis
|
|
|
-
|
|
|
- phi = Math.atan2( Math.sqrt( offset.x * offset.x + offset.z * offset.z ), offset.y );
|
|
|
+ spherical.fromDirection( offset );
|
|
|
|
|
|
if ( scope.autoRotate && state === STATE.NONE ) {
|
|
|
|
|
@@ -146,17 +141,16 @@ THREE.OrbitControls = function ( object, domElement ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
- theta += thetaDelta;
|
|
|
- phi += phiDelta;
|
|
|
+ spherical.add( sphericalDelta );
|
|
|
|
|
|
// restrict theta to be between desired limits
|
|
|
- theta = Math.max( scope.minAzimuthAngle, Math.min( scope.maxAzimuthAngle, theta ) );
|
|
|
+ spherical.theta = Math.max( scope.minAzimuthAngle, Math.min( scope.maxAzimuthAngle, spherical.theta ) );
|
|
|
|
|
|
// restrict phi to be between desired limits
|
|
|
- phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, phi ) );
|
|
|
+ spherical.phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, spherical.phi ) );
|
|
|
|
|
|
// restrict phi to be betwee EPS and PI-EPS
|
|
|
- phi = Math.max( EPS, Math.min( Math.PI - EPS, phi ) );
|
|
|
+ spherical.phi = Math.max( EPS, Math.min( Math.PI - EPS, spherical.phi ) );
|
|
|
|
|
|
var radius = offset.length() * scale;
|
|
|
|
|
@@ -166,9 +160,7 @@ THREE.OrbitControls = function ( object, domElement ) {
|
|
|
// move target to panned location
|
|
|
scope.target.add( panOffset );
|
|
|
|
|
|
- offset.x = radius * Math.sin( phi ) * Math.sin( theta );
|
|
|
- offset.y = radius * Math.cos( phi );
|
|
|
- offset.z = radius * Math.sin( phi ) * Math.cos( theta );
|
|
|
+ offset = spherical.direction( offset ).multiplyScalar( radius );
|
|
|
|
|
|
// rotate offset back to "camera-up-vector-is-up" space
|
|
|
offset.applyQuaternion( quatInverse );
|
|
@@ -179,13 +171,11 @@ THREE.OrbitControls = function ( object, domElement ) {
|
|
|
|
|
|
if ( scope.enableDamping === true ) {
|
|
|
|
|
|
- thetaDelta *= ( 1 - scope.dampingFactor );
|
|
|
- phiDelta *= ( 1 - scope.dampingFactor );
|
|
|
+ sphericalDelta.multiplyScalar( 1 - scope.dampingFactor );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- thetaDelta = 0;
|
|
|
- phiDelta = 0;
|
|
|
+ sphericalDelta.set( 0, 0 );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -254,11 +244,9 @@ THREE.OrbitControls = function ( object, domElement ) {
|
|
|
var EPS = 0.000001;
|
|
|
|
|
|
// current position in spherical coordinates
|
|
|
- var theta;
|
|
|
- var phi;
|
|
|
+ var spherical = new THREE.Spherical();
|
|
|
+ var sphericalDelta = new THREE.Spherical();
|
|
|
|
|
|
- var phiDelta = 0;
|
|
|
- var thetaDelta = 0;
|
|
|
var scale = 1;
|
|
|
var panOffset = new THREE.Vector3();
|
|
|
var zoomChanged = false;
|
|
@@ -289,13 +277,13 @@ THREE.OrbitControls = function ( object, domElement ) {
|
|
|
|
|
|
function rotateLeft( angle ) {
|
|
|
|
|
|
- thetaDelta -= angle;
|
|
|
+ sphericalDelta.theta -= angle;
|
|
|
|
|
|
}
|
|
|
|
|
|
function rotateUp( angle ) {
|
|
|
|
|
|
- phiDelta -= angle;
|
|
|
+ sphericalDelta.phi -= angle;
|
|
|
|
|
|
}
|
|
|
|