Skip to main content

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​

ParameterTypeDefaultDescription
forwardXnumberrequiredx part of the forward vector.
forwardYnumberrequiredy part of the forward vector.
forwardZnumberrequiredz part of the forward vector.
upXnumber0x part of the up vector.
upYnumber1y part of the up vector.
upZnumber0z part of the up vector.
skipDispatchEventbooleanfalseSet 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') with position, orientation (the forward vector) and up.

See also​