Skip to content

Commit

Permalink
orbitcontrols: pivot/target
Browse files Browse the repository at this point in the history
  • Loading branch information
sciecode committed Jan 26, 2020
1 parent 99bdca1 commit dccf157
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions examples/js/controls/OrbitControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ THREE.OrbitControls = function ( object, domElement ) {

// "target" sets the location of focus, where the object orbits around
this.target = new THREE.Vector3();
this.pivot = new THREE.Vector3();

// How far you can dolly in and out ( PerspectiveCamera only )
this.minDistance = 0;
Expand Down Expand Up @@ -63,7 +64,7 @@ THREE.OrbitControls = function ( object, domElement ) {
// Set to false to disable panning
this.enablePan = true;
this.panSpeed = 1.0;
this.screenSpacePanning = false; // if true, pan in screen-space
this.screenSpacePanning = true; // if true, pan in screen-space
this.keyPanSpeed = 7.0; // pixels moved per arrow key push

// Set to true to automatically rotate around the target
Expand All @@ -85,6 +86,7 @@ THREE.OrbitControls = function ( object, domElement ) {

// for reset
this.target0 = this.target.clone();
this.pivot0 = this.pivot.clone();
this.position0 = this.object.position.clone();
this.zoom0 = this.object.zoom;

Expand All @@ -107,6 +109,7 @@ THREE.OrbitControls = function ( object, domElement ) {
this.saveState = function () {

scope.target0.copy( scope.target );
scope.pivot0.copy( scope.pivot );
scope.position0.copy( scope.object.position );
scope.zoom0 = scope.object.zoom;

Expand All @@ -115,6 +118,7 @@ THREE.OrbitControls = function ( object, domElement ) {
this.reset = function () {

scope.target.copy( scope.target0 );
scope.pivot.copy( scope.pivot0 );
scope.object.position.copy( scope.position0 );
scope.object.zoom = scope.zoom0;

Expand Down Expand Up @@ -143,7 +147,7 @@ THREE.OrbitControls = function ( object, domElement ) {

var position = scope.object.position;

offset.copy( position ).sub( scope.target );
offset.copy( position ).sub( scope.pivot );

// rotate offset to "y-axis-is-up" space
offset.applyQuaternion( quat );
Expand Down Expand Up @@ -200,7 +204,7 @@ THREE.OrbitControls = function ( object, domElement ) {
// rotate offset back to "camera-up-vector-is-up" space
offset.applyQuaternion( quatInverse );

position.copy( scope.target ).add( offset );
position.copy( scope.pivot ).add( offset );

scope.object.lookAt( scope.target );

Expand Down
10 changes: 7 additions & 3 deletions examples/jsm/controls/OrbitControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var OrbitControls = function ( object, domElement ) {

// "target" sets the location of focus, where the object orbits around
this.target = new Vector3();
this.pivot = new Vector3();

// How far you can dolly in and out ( PerspectiveCamera only )
this.minDistance = 0;
Expand Down Expand Up @@ -73,7 +74,7 @@ var OrbitControls = function ( object, domElement ) {
// Set to false to disable panning
this.enablePan = true;
this.panSpeed = 1.0;
this.screenSpacePanning = false; // if true, pan in screen-space
this.screenSpacePanning = true; // if true, pan in screen-space
this.keyPanSpeed = 7.0; // pixels moved per arrow key push

// Set to true to automatically rotate around the target
Expand All @@ -95,6 +96,7 @@ var OrbitControls = function ( object, domElement ) {

// for reset
this.target0 = this.target.clone();
this.pivot0 = this.pivot.clone();
this.position0 = this.object.position.clone();
this.zoom0 = this.object.zoom;

Expand All @@ -117,6 +119,7 @@ var OrbitControls = function ( object, domElement ) {
this.saveState = function () {

scope.target0.copy( scope.target );
scope.pivot0.copy( scope.pivot );
scope.position0.copy( scope.object.position );
scope.zoom0 = scope.object.zoom;

Expand All @@ -125,6 +128,7 @@ var OrbitControls = function ( object, domElement ) {
this.reset = function () {

scope.target.copy( scope.target0 );
scope.pivot.copy( scope.pivot0 );
scope.object.position.copy( scope.position0 );
scope.object.zoom = scope.zoom0;

Expand Down Expand Up @@ -153,7 +157,7 @@ var OrbitControls = function ( object, domElement ) {

var position = scope.object.position;

offset.copy( position ).sub( scope.target );
offset.copy( position ).sub( scope.pivot );

// rotate offset to "y-axis-is-up" space
offset.applyQuaternion( quat );
Expand Down Expand Up @@ -210,7 +214,7 @@ var OrbitControls = function ( object, domElement ) {
// rotate offset back to "camera-up-vector-is-up" space
offset.applyQuaternion( quatInverse );

position.copy( scope.target ).add( offset );
position.copy( scope.pivot ).add( offset );

scope.object.lookAt( scope.target );

Expand Down

0 comments on commit dccf157

Please sign in to comment.