Skip to content

Commit

Permalink
OrbitControls: Add keyRotateSpeed. (mrdoob#29988)
Browse files Browse the repository at this point in the history
* feat: Add keyRotateSpeed to OrbitControls

This allows for setting a different speed of rotation when using the
keyboard vs when using a mouse. Similar in approach to the existing
keyPanSpeed.

* fix: reduce keyRotateSpeed down to 1
  • Loading branch information
bbsimong authored and cmhhelgeson committed Dec 5, 2024
1 parent 8f6a901 commit 76c2fba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/examples/en/controls/OrbitControls.html
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ <h3>[property:Float keyPanSpeed]</h3>
How fast to pan the camera when the keyboard is used. Default is 7.0 pixels per keypress.
</p>

<h3>[property:Float keyRotateSpeed]</h3>
<p>
How fast to rotate the camera when the keyboard is used. Default is 1.
</p>

<h3>[property:Object keys]</h3>
<p>
This object contains references to the keycodes for controlling camera panning. Default is the 4 arrow keys.
Expand Down
9 changes: 5 additions & 4 deletions examples/jsm/controls/OrbitControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class OrbitControls extends Controls {
// Set to false to disable rotating
this.enableRotate = true;
this.rotateSpeed = 1.0;
this.keyRotateSpeed = 1.0;

// Set to false to disable panning
this.enablePan = true;
Expand Down Expand Up @@ -786,7 +787,7 @@ class OrbitControls extends Controls {

if ( this.enableRotate ) {

this._rotateUp( _twoPI * this.rotateSpeed / this.domElement.clientHeight );
this._rotateUp( _twoPI * this.keyRotateSpeed / this.domElement.clientHeight );

}

Expand All @@ -809,7 +810,7 @@ class OrbitControls extends Controls {

if ( this.enableRotate ) {

this._rotateUp( - _twoPI * this.rotateSpeed / this.domElement.clientHeight );
this._rotateUp( - _twoPI * this.keyRotateSpeed / this.domElement.clientHeight );

}

Expand All @@ -832,7 +833,7 @@ class OrbitControls extends Controls {

if ( this.enableRotate ) {

this._rotateLeft( _twoPI * this.rotateSpeed / this.domElement.clientHeight );
this._rotateLeft( _twoPI * this.keyRotateSpeed / this.domElement.clientHeight );

}

Expand All @@ -855,7 +856,7 @@ class OrbitControls extends Controls {

if ( this.enableRotate ) {

this._rotateLeft( - _twoPI * this.rotateSpeed / this.domElement.clientHeight );
this._rotateLeft( - _twoPI * this.keyRotateSpeed / this.domElement.clientHeight );

}

Expand Down

0 comments on commit 76c2fba

Please sign in to comment.