getListenerOrientation
Get the current listener orientation: where the head looks and which way is up.
getListenerOrientation(): { forward: { x: number; y: number; z: number }; up: { x: number; y: number; z: number } };
Parameters
This method takes no parameters.
Returns
{ forward: { x: number; y: number; z: number }; up: { x: number; y: number; z: number } }: the two vectors. Until you change them, forward is { x: 0, y: 0, z: -1 } and up is { x: 0, y: 1, z: 0 }. You get a copy, so changing it does not turn the listener.
Example
import { SoundHub } from 'soundhub';
const soundHub = new SoundHub();
soundHub.setListenerOrientation(1, 0, 0);
const { forward, up } = soundHub.getListenerOrientation();
// forward: { x: 1, y: 0, z: 0 }, up: { x: 0, y: 1, z: 0 }
Good to know
- It returns the values soundhub stored, rounded to 2 decimals. It does not read the browser's
AudioListener. - When spatial audio is off,
setListenerOrientationreturns early and this keeps returning the old values.
See also
setListenerOrientation: turn the listener.getListenerPosition: where the listener is.resetListener: back to the defaults.