Capítulo 313 de 859
The implementation of this class is based on the Pointer Lock API. PointerLockControls is a perfect choice for first person 3D games.
const 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
| Signature |
|---|
new PointerLockControls( camera : Camera, domElement : HTMLElement ) |
Properties
| Property | Description |
|---|---|
.isLocked : boolean (readonly) | Whether the controls are locked or not. |
.maxPolarAngle : number | Camera pitch, upper limit. Range is '[0, Math.PI]' in radians. |
.minPolarAngle : number | Camera pitch, lower limit. Range is '[0, Math.PI]' in radians. |
.pointerSpeed : number | Multiplier for how much the pointer movement influences the camera rotation. |
Methods
| Method | Description |
|---|---|
.getDirection( v : Vector3 ) : Vector3 | Returns the look direction of the camera. |
.lock( unadjustedMovement : boolean ) | Activates the pointer lock. |
.moveForward( distance : number ) | Moves the camera forward parallel to the xz-plane. Assumes camera.up is y-up. |
.moveRight( distance : number ) | Moves the camera sidewards parallel to the xz-plane. |
.unlock() | Exits the pointer lock. |