Skip to content

Commit

Permalink
Add mouseSpeed property to PointerLockControls (mrdoob#23516)
Browse files Browse the repository at this point in the history
* Add `mouseSpeed` property to `PointerLockControls`

`mouseSpeed` controls the mouse sensitivity for `PointerLockControls`.
This change also adds a new optional `options` parameter to the
constructor of `PointerLockControls`.

* Update PointerLockControls.js

* Update PointerLockControls.js

* Rename `mouseSpeed` to `pointerSpeed`

* Add `pointerSpeed` property documentation

Co-authored-by: mrdoob <info@mrdoob.com>
  • Loading branch information
2 people authored and donmccurdy committed Mar 10, 2022
1 parent 92c18d4 commit b4064cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/examples/en/controls/PointerLockControls.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ <h3>[property:Float minPolarAngle]</h3>
Camera pitch, lower limit. Range is 0 to Math.PI radians. Default is 0.
</p>

<h3>[property:Float pointerSpeed]</h3>
<p>
Multiplier for how much the pointer movement influences the camera rotation. Default is 1.
</p>

<h2>Methods</h2>

<p>See the base [page:EventDispatcher] class for common methods.</p>
Expand Down
6 changes: 4 additions & 2 deletions examples/js/controls/PointerLockControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

this.maxPolarAngle = Math.PI; // radians

this.pointerSpeed = 1.0;

const scope = this;

function onMouseMove( event ) {
Expand All @@ -47,8 +49,8 @@

_euler.setFromQuaternion( camera.quaternion );

_euler.y -= movementX * 0.002;
_euler.x -= movementY * 0.002;
_euler.y -= movementX * 0.002 * scope.pointerSpeed;
_euler.x -= movementY * 0.002 * scope.pointerSpeed;
_euler.x = Math.max( _PI_2 - scope.maxPolarAngle, Math.min( _PI_2 - scope.minPolarAngle, _euler.x ) );
camera.quaternion.setFromEuler( _euler );
scope.dispatchEvent( _changeEvent );
Expand Down
6 changes: 4 additions & 2 deletions examples/jsm/controls/PointerLockControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class PointerLockControls extends EventDispatcher {
this.minPolarAngle = 0; // radians
this.maxPolarAngle = Math.PI; // radians

this.pointerSpeed = 1.0;

const scope = this;

function onMouseMove( event ) {
Expand All @@ -45,8 +47,8 @@ class PointerLockControls extends EventDispatcher {

_euler.setFromQuaternion( camera.quaternion );

_euler.y -= movementX * 0.002;
_euler.x -= movementY * 0.002;
_euler.y -= movementX * 0.002 * scope.pointerSpeed;
_euler.x -= movementY * 0.002 * scope.pointerSpeed;

_euler.x = Math.max( _PI_2 - scope.maxPolarAngle, Math.min( _PI_2 - scope.minPolarAngle, _euler.x ) );

Expand Down

0 comments on commit b4064cf

Please sign in to comment.