// The code that deals with 3d audio
import EventEmitter from 'eventemitter3';
import vec3 from '../../tsm/vec3';
export default class ResonatorScene extends EventEmitter {
    constructor(context) {
        super();
        this.context = context;
        this.scene = this.context.getContext().createGain();
        this.listener = this.context.getContext().listener;
        this.init();
    }
    init() {
        // this.scene.output.connect(this.context.getOutputDestination());
    }
    createSource() {
        const node = this.context.getContext().createPanner();
        node.panningModel = 'HRTF';
        node.distanceModel = 'linear';
        node.maxDistance = 20;
        node.refDistance = 2;
        node.connect(this.scene);
        return node;
    }
    getOutput() {
        return this.scene;
    }
    getInput() {
        return this.scene;
    }
    setListenerPosition(x, y, z) {
        this.listener.setPosition(x, y, z);
    }
    setListenerOrientation(forward, rawup) {
        let fwd = new vec3([forward.x, forward.y, forward.z]);
        let up = fwd.copy();
        vec3.cross(up, new vec3([rawup.x, rawup.y, rawup.z]), up);
        vec3.cross(up, fwd, up);
        fwd.normalize();
        up.normalize();
        this.listener.setOrientation(fwd.x, fwd.y, fwd.z, up.x, up.y, up.z);
    }
}
