Aufgrund einer Wartung wird GitLab am 28.09. zwischen 10:00 und 11:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 28.09. between 10:00 and 11:00 am.

VAUListener.cs 1.93 KB
Newer Older
1 2 3 4 5 6 7 8
using UnityEngine;
using System;
using System.Collections;
using VA;


public class VAUListener : MonoBehaviour {

9 10 11
    public string listenername = "MyListener";
    private int Listener;
    private VANet _VA = null;
12 13
    private Quaternion q;
    private Transform t;
14 15 16 17 18 19 20 21 22

    public int ID
    {
        get
        {
            return Listener;
        }
    }

23 24 25
    // Use this for initialization
    void Start()
    {
26
        _VA = VAUAdapter.VA;
27 28
        Listener = _VA.CreateListener(listenername, 0, VAUAdapter.DefaultHRIR);
        _VA.SetSoundSourceAuralizationMode(Listener, "all");
29
        Debug.Log("Listener " + Listener + " created");
30
        _VA.SetListenerHRIRDataset(Listener, VAUAdapter.DefaultHRIR);
31 32
        if (GetComponent<VAUAuralizationMode>() != null)
            GetComponent<VAUAuralizationMode>().AuraStringChanged += OnListenerAuralizationModeChanged;
33 34 35 36 37
    }
	
	// Update is called once per frame
	void Update ()
    {
38 39
        t = GetComponent<Transform>();
        q = t.rotation;
40 41
        Vector3 up = q * Vector3.up;
        Vector3 view = q * Vector3.forward;
42 43 44
        Vector3 view_ogl = new Vector3(view.x, view.y, -view.z);
        Vector3 up_ogl = new Vector3(up.x, up.y, -up.z);

45
        _VA.SetListenerPosition(Listener, t.transform.position.x, t.transform.position.y, -t.transform.position.z);
46 47 48 49 50
        _VA.SetListenerOrientationVU(Listener, view_ogl.x, view_ogl.y, view_ogl.z, up_ogl.x, up_ogl.y, up_ogl.z);
        //Quaternion q_ogl = new Quaternion(q.x, q.y, -q.z, -q.w);
        //Vector3 t1 = new Vector3(0, 0, 1);
        //Vector3 t1_ogl = ( q_ogl * t1 ); // result: 0 0 -1
       // Debug.Log(t1_ogl);
51
    }
52 53 54 55 56 57 58 59 60 61

    void OnListenerAuralizationModeChanged(string AuraMode)
    {
        _VA.SetListenerAuralizationMode(Listener, AuraMode);
    }
    void OnDisable()
    {
        if (GetComponent<VAUAuralizationMode>() != null)
            GetComponent<VAUAuralizationMode>().AuraStringChanged -= OnListenerAuralizationModeChanged;
    }
62
}