setListenerOrientation
Point the listener. Forward is where the head looks. Up is which way is up, so tilting the camera does not roll the sound around your head.
setListenerOrientation(forwardX: number, forwardY: number, forwardZ: number, upX?: number, upY?: number, upZ?: number, skipDispatchEvent?: boolean): void;
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
forwardX | number | required | x part of the forward vector. |
forwardY | number | required | y part of the forward vector. |
forwardZ | number | required | z part of the forward vector. |
upX | number | 0 | x part of the up vector. |
upY | number | 1 | y part of the up vector. |
upZ | number | 0 | z part of the up vector. |
skipDispatchEvent | boolean | false | Set to true to leave out the listener_changed event. |
Returns
Nothing.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
soundHub.setListenerOrientation(0, 0, -1); // straight ahead, the default
soundHub.setListenerOrientation(1, 0, 0); // turned a quarter to the right
soundHub.setListenerOrientation(0, 0, -1, 1, 0, 0); // lying on your left side
Good to know
- The defaults are the Web Audio ones: looking down negative z, with up along positive y.
- Leaving out the up vector sets it back to
0, 1, 0. It does not keep the up vector from an earlier call. - The values are rounded to 2 decimals.
- Does nothing when spatial audio is off or unsupported.
- Every call dispatches
SoundEventsEnum.LISTENER_CHANGED('listener_changed') withposition,orientation(the forward vector) andup.
See also
setListenerPosition: move the listener, with a first-person example.getListenerOrientation: read both vectors back.resetListener: back to the default orientation.setSpatialOrientation: point a sound instead.