[page:EventDispatcher] →

[name]

The implementation of this class is based on the [link:https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API Pointer Lock API]. [name] is a perfect choice for first person 3D games.

Example

[example:misc_controls_pointerlock misc / controls / pointerlock ]

var controls = new PointerLockControls( camera, document.body ); // add event listener to show/hide a UI (e.g. the game's menu) controls.addEventListener( 'lock', function () { menu.style.display = 'none'; } ); controls.addEventListener( 'unlock', function () { menu.style.display = 'block'; } );

Constructor

[name]( [param:Camera camera], [param:HTMLDOMElement domElement] )

[page:Camera camera]: The camera of the rendered scene.

[page:HTMLDOMElement domElement]: The HTML element used for event listeners.

Creates a new instance of [name].

Events

change

Fires when the user moves the mouse.

lock

Fires when the pointer lock status is "locked" (in other words: the mouse is captured).

unlock

Fires when the pointer lock status is "unlocked" (in other words: the mouse is not captured anymore).

Properties

[property:HTMLDOMElement domElement]

The HTMLDOMElement used to listen for mouse / touch events. This must be passed in the constructor; changing it here will not set up new event listeners.

[property:Boolean isLocked]

Whether or not the controls are locked.

Methods

See the base [page:EventDispatcher] class for common methods.

[method:null connect] ()

Adds the event listeners of the controls.

[method:null disconnect] ()

Removes the event listeners of the controls.

[method:Vector3 getDirection] ( [param:Vector3 target] )

[page:Vector3 target]: The target vector.

Returns the look direction of the camera.

[method:null lock] ()

Activates the pointer lock.

[method:null moveForward] ( [param:Number distance] )

[page:Number distance]: The signed distance.

Moves the camera forward parallel to the xz-plane. Assumes camera.up is y-up.

[method:null moveRight] ( [param:Number distance] )

[page:Number distance]: The signed distance.

Moves the camera sidewards parallel to the xz-plane.

[method:null unlock] ()

Exits the pointer lock.

Source

[link:https://github.com/mrdoob/three.js/blob/master/examples/js/controls/PointerLockControls.js examples/js/controls/PointerLockControls.js]